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"))

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.2.tar.gz (12.4 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.2-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: filelayer-0.1.2.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for filelayer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ad452ca754fb277d54707e6961eac49cd7e44630f24c3872d697f3d75cdff58f
MD5 4774f79e70e642bb4c0caa0f5cafd760
BLAKE2b-256 b68cfa1e8e56a1fafa85430e55b11aa11f6f882a7077537a8e1fa224f6554d92

See more details on using hashes here.

File details

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

File metadata

  • Download URL: filelayer-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for filelayer-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 982e077a60ef373fec8f350451fd041af3efe2bb04bc97ee77e0ee944e704a6c
MD5 e9747c0ad70871fe65415e352908e3e1
BLAKE2b-256 5beb6afc8625cdefa8c1d9d1fb71ee5ad7054bc98a9b0d8fcbd1f66d1579f542

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