void-ux / aiob2 Goto Github PK
View Code? Open in Web Editor NEWA modern and Pythonic Backblaze B2 API wrapper
Home Page: https://aiob2.readthedocs.io/en/latest/
License: MIT License
A modern and Pythonic Backblaze B2 API wrapper
Home Page: https://aiob2.readthedocs.io/en/latest/
License: MIT License
If you create an aiob2.Client
instance, then use it to fire off multiple concurrent operations, multiple coroutines can be in the section between testing and setting the underlying HTTPClient._authorization_token
, resulting in multiple authentication calls.
Example code:
import os
import asyncio
from aiob2 import Client
keys = [
"some-big-file",
"some-small-file"
]
async def download_file(client, bucket, key):
print(f"About to download {bucket}/{key}")
f = await client.download_file_by_name(
file_name=key,
bucket_name=bucket,
)
print(f"Downloaded {bucket}/{key}: {f.content_length} bytes")
return f.content_length
async def main():
print(f"Downloading objects {keys}")
async with Client(os.environ["B2_APPLICATION_KEY_ID"], os.environ["B2_APPLICATION_KEY"]) as client:
sizes = await asyncio.gather(*(download_file(client, "my-bucket", key) for key in keys))
print(f"Object sizes: {sizes}")
if __name__ == '__main__':
asyncio.run(main())
Output:
Downloading objects ['some-big-file', 'some-small-file']
About to download my-bucket/some-big-file
2023-05-04 13:17:15 INFO aiob2.http Authenticating using static application key
About to download my-bucket/some-small-file
2023-05-04 13:17:15 INFO aiob2.http Authenticating using static application key
Downloaded my-bucket/some-small-file: 6 bytes
Downloaded my-bucket/some-big-file: 15729152 bytes
Object sizes: ['15729152', '6']
The second download doesn't "see" the token retrieved by the first download.
Assuming the goal is to have the HTTPClient
authenticate just once, I'm not sure it's possible to do 'lazy' authentication without synchronizing on HTTPClient._authorization_token
. It might be easier to just have HTTPClient
authenticate in its constructor. In case of authentication failure, that's probably a better (more obvious to the developer) place to throw the error than the first time the client is used.
In DownloadedFile
, it's unclear what this code is doing:
if (expires := headers.get('cache-control')) is not None:
expires = datetime.datetime.strptime(expires, '%a, %d %b %Y %H:%M:%S %Z')
else:
expires = None
self.expires: Optional[datetime.datetime] = expires
The value of the cache-control
header is assigned to expires
, which is then parsed as a timestamp.
I think it should be:
self.cache_control: Optional[str] = headers.get('cache-control')
if (expires := headers.get('expires')) is not None:
expires = datetime.datetime.strptime(expires, '%a, %d %b %Y %H:%M:%S %Z')
else:
expires = None
self.expires: Optional[datetime.datetime] = expires
Let me know if my understanding is correct and I'll file the PR.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.