Skip to main content

File-like interface for cloud block storage

Project description

Superfile

Simple Python file-like interface for cloud block storage. This is unlikely to be the most performant way do I/O with data from block storage, but it provides a uniform, simple API that can be used across multiple cloud block storage providers such as Google Cloud Storage, Amazon S3 and Azure Blob Storage.

Simple Usage

Importing the main module:

import superfile

Reading a local file:

with superfile.open('my/local/path', 'r') as f:
  contents = f.read()

Reading a text file:

with superfile.open('gs://my_bucket_name/file.txt', 'r') as f:
  text = f.read()

Reading a binary file:

with superfile.open('gs://my_bucket_name/file.ext', 'rb') as f:
  data = f.read()

Writing a text file:

text = 'hello world'
with superfile.open('gs://my_bucket_name/file.txt', 'w') as f:
  f.write(text)

Writing a binary file:

data = b'hello world'
with superfile.open('gs://my_bucket_name/file.txt', 'wb') as f:
  f.write(data)

Listing all files in a bucket:

fnames = list(superfile.list('gs://my_bucket_name'))

Listing files with a prefix from a bucket:

prefix = 'abc'
fnames = list(superfile.list(f'gs://my_bucket_name/{prefix}'))

Advanced Usage

Reading a file from GCS and providing auth credentials:

import superfile
from google.oauth2 import service_account

fpath = 'gs://my_bucket_name/file.txt'
creds = service_account.Credentials.from_service_account_file('/path/to/key.json')
with superfile.open(
  path=fpath,
  mode='r',
  # All init_kwargs are passed to google.cloud.storage.Client.__init__().
  init_kwargs=dict(credentials=creds),
  # All open_kwargs are passed to google.cloud.storage.Blob.open().
  open_kwargs=dict(errors='strict'),
) as f:
  ...

Reading a file from S3 and providing endpoint URL:

import superfile

fpath = 's3://my_bucket_name/file.txt'
endpoint_url = 'https://example.com'
with superfile.open(
  path=fpath,
  mode='r',
  # All init_kwargs are passed to boto3.client().
  init_kwargs=dict(endpoint_url=endpoint_url),
  # All open_kwargs are passed to boto3.client.get_object() or boto3.client.put_object().
  open_kwargs=dict(VersionId='...'),
) as f:
  ...

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

superfile-0.0.7.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

superfile-0.0.7-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file superfile-0.0.7.tar.gz.

File metadata

  • Download URL: superfile-0.0.7.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for superfile-0.0.7.tar.gz
Algorithm Hash digest
SHA256 77bf217356ca446b94ee658cd17c9dfc774c652bf811d7df9e187bed80aa1748
MD5 a79014751ec9cf1dc697db24a38efa9d
BLAKE2b-256 a723e5611f51c68d5e3d519bdb7d043a3981fab56cca5ec6b7588f8a8105d6d7

See more details on using hashes here.

File details

Details for the file superfile-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: superfile-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for superfile-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0f62f32c4e82e3d03ac57b1e4f8632896f472e8b3988c23959553de7ef2cba31
MD5 ada5e9ebba28e669fbeb3ed4f0cdb2c6
BLAKE2b-256 738d51d6366eb3198a6523417f2dae158347b95f369b303970384461ae6cf026

See more details on using hashes here.

Supported by

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