A sqlite3-compatible DB-API adapter for GNU recfiles
Project description
RecDB
A PEP 249-style Python DB-API adapter that supports recfile behind an python module style interface. This is intended as an alternative to SQLite where human-readable flat file databases is preferred.
Refer to this wikipedia article about recfiles and recutils
Why?
Recfiles are plain text — human-readable, diffable with git diff, editable
with any text editor, queryable with standard Unix tools. For small projects
where textual transparency matters more than performance, they're a compelling
alternative to binary database files.
recdb lets you use a simple SQL subset against recfiles while keeping a clean
migration path to SQLite when you outgrow them.
Installation
pip install sqlparse # only dependency beyond stdlib
apt install recutils # required for the recfile backend
Quickstart
from recdb import connect
# ── Recfile backend (text files, human-readable) ─────────────────────────────
conn = connect("recfile", "./data") # directory of .rec files
# ── SQLite backend (drop-in swap) ────────────────────────────────────────────
conn = connect("sqlite", "inventory.db")
# ── Identical API from here ──────────────────────────────────────────────────
conn.execute(
"INSERT INTO items (name, sku, stock, price) VALUES (?, ?, ?, ?)",
("Widget", "WGT-001", 50, 9.99)
)
conn.commit()
cur = conn.execute("SELECT * FROM items WHERE stock > 0")
for row in cur.fetchall():
print(row) # dict: {'name': 'Widget', 'sku': 'WGT-001', ...}
conn.close()
Context manager
with connect("recfile", "./data") as conn:
conn.execute("UPDATE items SET stock = 45 WHERE sku = 'WGT-001'")
# commit() called automatically on clean exit
Supported SQL
| Statement | Example |
|---|---|
SELECT |
SELECT * FROM items |
SELECT with projection |
SELECT name, stock FROM items |
SELECT with WHERE |
SELECT * FROM items WHERE stock < 10 |
INSERT |
INSERT INTO items (name, sku, stock) VALUES ('X', 'X-1', 5) |
UPDATE |
UPDATE items SET stock = 50 WHERE sku = 'WGT-001' |
DELETE |
DELETE FROM items WHERE stock = 0 |
| Parameter binding | cursor.execute("SELECT * FROM items WHERE sku = ?", ("WGT-001",)) |
WHERE clause
- Operators:
= != < > <= >= ANDbetween conditions is supportedOR, subqueries, and nesting are not supported in the recfile backend (AssertionError raised)
Unsupported (recfile backend raises AssertionError)
JOIN, GROUP BY, ORDER BY, LIMIT, UNION, HAVING, subqueries.
Recfile schema
Each table maps to a .rec file in your data directory. You can add type
hints and constraints using standard recutils directives:
%rec: items
%mandatory: name sku stock price
%type: stock int
%type: price real
name: Widget A
sku: WGT-001
stock: 120
price: 9.99
File layout
recdb/
├── src/recdb/
│ ├── __init__.py # connect() entry point
│ ├── base.py # BaseConnection / BaseCursor ABCs
│ ├── parser.py # SQL → AST translator (used by recfile backend)
│ ├── recfile.py # RecfileConnection / RecfileCursor
├── data/
│ └── items.rec # sample inventory data
└── inventory_demo.py # demo: runs both backends side by side
Running the demo
python inventory_demo.py # runs both backends
RECDB_BACKEND=recfile python inventory_demo.py
RECDB_BACKEND=sqlite python inventory_demo.py
Stability and 1.0 Release Criteria
RecDB is a hobby project and does not follow a fixed release schedule.
The 1.0 release will be considered when the project is successfully used in other projects over a period of time in a stable fashion. If this is useful for you, please note your project down in Known users / projects in this readme.
Until then, breaking changes may occur in minor versions.
Known users / projects
Send your PR to add your project here! This will help in tracking readiness for v1.0 release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file recdb-0.1.0.tar.gz.
File metadata
- Download URL: recdb-0.1.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2b2998a727c54ac2d7dfaf4b6d20f2b7baa4d78d37f7d0ad4f8f74fc44db24c
|
|
| MD5 |
fc68f0f1929d0f8c201a7cb75734caea
|
|
| BLAKE2b-256 |
4b287d972c6944c0cdbbd02947945e7eafbda0e69eb125ea91571915a0c23f4f
|
File details
Details for the file recdb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: recdb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1eb2ff7c7996cf629bea094a9de331a634ffde3346e2e14f139f8edd264b7015
|
|
| MD5 |
fb7b937637ebc71016b6829029913ca0
|
|
| BLAKE2b-256 |
cd2073a9da7a8c10ea6a0dbe1ef8afe5e8fd20cebd5bcb3c9d969b7cd4fc05aa
|