Skip to main content

Simple file access abstraction over local filesystem and S3-compatible storage.

Project description

filelayer

CI PyPI version License: MIT Python 3.11+

filelayer is a small Python package that provides a simple file abstraction over:

  • local filesystem
  • S3-compatible object storage such as Wasabi

It exposes a minimal API:

  • read_file(filepath) -> str
  • write_file(filepath, file_content) -> None
  • read_file_bytes(filepath) -> bytes
  • write_file_bytes(filepath, file_bytes) -> None
  • exists(filepath) -> bool

For S3-compatible backends, filepath is treated as the object key. For local storage, filepath is resolved relative to the configured local base path.

Installation

pip install filelayer

For development:

pip install -e .[dev]

Quick start

No configuration needed — local filesystem is the default:

from filelayer import StorageService

storage = StorageService.from_settings()

storage.write_file("documents/example.txt", "Hello from local storage")
content = storage.read_file("documents/example.txt")
print(content)

storage.write_file_bytes("documents/example.bin", b"\x00\x01\x02")
print(storage.read_file_bytes("documents/example.bin"))
print(storage.exists("documents/example.txt"))

By default, files are stored under ./data/storage. You can customize this and other settings via environment variables or a .env file:

STORAGE_PROVIDER=local          # default
STORAGE_DEFAULT_PREFIX=my-app   # optional path prefix
STORAGE_ENCODING=utf-8          # default
LOCAL_STORAGE_BASE_PATH=./data/storage  # default

Wasabi / S3-compatible example

Environment:

STORAGE_PROVIDER=s3
STORAGE_DEFAULT_PREFIX=my-app
STORAGE_ENCODING=utf-8

S3_ENDPOINT_URL=https://s3.eu-central-1.wasabisys.com
S3_ACCESS_KEY_ID=your-access-key
S3_SECRET_ACCESS_KEY=your-secret-key
S3_REGION_NAME=eu-central-1
S3_BUCKET=your-bucket
S3_USE_SSL=true
S3_VERIFY_SSL=true
S3_ADDRESSING_STYLE=virtual
S3_CONNECT_TIMEOUT=10
S3_READ_TIMEOUT=60
S3_MAX_ATTEMPTS=5

Usage:

from filelayer import StorageService

storage = StorageService.from_settings()

storage.write_file("documents/example.txt", "Hello from Wasabi")
print(storage.read_file("documents/example.txt"))
print(storage.exists("documents/example.txt"))

S3 caching

The S3 provider caches downloaded objects on the local filesystem to save bandwidth. Caching is enabled by default and uses ETag-based revalidation — on repeated reads, a conditional GET is sent to S3. If the object hasn't changed (304 Not Modified), the cached copy is used. Writes are write-through: after a successful upload, the content is stored in the cache immediately.

S3_CACHE_ENABLED=true                    # default, set to false to disable
S3_CACHE_DIR=/tmp/filelayer_cache        # default: system temp directory

Notes

  • STORAGE_DEFAULT_PREFIX is prepended to all paths or keys.
  • write_file() stores text using STORAGE_ENCODING.
  • write_file_bytes() stores raw bytes unchanged.
  • Local provider prevents path traversal outside the configured storage root.

Contributing

Contributions are welcome! See CONTRIBUTING.md for development setup and guidelines.

License

This project is licensed under the MIT License.

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

filelayer-0.1.4.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

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

filelayer-0.1.4-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file filelayer-0.1.4.tar.gz.

File metadata

  • Download URL: filelayer-0.1.4.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for filelayer-0.1.4.tar.gz
Algorithm Hash digest
SHA256 03c04515605c5fbb0be38d7f9ac1cdbaac0df0f3ea59de063a7a252410cfa561
MD5 0a56f8dd808be21be0a0bcbdd48d77a7
BLAKE2b-256 1cac45cefc16824c1ecc3ec1e3167fe738816c4ce22bbfb484e7f513f23bba76

See more details on using hashes here.

Provenance

The following attestation bundles were made for filelayer-0.1.4.tar.gz:

Publisher: publish-to-pypi.yml on sireto/filelayer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file filelayer-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: filelayer-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for filelayer-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cad9e3ef350914ca1d6fd552e2220bf107aa050409a21a39619e993023e166f0
MD5 dbe4a34e5b407b90d3d2a6d0f970ba15
BLAKE2b-256 78bed8862c9cb47e36811b4684fc9212f644975ed3e33b1d60b94594886d8c9a

See more details on using hashes here.

Provenance

The following attestation bundles were made for filelayer-0.1.4-py3-none-any.whl:

Publisher: publish-to-pypi.yml on sireto/filelayer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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