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) -> strwrite_file(filepath, file_content) -> Noneread_file_bytes(filepath) -> byteswrite_file_bytes(filepath, file_bytes) -> Noneexists(filepath) -> boolresolve_path(filepath) -> str
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"))
print(storage.resolve_path("documents/example.txt"))
# → /absolute/path/to/data/storage/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"))
print(storage.resolve_path("documents/example.txt"))
# → s3://your-bucket/my-app/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_PREFIXis prepended to all paths or keys.write_file()stores text usingSTORAGE_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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file filelayer-0.2.0.tar.gz.
File metadata
- Download URL: filelayer-0.2.0.tar.gz
- Upload date:
- Size: 34.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa95a18e08f973b3d9400673105780a0ca70c493d695a8c0d865d81e4dc1c955
|
|
| MD5 |
c088ffffd269db0cd69edf7f7b0133e4
|
|
| BLAKE2b-256 |
718bdfe9a7689b8cc8a65907b2665dac0e119f8b819c684d989fc235e37edc12
|
Provenance
The following attestation bundles were made for filelayer-0.2.0.tar.gz:
Publisher:
publish-to-pypi.yml on sireto/filelayer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
filelayer-0.2.0.tar.gz -
Subject digest:
fa95a18e08f973b3d9400673105780a0ca70c493d695a8c0d865d81e4dc1c955 - Sigstore transparency entry: 1233841250
- Sigstore integration time:
-
Permalink:
sireto/filelayer@ddd55e3f03962a772e76828d4fb60a2b3cd31a44 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/sireto
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ddd55e3f03962a772e76828d4fb60a2b3cd31a44 -
Trigger Event:
push
-
Statement type:
File details
Details for the file filelayer-0.2.0-py3-none-any.whl.
File metadata
- Download URL: filelayer-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df66f8e0ed35a4e230086537e885e66817235e82fc2a08471275e90e0a1a1532
|
|
| MD5 |
68846a89efaa106172f38b2ad657f479
|
|
| BLAKE2b-256 |
5ed23025ac1ff12cfe04c5197d94f1ef01b041695f916103ca89b8db9ca1b291
|
Provenance
The following attestation bundles were made for filelayer-0.2.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on sireto/filelayer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
filelayer-0.2.0-py3-none-any.whl -
Subject digest:
df66f8e0ed35a4e230086537e885e66817235e82fc2a08471275e90e0a1a1532 - Sigstore transparency entry: 1233841259
- Sigstore integration time:
-
Permalink:
sireto/filelayer@ddd55e3f03962a772e76828d4fb60a2b3cd31a44 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/sireto
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ddd55e3f03962a772e76828d4fb60a2b3cd31a44 -
Trigger Event:
push
-
Statement type: