Skip to main content

FerrumDB Python Bindings

PyPI PyPI Downloads Python Versions

FerrumDB is a zero-setup embedded document database for Python, powered by Rust.

  • Zero-setup — no server, no config, just open()
  • Rust-speed — AOF writes, in-memory index for O(1) reads
  • AES-256 Encrypted — optional encryption at rest
  • Native JSON — store any structured document
  • Secondary Indexing — query by JSON fields
  • TTL Support — keys auto-expire after a configurable duration
  • Built-in Dashboard — launch Ferrum Studio from your app

Installation

From PyPI (recommended)

pip install ferrumdb

From source (requires Rust toolchain + maturin)

pip install maturin
git clone https://github.com/MuhammadUsmanGM/FerrumDB.git
cd FerrumDB/ferrumdb-python
maturin develop --release

Quick Start

from ferrumdb import FerrumDB, Transaction

# Zero-setup: creates myapp.db if it doesn't exist
db = FerrumDB.open("myapp.db")

# Store any JSON-serializable value
db.set("user:1", {"name": "alice", "role": "admin", "score": 99})
db.set("user:2", {"name": "bob", "role": "user", "score": 45})

# TTL — auto-expires after 60 seconds
db.set_ex("session:abc", {"token": "xyz"}, 60)

# Read back (returns native Python dict!)
user = db.get("user:1")
print(user)  # {'name': 'alice', 'role': 'admin', 'score': 99}

print(db.count())  # 2
print(db.keys())   # ['user:1', 'user:2']

# Key existence check (O(1), no disk read)
if db.exists("user:1"):
    print("User exists!")

# Prefix scanning
user_keys = db.keys_with_prefix("user:")
print(user_keys)  # ['user:1', 'user:2']

# Database statistics
stats = db.stats()
print(f"Keys: {stats['key_count']}, Disk: {stats['disk_size_bytes']} bytes")

# Delete
db.delete("user:2")

Encryption

Open a database with AES-256-GCM encryption at rest:

db = FerrumDB.open("secure.db", encryption_key="my_super_secret_key_32_bytes_!!?")
db.set("secret", {"classified": True})

The key must be exactly 32 characters.

Secondary Indexing

Query by JSON field values in O(1) time:

db = FerrumDB.open("myapp.db")

db.set("user:1", {"name": "alice", "role": "admin"})
db.set("user:2", {"name": "bob", "role": "user"})
db.set("user:3", {"name": "charlie", "role": "admin"})

db.create_index("role")
admins = db.find("role", '"admin"')
print(admins)  # ["user:1", "user:3"]

Transactions

tx = Transaction()
tx.set("key1", {"value": 1})
tx.set_ex("cache:temp", {"data": 123}, 300)  # TTL in transactions too
tx.delete("old_key")
db.commit(tx)  # all-or-nothing

Ferrum Studio (Web Dashboard)

Launch the built-in web dashboard directly from your app:

db = FerrumDB.open("myapp.db")
db.start_studio(7474)  # http://localhost:7474

Browse keys, inspect values, set/delete entries, and view real-time metrics — no extra tools needed.

API Reference

Method Description
FerrumDB.open(path, encryption_key=None) Open/create database. Optional AES-256 encryption.
db.set(key, value) Store any JSON-serializable value
db.set_ex(key, value, ttl_seconds) Store with TTL (auto-expires)
db.get(key) Retrieve value (returns native Python dict/None)
db.delete(key) Delete a key (returns True if existed)
db.keys() List all keys
db.keys_with_prefix(prefix) List keys starting with prefix
db.count() Total number of entries
db.exists(key) Check if key exists (O(1), no disk read)
db.stats() Get database statistics (dict with key_count, disk_size_bytes, etc.)
db.create_index(field) Build secondary index on JSON field
db.find(field, value) Query by indexed field (value as JSON string)
db.commit(tx) Commit an atomic transaction
db.export_json() Export all key-value pairs as list of tuples
db.import_json(entries) Import key-value pairs from list of tuples
db.start_studio(port=7474) Launch Ferrum Studio dashboard

Transaction

Method Description
Transaction() Create a new transaction
tx.set(key, value) Stage a SET operation
tx.set_ex(key, value, ttl_seconds) Stage a SET with TTL
tx.delete(key) Stage a DELETE operation

Limitations

  • Entire index in RAM — Best for databases <1GB
  • Single-writer only — One process per database file
  • No range queries — Only exact value matches on indexed fields
  • No nested field indexes — Only top-level JSON fields supported

What's New in v0.2.0

  • Native Python dicts — get() now returns Python dicts instead of JSON strings
  • CRC32 checksums — Early corruption detection with clear error messages
  • Encrypted file caching — O(1) reads after first access (was O(n) on every read)
  • New API methods: exists(), stats(), keys_with_prefix(), export_json(), import_json()
  • Auto-compaction — Automatic dead data cleanup when threshold is exceeded

See GitHub for full documentation.

License

MIT — See LICENSE for details.

Metadata

Release files for ferrumdb 0.2.1

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

Built distributions (wheels)

Table of built distributions (wheels) for ferrumdb 0.2.1
File
ferrumdb-0.2.1-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details
ferrumdb-0.2.1-cp311-cp311-manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ x86-64 Details
ferrumdb-0.2.1-cp310-cp310-manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ x86-64 Details
ferrumdb-0.2.1-cp39-cp39-manylinux_2_34_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.34+ x86-64 Details
ferrumdb-0.2.1-cp38-cp38-manylinux_2_34_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.34+ x86-64 Details

Total release size: 6.2 MB

Release files / ferrumdb-0.2.1-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL ferrumdb-0.2.1-cp312-cp312-manylinux_2_34_x86_64.whl
Size 1.2 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
8f012a441e47e572ef6edd2b08a29e3915c3bfb51e67ed2306bab751b6d25b86
BLAKE2b-256 checksum
How to use checksums
37c30a93431e0a2af891ced7746b064407134f4d713c939a43c62aeaeda358ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / ferrumdb-0.2.1-cp311-cp311-manylinux_2_34_x86_64.whl

Download URL ferrumdb-0.2.1-cp311-cp311-manylinux_2_34_x86_64.whl
Size 1.2 MB
Tags CPython 3.11 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
965e3965835196c1930c7952c1e5a536173027ccd7c1108964a9aa44a79cd585
BLAKE2b-256 checksum
How to use checksums
2688f27cdd2df948713762df8e8ec5dc13e6c4d23c8f9d5040cec331a5753549
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / ferrumdb-0.2.1-cp310-cp310-manylinux_2_34_x86_64.whl

Download URL ferrumdb-0.2.1-cp310-cp310-manylinux_2_34_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
f23874e159a36cd670c2c80e787c1337d271b3e72e90eb61276c97377afdf13c
BLAKE2b-256 checksum
How to use checksums
b29ebbd72a55c1875b5decd05b75b80a04f86e0fbbe81938b1e863b3676c5028
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / ferrumdb-0.2.1-cp39-cp39-manylinux_2_34_x86_64.whl

Download URL ferrumdb-0.2.1-cp39-cp39-manylinux_2_34_x86_64.whl
Size 1.2 MB
Tags CPython 3.9 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
3802325b1da5ca1cf11022617eb9a871240ae26e3e8e9106ebf38dd9656c1f59
BLAKE2b-256 checksum
How to use checksums
b09fdcc3f1a9235cc83cef001247aaf57c2d3060187a08ee8fd810a5d86c541b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / ferrumdb-0.2.1-cp38-cp38-manylinux_2_34_x86_64.whl

Download URL ferrumdb-0.2.1-cp38-cp38-manylinux_2_34_x86_64.whl
Size 1.2 MB
Tags CPython 3.8 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
bc457895b006bf5169848f1c2856dc92d5020cd5db3770e0929c80bb5a391a45
BLAKE2b-256 checksum
How to use checksums
94a1b3afda0f177dc8c8c8ab650519f99fd82c0ce385ef98a8887aad292e1e59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

0.2.1 This release

5 release files

0.2.0

11 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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