在Kiwix/OpenZIM项目中使用的Kiwix S3缓存包装器
kiwixstorage的Python项目详细描述
猕猴桃贮藏室
S3存储的助手,来自URL+Wasabi的autoconf(wasabisys.com网站)额外费用
目标主要是从一个URL提供一个配置好的s3.client和s3.resource 用户可以将使用限制在这个范围内,并直接从那里使用boto3。在
为了简化常见的操作,还准备了一些附加的包装器。 另外,非S3、wasabi特有的特性也会直接暴露出来。在
使用
pip install kiwixstorage
连接
^{pr2}$铲运机使用案例
online_url="https://xxx"fpath="/local/path.ext"# retrieve origin etagetag=requests.head(online_url,allow_redirects=True).headers.get("Etag")# check if we have that very same version in storeifs3.has_matching_object(key=url,etag=etag)# lastest version in our store, download from there (using progress output)s3.download_file(key=url,fpath=fpath,progress=True)else:# download the origin file using your regular toolsdownload_file(url,fpath)# upload it our storages3.upload_file(fpath=fpath,key=url)# now you have a local file of lastest version and the storage is up to date
其他用例
# create a bucketbucket=s3.create_bucket("bucket_name")# set auto-delete on buckets3.set_bucket_autodelete_after(nb_days=7)# allow public downloads from buckets3.allow_public_downloads_on()# upload a files3.upload_file(fpath,"some/path/file.img",meta={"ENCODER_VERSION":"v1"})# set autodelete on specific files3.set_object_autodelete_on(key,datetime.datetime.now())# download a files3.download_file(key,fpath)# get URL for external downloads3.get_download_url(key)
资源:
- https://wasabi.com/wp-content/themes/wasabi/docs/API_Guide
- https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html
- 项目
标签: