Filesystem
Titancore provides local and S3-compatible disks through fsspec and s3fs. S3-compatible endpoints include Cloudflare R2 and local object storage servers. File operations run in worker threads.
Save disk configuration in config/filesystem.yaml.
default: local
disks:
local:
driver: local
root: storage/app
objects:
driver: s3
bucket: application-files
root: uploads
options:
client_kwargs:
endpoint_url: https://ACCOUNT_ID.r2.cloudflarestorage.com
region_name: auto
For AWS S3, omit endpoint_url and use the SDK credential chain.
For R2 or a local server, provide credentials through the process environment
or the configured SDK options. Keep credentials out of tracked YAML files.
The options mapping passes directly to s3fs, including key, secret,
token, and client_kwargs.
Register the provider after configuration bootstrap.
from titancore import Application
from titancore.facades import Storage
from titancore.filesystem import FilesystemServiceProvider
from titancore.foundation.bootstrap import default_bootstrappers
app = Application()
app.bootstrap_with(default_bootstrappers())
app.register(FilesystemServiceProvider(app.base_path))
async with app:
await Storage.put("reports/latest.txt", "hello")
contents = await Storage.get("reports/latest.txt")
assert contents == b"hello"
objects = await Storage.disk("objects")
await objects.put("report.txt", contents)
put accepts bytes or UTF-8 text. get returns bytes. Disks also expose
exists, missing, delete, copy, move, size, and all_files.
The facade forwards these operations to the default disk. temporary_url
creates a signed download URL for an S3-compatible disk. Its expires
argument is a lifetime in seconds, defaulting to 3600.
Disk paths are relative to their configured root. Absolute paths, parent traversal, null characters, and backslashes are rejected. Existing local symlinks are resolved before checking confinement. Applications must keep local storage directories under trusted ownership.
Reads raise FileNotFoundError for missing files. Deleting a missing local
file returns false. Backend failures propagate to the caller. A move copies
the object before deleting its source, and concurrent writes follow backend
semantics. File reads load the complete file into memory.
The application container owns managers and closes resolved disks during
shutdown. Filesystem and FilesystemManager contracts live in
titancore.contracts.filesystem. The manager resolves through its concrete
type, contract, and "filesystem" key. HTTP response generation remains the
HTTP kernel's responsibility.