Kiwix S3 Cache wrapper to use within Kiwix/OpenZIM projects
Project description
kiwixstorage
helpers for S3 storage, autoconf from URL + Wasabi (wasabisys.com) extras
Goal is mainly to provide a configured s3.client and s3.resource from an URL Users could limit usage to this and use boto3 directly from there.
A few additional wrappers are in place to simplify common actions. Also, non-S3, wasabi-specific features are exposed directly.
Usage
pip install kiwixstorage
Connection
from kiwixstorage import KiwixStorage
url = "https://s3.us-east-1.wasabisys.com/?keyId=x&secretAccessKey=y&bucketName=z"
s3 = KiwixStorage(url)
# test credentials and ensure we can list buckets
if not s3.check_credentials(list_buckets=True, failsafe=True):
return # bad auth
Scraper use-case
online_url = "https://xxx"
fpath = "/local/path.ext"
# retrieve origin etag
etag = requests.head(online_url, allow_redirects=True).headers.get("Etag")
# check if we have that very same version in store
if s3.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 tools
download_file(url, fpath)
# upload it our storage
s3.upload_file(fpath=fpath, key=url)
# now you have a local file of lastest version and the storage is up to date
Other use cases
# create a bucket
bucket = s3.create_bucket("bucket_name")
# set auto-delete on bucket
s3.set_bucket_autodelete_after(nb_days=7)
# allow public downloads from bucket
s3.allow_public_downloads_on()
# upload a file
s3.upload_file(fpath, "some/path/file.img", meta={"ENCODER_VERSION": "v1"})
# set autodelete on specific file
s3.set_object_autodelete_on(key, datetime.datetime.now())
# download a file
s3.download_file(key, fpath)
# get URL for external download
s3.get_download_url(key)
Resources:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kiwixstorage-0.8.2.tar.gz
(36.8 kB
view details)
Built Distribution
File details
Details for the file kiwixstorage-0.8.2.tar.gz
.
File metadata
- Download URL: kiwixstorage-0.8.2.tar.gz
- Upload date:
- Size: 36.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3cd3f2a6f5a93c5f8274a027576948316b1785a1f3bdf1606fb8b94d619864a |
|
MD5 | 4121bb6c152eac0a4ad03dbc5a84847c |
|
BLAKE2b-256 | b18fc507e20b0ba3d503b2835217b7a63c4836a7ab04133d876b7f21b8b6dbfe |
Provenance
File details
Details for the file kiwixstorage-0.8.2-py3-none-any.whl
.
File metadata
- Download URL: kiwixstorage-0.8.2-py3-none-any.whl
- Upload date:
- Size: 35.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7488ffaf3faf508edf20c193f1852ff12e1666c9db6fa774ad928740b69fa1a8 |
|
MD5 | b27868a0769271802815f38c67854c89 |
|
BLAKE2b-256 | 87413c6ebed82f4e70d5e1f0316057cc9e6cdbe20ec231cb1f84be294286fc12 |