Skip to main content

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

Project description

filelayer

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]

Local filesystem example

Environment:

STORAGE_PROVIDER=local
STORAGE_DEFAULT_PREFIX=my-app
STORAGE_ENCODING=utf-8
LOCAL_STORAGE_BASE_PATH=./data/storage

Usage:

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

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.

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.0.tar.gz (9.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.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: filelayer-0.1.0.tar.gz
  • Upload date:
  • Size: 9.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.0.tar.gz
Algorithm Hash digest
SHA256 25b99a287b0e2eddd00ca341dd070123d97bda3b5f6f5ec8e594c521a1e0d170
MD5 e3683b906ba534063b43cb8651b71dc3
BLAKE2b-256 50419956a0d2c51821d29751331dda983682ec0b1daa5342446a2a6bcaedf6d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: filelayer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06024eb861679528e643dcdcef584240adb6ba429cb228e4ac8c32e297e84efa
MD5 fd9b42df2f0036bdb2cc473e1364b192
BLAKE2b-256 c2e2694356ea693b88d97840150121f8dca02bac1298893fe1fbda197f696fc2

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