Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from WardPearce/Development
Browse files Browse the repository at this point in the history
0.1.0
  • Loading branch information
WardPearce committed Jun 17, 2021
2 parents dd02157 + 6d6df35 commit 173b8de
Show file tree
Hide file tree
Showing 27 changed files with 494 additions and 276 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist
# exit-zero treats all errors as warnings
flake8 . --count --max-line-length=80 --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist
- uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install pyright
run: npm install pyright -g
- name: Run pyright
run: pyright backblaze/*
- name: Run unit tests
env:
KEY_ID: ${{ secrets.KEY_ID }}
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist
# exit-zero treats all errors as warnings
flake8 . --count --max-line-length=80 --statistics --exclude .git,__pycache__,docs/source/conf.py,old,build,dist
- uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install pyright
run: npm install pyright -g
- name: Run pyright
run: pyright backblaze/*
- name: Run unit tests
env:
KEY_ID: ${{ secrets.KEY_ID }}
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.linting.flake8Enabled": true,
"python.linting.enabled": true
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ The awaiting version requires Python ``3.7`` or above!
### Features:

- Full API coverage.
- Static typing with [PyRight](https://github.com/microsoft/pyright).
- Background authentication.
- Asynchronous & synchronous support.
- Easy to use with an object oriented design.
- 100% test coverage.
- Unit testing.
- Upload URL caching.
- Rate limit handler.

### Install

- Pip: ``pip3 install backblaze``
- Git: ``pip3 install git+https://github.com/WardPearce/backblaze.git``
- Pip:``pip3 install backblaze``
- Git:``pip3 install git+https://github.com/WardPearce/backblaze.git``

### Examples

Expand Down
146 changes: 94 additions & 52 deletions backblaze/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time

from httpx import AsyncClient, Client
from typing import Any, Generator, AsyncGenerator, Tuple
from typing import Generator, AsyncGenerator, Tuple, cast
from random import randint

from .base import Base
Expand Down Expand Up @@ -76,16 +76,19 @@ async def download_by_name(self, bucket_name: str, file_name: str,
params = settings.parameters
headers = settings.headers

return await self._get(
url="{}/{}/{}".format(
self._routes.download.file,
bucket_name,
file_name
),
headers=headers,
params=params,
resp_json=False,
include_account=False
return cast(
bytes,
await self._get(
url="{}/{}/{}".format(
self._routes.download.file,
bucket_name,
file_name
),
headers=headers,
params=params,
resp_json=False,
include_account=False
)
)

@authorize_required
Expand All @@ -105,17 +108,21 @@ async def create_key(self, settings: KeySettings
AwaitingKey
"""

data = await self._post(
json=settings.payload,
url=self._routes.key.create
data = cast(
dict,
await self._post(
json=settings.payload,
url=self._routes.key.create
)
)

return KeyModel(data), self.key(data["applicationKeyId"])

@authorize_required
async def keys(self, limit: int = 100,
start_key_id: str = None
) -> AsyncGenerator[Any, None]:
) -> AsyncGenerator[
Tuple[KeyModel, AwaitingKey, str], None]:
"""Used to list keys.
Parameters
Expand All @@ -134,9 +141,15 @@ async def keys(self, limit: int = 100,
Next application key ID.
"""

data = await self._post(
url=self._routes.key.list,
json={"maxKeyCount": limit, "startApplicationKeyId": start_key_id}
data = cast(
dict,
await self._post(
url=self._routes.key.list,
json={
"maxKeyCount": limit,
"startApplicationKeyId": start_key_id
}
)
)

for key in data["keys"]:
Expand Down Expand Up @@ -179,16 +192,22 @@ async def create_bucket(self, settings: BucketSettings
Used to interact with a bucket.
"""

data = BucketModel(await self._post(
url=self._routes.bucket.create,
json=settings.payload
))
data = BucketModel(
cast(
dict,
await self._post(
url=self._routes.bucket.create,
json=settings.payload
)
)
)

return data, self.bucket(data.bucket_id)

@authorize_required
async def buckets(self, types: list = ["all"]
) -> AsyncGenerator[BucketModel, AwaitingBucket]:
) -> AsyncGenerator[
Tuple[BucketModel, AwaitingBucket], None]:
"""Lists buckets.
Parameters
Expand All @@ -204,9 +223,12 @@ async def buckets(self, types: list = ["all"]
Used for interacting with bucket.
"""

data = await self._post(
url=self._routes.bucket.list,
json={"bucketTypes": types}
data = cast(
dict,
await self._post(
url=self._routes.bucket.list,
json={"bucketTypes": types}
)
)

for bucket in data["buckets"]:
Expand Down Expand Up @@ -313,16 +335,19 @@ def download_by_name(self, bucket_name: str, file_name: str,
params = settings.parameters
headers = settings.headers

return self._get(
url="{}/{}/{}".format(
self._routes.download.file,
bucket_name,
file_name
),
headers=headers,
params=params,
resp_json=False,
include_account=False
return cast(
bytes,
self._get(
url="{}/{}/{}".format(
self._routes.download.file,
bucket_name,
file_name
),
headers=headers,
params=params,
resp_json=False,
include_account=False
)
)

@authorize_required
Expand All @@ -342,17 +367,20 @@ def create_key(self, settings: KeySettings
BlockingKey
"""

data = self._post(
json=settings.payload,
url=self._routes.key.create
data = cast(
dict,
self._post(
json=settings.payload,
url=self._routes.key.create
)
)

return KeyModel(data), self.key(data["applicationKeyId"])

@authorize_required
def keys(self, limit: int = 100,
start_key_id: str = None
) -> Generator[KeyModel, AwaitingKey, None]:
) -> Generator[Tuple[KeyModel, BlockingKey], None, None]:
"""Used to list keys.
Parameters
Expand All @@ -366,12 +394,18 @@ def keys(self, limit: int = 100,
-------
KeyModel
Holds details on key.
AwaitingKey
BlockingKey
"""

data = self._post(
url=self._routes.key.list,
json={"maxKeyCount": limit, "startApplicationKeyId": start_key_id}
data = cast(
dict,
self._post(
url=self._routes.key.list,
json={
"maxKeyCount": limit,
"startApplicationKeyId": start_key_id
}
)
)

for key in data["keys"]:
Expand Down Expand Up @@ -410,16 +444,21 @@ def create_bucket(self, settings: BucketSettings
Used to interact with a bucket.
"""

data = BucketModel(self._post(
url=self._routes.bucket.create,
json=settings.payload,
))
data = BucketModel(
cast(
dict,
self._post(
url=self._routes.bucket.create,
json=settings.payload,
)
)
)

return data, self.bucket(data.bucket_id)

@authorize_required
def buckets(self, types: list = ["all"]
) -> Generator[BucketModel, BlockingBucket, None]:
) -> Generator[Tuple[BucketModel, BlockingBucket], None, None]:
"""Lists buckets.
Parameters
Expand All @@ -435,9 +474,12 @@ def buckets(self, types: list = ["all"]
Used for interacting with bucket.
"""

data = self._post(
url=self._routes.bucket.list,
json={"bucketTypes": types}
data = cast(
dict,
self._post(
url=self._routes.bucket.list,
json={"bucketTypes": types}
)
)

for bucket in data["buckets"]:
Expand Down
2 changes: 1 addition & 1 deletion backblaze/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .cache import Cache


__version__ = "0.0.8"
__version__ = "0.1.0"
__url__ = "https://backblaze.readthedocs.io/en/latest/"
__description__ = "Wrapper for Backblaze's B2."
__author__ = "WardPearce"
Expand Down

0 comments on commit 173b8de

Please sign in to comment.