Skip to main content

byoc-storage

PyPI Python Tests Types License

Python SDK for BYOC (Bring Your Own Cloud): one storage API for Google Drive, Nextcloud, and S3-compatible clouds, so files live in accounts the end user already owns.

Part of the BYOC monorepo. Peer implementation of @byoc/core on npm, verified interoperable by an automated cross-SDK suite.

Why

Rather than paying to host every file in one central bucket, BYOC lets an application read and write storage the end user already owns: a personal Google Drive, a company Nextcloud, an organization's own R2 bucket.

FastAPI / Django / Celery
   │
   ├── PostgreSQL  → users, jobs, metadata pointers
   │
   └── byoc        → the actual PDFs, images, audio, model artifacts
           │
           └── the user's own cloud

Use Postgres for application data. Use BYOC for the user's files.

Install

pip install byoc-storage

The distribution is named byoc-storage because byoc on PyPI belongs to an unrelated CLI framework. The import name is still byoc:

import byoc

If you also depend on the unrelated byoc CLI framework, do not install both into the same environment: they share the byoc import name and will shadow each other.

Usage

Start with no credentials at all. LocalFileSystemProvider and MemoryProvider are bundled, need no account and no network, and behave like every other provider:

from byoc import AsyncBYOC, LocalFileSystemProvider

storage = AsyncBYOC(provider=LocalFileSystemProvider("./storage"))

async with storage:
    await storage.write_text("documents/welcome.md", "# Hello from BYOC!")
    content = await storage.read_text("documents/welcome.md")

Swap in S3CompatibleProvider, WebDAVProvider, or GoogleDriveProvider and none of the calling code changes:

import os
from byoc import AsyncBYOC
from byoc.providers.s3 import S3CompatibleProvider

storage = AsyncBYOC(
    provider=S3CompatibleProvider(
        endpoint="https://<account_id>.r2.cloudflarestorage.com",
        bucket="user-assets",
        region="auto",
        access_key_id=os.environ["R2_ACCESS_KEY_ID"],
        secret_access_key=os.environ["R2_SECRET_ACCESS_KEY"],
    )
)

async with storage:
    await storage.write_text("documents/welcome.md", "# Hello from BYOC!")
    content = await storage.read_text("documents/welcome.md")

Testing without a cloud

MemoryProvider is a test double that behaves like a real provider, so your tests exercise the same code path production does:

from byoc import AsyncBYOC, MemoryProvider

async def test_report_is_archived():
    provider = MemoryProvider()
    await archive_report(AsyncBYOC(provider=provider), report)

    assert provider.snapshot() == {"reports/q3.pdf": b"..."}

Like S3, it models a flat object store and reports folders=False. If your production provider has real folders, use LocalFileSystemProvider against a tmp_path instead.

Multiple providers and migration

storage = AsyncBYOC(providers=[drive, r2, nextcloud], default_provider_id="s3-compatible")

storage.use_provider("webdav")
await storage.write_bytes("images/banner.png", data)

report = await storage.migrate(
    source="s3-compatible",
    target="webdav",
    paths=["documents/report.pdf"],
    on_progress=lambda p: print(f"{p.current_file} ({p.percentage}%)"),
)

report.files_partial counts files that reached the target but whose source cleanup failed. The transfer is done, so retrying those would re-upload for nothing.

Async only for now. A synchronous facade for Celery, Django, and scripts is planned but not yet implemented; use asyncio.run() in the meantime.

Google Drive

Drive needs a Google Cloud OAuth client. See Google Drive OAuth Setup, then verify your setup with:

.venv/bin/python scripts/validate_gdrive_live.py

Cross-SDK compatibility

This SDK and the TypeScript SDK are peer implementations of the same contract. Both run against the shared conformance vectors in spec/fixtures, so a file written by a Next.js frontend can be read by a FastAPI backend, including client-side encrypted files, whose envelope format is byte-identical across both.

Development

python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

pytest              # unit + conformance suite
mypy src            # strict type checking
ruff check .        # lint

Without activating, call the venv binaries directly: .venv/bin/pytest, .venv/bin/mypy src, .venv/bin/ruff check .

License

Apache-2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

byoc_storage-0.3.0.tar.gz (152.5 kB view details)

Uploaded Source

Built Distribution

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

byoc_storage-0.3.0-py3-none-any.whl (69.5 kB view details)

Uploaded Python 3

File details

Details for the file byoc_storage-0.3.0.tar.gz.

File metadata

  • Download URL: byoc_storage-0.3.0.tar.gz
  • Upload date:
  • Size: 152.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for byoc_storage-0.3.0.tar.gz
Algorithm Hash digest
SHA256 df9492d730da2ccea5229e2d389897e96efa370e0c25e45ed95349f2f9c03d97
MD5 d226eec0a7988cab32480664fcf310bd
BLAKE2b-256 69d492ce28da4d5112f84f549c6933b74a9acf55928e904955a6239bade4d63b

See more details on using hashes here.

File details

Details for the file byoc_storage-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: byoc_storage-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 69.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for byoc_storage-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fdb07bde1aee7891cd2a2bfa56b8400366a61636c0fbfecf36888630d69a6e5e
MD5 39d3c8c054bbd3486e1a120d7d96bdff
BLAKE2b-256 caf7c0e3c0a53563676249b744a0451fc193f91b28a7e665dd90d10958ad2622

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

This release

0.3.0 This release

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page