Skip to main content

s3-avldb

PyPI Python versions CI License: Apache-2.0 OR GPL-3.0-only

s3-avldb provides an S3Backend for avldb — a typed embedded document database with Rust-backed AVL indexes. With S3Backend you can use any AWS S3 bucket (or S3-compatible store such as MinIO or LocalStack) as durable storage.

Installation

pip install s3-avldb

Python 3.10+ and CPython are supported.

Quick start

import boto3
from avldb import Collection, Document
from s3avldb import S3Backend


class User(Document):
    name: str
    age: int


backend = S3Backend(bucket="my-bucket", prefix="users/")

with Collection(User, backend=backend) as users:
    users.ensure_index("age")
    users.insert(User(name="Ada", age=36))
    users.insert(User(name="Grace", age=29))

    adults = users.find({"age": {"$gte": 18}}).sort({"age": -1}).all()

Configuration

S3Backend(
    bucket="my-bucket",       # S3 bucket name
    prefix="myapp/users/",    # optional key prefix (no leading slash)
    client=None,              # inject a pre-configured boto3 S3 client, or None to create one
    endpoint_url=None,        # override endpoint for MinIO / LocalStack / other S3-compatible stores
    max_fetch_workers=None,   # default: all available logical CPUs; pass an int to limit
)

When client is None, S3Backend creates a boto3 S3 client on first use; standard boto3 credential discovery applies (environment variables, ~/.aws/credentials, instance profiles, etc.). Document reads use a bounded thread pool and preserve the backend's iteration order. By default its size is the number of logical CPUs available to the process; set max_fetch_workers to a positive integer to override it. When injecting your own boto3 client, configure its max_pool_connections to at least the resolved worker count; internally created clients are configured automatically.

How it works

S3Backend follows the same StorageBackend / BackendView contract as avldb's built-in DiskBackend and MemoryBackend. The S3 object layout is:

{prefix}/manifest.json               ← atomic commit marker
{prefix}/content/{uuid}.jsonl        ← immutable JSONL content segments
{prefix}/indexes/{field_hash}/{uuid}.jsonl  ← immutable JSONL index segments

Atomicity is achieved via S3 conditional writes (If-Match on PutObject): the manifest's ETag is used as an optimistic concurrency token. A conflicting commit from another writer raises WriteConflictError exactly as it would with DiskBackend.

Indexes are loaded into in-memory AVL trees at open() time. Index segment objects are downloaded concurrently using the configured fetch worker count, then decoded and replayed in manifest order to preserve update semantics. Documents are fetched lazily through concurrent byte-range GetObject calls.

No distributed lock is acquired — multiple processes may safely open the same prefix concurrently using optimistic concurrency.

Compaction

with Collection(User, backend=S3Backend("my-bucket", "users/")) as users:
    users.backend.compact()

Compaction consolidates all live data into a new content segment and updates the manifest, reducing the objects that future opens need to read. Previous segments are retained because an existing immutable view—or another process—may still reference them. Configure an S3 lifecycle rule if you want to reclaim superseded segments after a retention period suitable for your application.

Non-AWS S3 stores

backend = S3Backend(
    bucket="test-bucket",
    endpoint_url="http://localhost:9000",  # MinIO
)

Or inject a pre-built client:

import boto3
client = boto3.client("s3", endpoint_url="http://localhost:9000")
backend = S3Backend(bucket="test-bucket", client=client)

License

Copyright 2026 Anuradha Wickramarachchi.

Like avldb, s3-avldb is available under your choice of the Apache License 2.0 or the GNU General Public License v3.0 only. See the dual-license notice for details.

Download files

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

Source Distribution

s3_avldb-0.1.0.tar.gz (113.3 kB view details)

Uploaded Source

Built Distribution

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

s3_avldb-0.1.0-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: s3_avldb-0.1.0.tar.gz
  • Upload date:
  • Size: 113.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for s3_avldb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f7bd2013e80bb2336f449cf9a27cce0f15e23ed787fe90a75912705a621ba6bf
MD5 6e6a5656503f42f4048c1dad1c299232
BLAKE2b-256 f5530ed4d50c26ba8208e56d2a52351e5f6f0cf7bc1140313655be1db1ff002f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: s3_avldb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for s3_avldb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b4caec0f30473bdf601eaf1c20f58f7e31766eaff3f0899d6f5d22cf7dcbfc9
MD5 64fc6790af600afb21b2b6b02fb3040a
BLAKE2b-256 38a1ce3697a09e51fc79b93d3d831a449dbf4a2de17a7d3311d4e5dab8424777

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page