Encrypted Async File-Based Database for Pydantic Models
Project description
BabaDB
BabaDB — Encrypted Async File-Based Database for Pydantic Models
Overview
BabaDB is a lightweight asynchronous file-based database designed specifically for working with Pydantic models. It stores data as encrypted lines in a file, providing simple async methods to add, get, update, and delete your models.
Features
- Asynchronous API using
async/await - Works seamlessly with Pydantic models
- Line-based encrypted file storage
- Simple, minimalistic, easy to use
- Configurable logging:
logging=None: logs to terminallogging=True: logs to timestamped file inbaba_logs/logging=False: disables logging
Installation
pip install babadb
Or clone the repo and install manually.
Basic Usage
import asyncio
from pydantic import BaseModel
from baba import Baba, BabaSession
class Product(BaseModel):
id: int
name: str
price: float
async def main():
db = Baba('products.baba', logging=None) # Logging to terminal
async with BabaSession(db.engine, model=Product) as session:
await session.add(Product(id=1, name="Apple", price=0.99))
await session.add(Product(id=2, name="Banana", price=0.79))
products = await session.get_all()
for p in products:
print(p)
asyncio.run(main())
API Reference
Baba(filename: str, logging: Optional[bool] = None)
-
filename: database file name -
logging: controls loggingNone- log to terminalTrue- log to file inbaba_logs/False- disable logging
Creates a database instance and internal engine and session.
BabaSession(engine, model)
engine: BabaEngine instancemodel: Pydantic model class
Provides async context manager with methods:
add(model_instance): Add a new recordget_all(): Get all records as model instancesget_by_id(id_value): Get one record by idupdate(id_value, new_model_instance): Update record by iddelete(id_value): Delete record by idclear_cache(): Clear internal session cache
BabaEngine(filename: str, logging: Optional[bool])
Low-level engine with:
write(data: str)read_all() -> List[str]clear()
Handles encrypted storage and logging.
Logging
-
Default logs to terminal.
-
logging=Truesaves logs tobaba_logs/YYYY-MM-DD_HH-MM-SS.log. -
logging=Falsedisables all logs. -
Log format:
[BABA LOG] (info): message [BABA LOG] (error): message
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
License
MIT License © 2025 BabaDB Contributors
Project details
Release history Release notifications | RSS feed
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 babadb-1.1.1.tar.gz.
File metadata
- Download URL: babadb-1.1.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bf23021a6227c32bc273af867e99ecb354515b2cf4716e8500b4e85a1399509
|
|
| MD5 |
2f3b5e492a3ba83bb0a90838b7cb8a80
|
|
| BLAKE2b-256 |
a1de39094c5e52b3fe16f2800a8e0a3746192ab07f9530d8d7a4002253acd63b
|
File details
Details for the file babadb-1.1.1-py3-none-any.whl.
File metadata
- Download URL: babadb-1.1.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c422292ee0c662ca3f31b7f3d03c78f5f77f6f86245576bf130d6bccfa199c06
|
|
| MD5 |
a9643083feb866cc11456f90312178c4
|
|
| BLAKE2b-256 |
3af8b518b4cbb3b3d5443df08991aa26af2bb2047d416d11ccce4eb24a10bfa4
|