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.6.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.6-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: superfile-0.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 71464454c668193e9306a9a61d44d56e81888fae58193dd92a65844a1ff20458
MD5 b684a88bd324fcb9f4fcfe6f421b55e1
BLAKE2b-256 4bbcc5a67cb95ca8011ea760cbe4bff2c70183800f4e820c67f71feada84d33e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: superfile-0.0.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f9fe4e796c18a269a79605f25186a5fd5ecd2eaa69e29d5089da14a3b3821a1e
MD5 351283cdf41f62d0a9ed9af3dba83cdf
BLAKE2b-256 a86be3da0463feaec911c319d42e2270c571d0940d8870fe7a27ce310b966b4c

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