Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

FDB Record Layer for Python

CI PyPI Python License

⚠️ Disclaimer: This is an AI-assisted reimplementation of the Java FoundationDB Record Layer, written with Claude (Anthropic). It is not affiliated with or endorsed by Apple or the FoundationDB team.

Status: beta. The API may still change between releases. Test it with your workload before using it in production.

A Python implementation of the FoundationDB Record Layer: a record-oriented store with Protocol Buffer schemas, secondary indexes and a query planner on top of FoundationDB.

Features

  • Record store: save, load, scan and delete Protocol Buffer messages, with transactional retries
  • Secondary indexes: VALUE, COUNT, SUM, RANK and TEXT indexes, maintained on every write
  • Query API: a declarative query builder with a heuristic planner (a Cascades cost-based planner is included and experimental)
  • Continuations: cursor-based pagination across transactions
  • Java interoperability: JavaCompatibleStore reads and writes the Java Record Layer's on-disk format
  • Schema evolution checks: validate that a metadata change is safe before deploying it
  • SQL (experimental): SQL parser and executor. SELECT can run against a record store; CREATE/INSERT/UPDATE/DELETE currently work on an in-memory table only
  • Operational utilities: circuit breakers, health checks, graceful shutdown, metrics, caching
  • async/await throughout

Requirements

Component Supported versions
Python 3.11 – 3.15
FoundationDB server and client library 7.4 or 8.0 (tested in CI with 7.4.10 and 8.0.1)
foundationdb Python package Same major.minor as your client library
protobuf 6.33.2 or newer (including 7.x)

The library uses FDB API version 740, which both 7.4 and 8.0 clients support.

Installation

  1. Install the FoundationDB client library for your platform from the FoundationDB releases.

  2. Install the package together with the matching Python binding:

    # FoundationDB 8.0 client
    pip install fdb-record-layer "foundationdb~=8.0.0"
    
    # FoundationDB 7.4 client
    pip install fdb-record-layer "foundationdb~=7.4.0"
    

    The foundationdb 8.x binding refuses to load a 7.4 client library, so pin it when you use 7.4.

  3. For SQL support, add the sql extra: pip install "fdb-record-layer[sql]".

To run a local FoundationDB in Docker, see Local FoundationDB.

Quick start

The code below is taken from examples/quickstart.py, which CI runs against FoundationDB 7.4 and 8.0 on every push.

Define your schema

Records are Protocol Buffer messages. Given examples/sample.proto compiled with protoc --python_out=. sample.proto:

import fdb_record_layer as frl
from sample_pb2 import DESCRIPTOR, Person

metadata = (
    frl.RecordMetaDataBuilder(DESCRIPTOR)
    .set_record_type("Person", primary_key=frl.field("id"))
    .add_index("Person", "person_by_name", frl.field("name"))
    .add_index("Person", "person_by_city_age", frl.concat(frl.field("city"), frl.field("age")))
    .build()
)

Save and load records

FDBDatabase.run() runs a function in a transaction and retries it on conflicts.

from fdb.subspace_impl import Subspace

db = frl.FDBDatabase()  # uses FDB_CLUSTER_FILE or the default cluster file
subspace = Subspace(("quickstart",))

async def save_people(ctx):
    store = frl.FDBRecordStore(ctx, subspace, metadata)
    await store.save_record(Person(id=1, name="Alice", age=30, city="Zurich"))
    await store.save_record(Person(id=2, name="Bob", age=25, city="Zurich"))

async def load_alice(ctx):
    store = frl.FDBRecordStore(ctx, subspace, metadata)
    stored = await store.load_record("Person", (1,))
    return stored.record.name

await db.run(save_people)
print(await db.run(load_alice))  # Alice

Scan an index

async def people_in_zurich(ctx):
    store = frl.FDBRecordStore(ctx, subspace, metadata)
    cursor = await store.scan_index("person_by_city_age", frl.IndexScanRange.prefix("Zurich"))
    return [stored.record.name async for stored in cursor]

IndexScanRange also has equals(...), between(low, high) and greater_than(...).

Query builder

from fdb_record_layer.query import Field, Query

async def older_than_28(ctx):
    store = frl.FDBRecordStore(ctx, subspace, metadata)
    query = Query.from_type("Person").where(Field("age").greater_than(28)).build()
    cursor = await store.execute_query(query)
    return [stored.record.name async for stored in cursor]

Use store.explain_query(query) to see which plan was chosen.

SQL (experimental)

from fdb_record_layer.relational import connect

sql = connect("demo")
sql.execute_sql("CREATE TABLE users (id BIGINT PRIMARY KEY, name STRING, age INT)")
sql.execute_sql("INSERT INTO users (id, name, age) VALUES (1, 'Alice', 30)")
for row in sql.query("SELECT name FROM users WHERE age > 25"):
    print(row["name"])

Without a record store, tables created this way live in memory and are not persisted.

Key expressions

Key expressions describe how to build primary and index keys from a record:

from fdb_record_layer.expressions import FanType, concat, field, nest, record_type

field("name")                                    # a single field
concat(field("last_name"), field("first_name"))  # composite key
nest("address", field("city"))                  # field of a nested message
field("tags", fan_type=FanType.FAN_OUT)          # one index entry per element of a repeated field
concat(record_type(), field("id"))               # prefix keys with the record type

Index types

Type Builder method Use case
VALUE add_index(type, name, expr) Equality, range and prefix scans
COUNT add_count_index(type, name, group_by) store.get_count(index, *group) without scanning
SUM add_sum_index(type, name, group_by) store.get_sum(index, *group) without scanning
RANK add_rank_index(type, name, score) Leaderboards: get_rank, get_by_rank
TEXT add_text_index(type, name, field) Full-text search with store.text_search(...)

Java interoperability

JavaCompatibleStore uses the same subspace layout, record splitting, versionstamp-based record versions and store header as the Java Record Layer, so both can work on the same data. See examples/README.md.

Operational utilities

from fdb_record_layer.utils import get_circuit_breaker, get_health_checker, init_lifecycle

breaker = get_circuit_breaker("fdb")
async with breaker:                  # opens after repeated failures
    await db.run(save_people)

checker = get_health_checker()
checker.register_check("cache", lambda: True)
report = await checker.check_health()
print(report.status.value)           # "healthy"

lifecycle = init_lifecycle()         # handles SIGTERM/SIGINT and runs shutdown hooks

More examples

The Java Record Layer documentation explains the underlying concepts.

Development

git clone https://github.com/mirkomikulic/fdb-record-layer-python
cd fdb-record-layer-python
pip install -e ".[dev,sql]"

pytest                                   # unit tests (no FoundationDB needed)
ruff check fdb_record_layer tests        # lint
ruff format fdb_record_layer tests       # format
mypy fdb_record_layer                    # type check

Local FoundationDB

scripts/setup_fdb.sh                     # FoundationDB 8.0.1 in Docker
FDB_VERSION=7.4.10 scripts/setup_fdb.sh  # or another version

python -m grpc_tools.protoc --python_out=tests/integration \
    --proto_path=tests/integration tests/integration/test_records.proto
FDB_CLUSTER_FILE=./fdb.cluster pytest tests/integration
FDB_CLUSTER_FILE=./fdb.cluster python examples/quickstart.py

The FoundationDB client library on your machine must have the same major.minor version as the server.

Contributing

Contributions are welcome. Please read CONTRIBUTING.md and the Code of Conduct. Report security issues as described in SECURITY.md. Changes are listed in the CHANGELOG.

License

Apache License 2.0. See LICENSE.

Acknowledgments

This project is a Python port of the FoundationDB Record Layer, originally developed by Apple.

Metadata

Release files for fdb-record-layer 0.1.0b8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fdb-record-layer 0.1.0b8
File Size Uploaded Provenance Actions
fdb_record_layer-0.1.0b8.tar.gz 198.3 kB With provenance Details for fdb_record_layer-0.1.0b8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fdb-record-layer 0.1.0b8
File Interpreter ABI Platform Actions
fdb_record_layer-0.1.0b8-py3-none-any.whl Python 3 none any Details for fdb_record_layer-0.1.0b8-py3-none-any.whl

Total release size: 402.5 kB

Release files / fdb_record_layer-0.1.0b8.tar.gz

Download URL fdb_record_layer-0.1.0b8.tar.gz
Size 198.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1b2a69e452601187ed78d97425cf227b40c6a3b77cd0a9c0f1b5a0f46ea0f832
BLAKE2b-256 checksum
How to use checksums
5fde85ff16cd2c233ef7f565461aca6909e7fcb139d55c482ab612bddf7679f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / fdb_record_layer-0.1.0b8-py3-none-any.whl

Download URL fdb_record_layer-0.1.0b8-py3-none-any.whl
Size 204.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bea7e9668221582ae7cee44f025358119a11168f867c19f45070a16aa558893
BLAKE2b-256 checksum
How to use checksums
765c14f5a5ffe885281f6d9f7f9abb288adf9d9cefc3edf41c875fdbf4b9f22e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for fdb-record-layer 0.1.0b8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fdb_record_layer-0.1.0b8.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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