Skip to main content

Kiwix S3 Cache wrapper to use within Kiwix/OpenZIM projects

Project description

kiwixstorage

CodeFactor License: GPL v3 PyPI version shields.io

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


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.1.tar.gz (35.9 kB view details)

Uploaded Source

Built Distribution

kiwixstorage-0.8.1-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file kiwixstorage-0.8.1.tar.gz.

File metadata

  • Download URL: kiwixstorage-0.8.1.tar.gz
  • Upload date:
  • Size: 35.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6

File hashes

Hashes for kiwixstorage-0.8.1.tar.gz
Algorithm Hash digest
SHA256 d6b9998d5d491ec998472fd6aaede304ab4eddfeefdad730fe5f035889eed5d4
MD5 90f69763b46245b7c5aac575b792cfbc
BLAKE2b-256 d3a16eaee64162c9f1fe5838157bd1afa18cadef77898572bff8957cff49078c

See more details on using hashes here.

Provenance

File details

Details for the file kiwixstorage-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: kiwixstorage-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.6

File hashes

Hashes for kiwixstorage-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf85c1215e0f0daaa2eb3a39f466a3ac5908ade39435517fd67246ab22de56aa
MD5 4a2c6ca22a8517c850f15dff6fb58228
BLAKE2b-256 b96e034660b634dc8e848c8bde92c7f49d13f3f1c776991f867a43881272ebd9

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page