Tealdb
One consistent, function-style API for several databases, with sync and async versions. Python 3.10+. Backends are optional extras and are imported lazily.
| Backend | Engines | Extra |
|---|---|---|
sqltools |
SQLite, PostgreSQL, MySQL/MariaDB, DuckDB (via SQLAlchemy) | tealdb[sql] (+ postgres, mysql, duckdb) |
mango |
MongoDB | tealdb[mongo] |
tiny |
TinyDB (JSON file or memory) | tealdb[tiny] |
redis |
Redis | tealdb[redis] |
valkey |
Valkey | tealdb[valkey] |
pip install "tealdb[sql]" # pick the extras you need
Quick start
import tealdb
db = tealdb.connect("sqlite:///app.db") # backend chosen from the URL scheme
sql = tealdb.backend(db) # the backend module for this handle
sql.create(db, "users", {"id": "int", "name": "text", "age": "int"})
sql.add(db, "users", {"id": 1, "name": "Ann", "age": 30})
sql.find(db, "users", {"age": {"gte": 18}}, sort=["name"], limit=10)
sql.update(db, "users", {"name": "Ann"}, {"age": 31})
sql.delete(db, "users", {"name": "Ann"})
with sql.transaction(db) as tx: # a transaction is accepted wherever a db is
sql.add(tx, "users", {"id": 2, "name": "Bob", "age": 25})
tealdb.close(db)
You can also import a backend directly:
from tealdb import sqltools, mango, valkey, redis, tiny # sync
from tealdb.aio import sqltools, mango, valkey, redis, tiny # async, same names
Async works the same way, with await:
import tealdb.aio as aio
db = await aio.connect("sqlite+aiosqlite:///app.db")
sql = aio.backend(db)
async with sql.transaction(db) as tx:
await sql.add(tx, "users", {"id": 1, "name": "Ann", "age": 30})
await aio.close(db)
Connection URLs: sqlite:///file.db, postgresql://user:pw@host/db, mysql://...,
duckdb:///file.duckdb, mongodb://host/dbname, tiny:///file.json,
redis://host:6379/0, valkey://host:6379/0. You can also pass a ConnectionConfig, or call
connect() with no arguments to read TEALDB_URL (or TEALDB_SCHEME, TEALDB_HOST, ...).
Backend options go as keyword arguments, e.g. tealdb.connect("redis://...", prefix="app:").
Filters (shared by sqltools, mango and tiny)
{"age": 30} # equality
{"age": {"gte": 18, "lt": 65}} # eq ne gt gte lt lte in not_in exists regex contains icontains
{"or": [{"age": {"lt": 18}}, {"city": None}]} # or / and / not combine filters
{"name": {"in": ["Ann", "Bob"]}}
Rows are plain dicts. Results of writes are InsertResult / WriteResult.
Key/value backends (redis, valkey)
from tealdb import redis
db = redis.connect("redis://localhost:6379/0", prefix="app:")
redis.set(db, "user:1", {"name": "Ann"}, ttl=60) # values are JSON (never pickle)
redis.get(db, "user:1"); redis.incr(db, "visits")
redis.hset(db, "h", "field", 1); redis.list_push(db, "q", 1, 2); redis.set_add(db, "s", "a")
redis.delete_all(db, confirm=True) # only keys under your prefix
with redis.transaction(db) as tx: # queued, atomic; reads are refused inside
redis.set(tx, "a", 1)
Safety
- Errors never contain passwords, full URLs, SQL, values or driver text, and the original
driver exception is not reachable through
__context__. - Passwords are masked in
repr/logs (Secret). There are no plaintext password helpers. - Identifiers and field names are validated; values are always bound as parameters.
- Destructive operations (
delete_all, ...) requireconfirm=True. - Mongo
$where/$functionand server-side writes in aggregation are refused by default.
Engine notes
- MySQL/MariaDB DDL commits implicitly, so schema changes (
rename_table, ...) are refused inside a transaction. - On MariaDB,
jsoncolumns hold text (MariaDB stores JSON as LONGTEXT); passing a dict/list is refused. - MySQL
decimalcolumns default toDECIMAL(38,10)so fractions are kept.
Errors
TealError is the base class; also ConnectionFailed, NotFound, InvalidQuery,
UnsupportedOperation, ConstraintViolation.
Development
pip install -e ".[dev]"
ruff check src tests && mypy src/tealdb && pytest
Optional real-server tests: set TEALDB_TEST_POSTGRES_URL, TEALDB_TEST_MYSQL_URL,
TEALDB_TEST_MONGO_URL, TEALDB_TEST_REDIS_URL, TEALDB_TEST_VALKEY_URL
(database names must contain "test"; tests only touch what they create).
License
MIT
Metadata
Release files for tealdb 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tealdb-0.2.3.tar.gz | 267.4 kB | Without provenance | Details for tealdb-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tealdb-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for tealdb-0.2.3-py3-none-any.whl |
Total release size: 419.9 kB
Release files / tealdb-0.2.3.tar.gz
| Download URL | tealdb-0.2.3.tar.gz |
|---|---|
| Size | 267.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f22b795f15065745559537ff5a27d4e818dd291f6cea3c3f514b25a26a22e048
|
|
BLAKE2b-256 checksum How to use checksums |
e263fbff28d868afc932b70bfc121bf6698e3a135af78ec26fb47714bac2e4ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / tealdb-0.2.3-py3-none-any.whl
| Download URL | tealdb-0.2.3-py3-none-any.whl |
|---|---|
| Size | 152.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
412f5ad11eb57b93eef09683c852dabca419a62ec2f1326a45c457f19c5c516c
|
|
BLAKE2b-256 checksum How to use checksums |
8ef73039ec02ede43ea38adb6cff85a8779945a71d5aba26c5527e0f368122dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Security for tealdb 0.2.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.