Skip to main content

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 terminal
    • logging=True: logs to timestamped file in baba_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 logging

    • None - log to terminal
    • True - log to file in baba_logs/
    • False - disable logging

Creates a database instance and internal engine and session.

BabaSession(engine, model)

  • engine: BabaEngine instance
  • model: Pydantic model class

Provides async context manager with methods:

  • add(model_instance): Add a new record
  • get_all(): Get all records as model instances
  • get_by_id(id_value): Get one record by id
  • update(id_value, new_model_instance): Update record by id
  • delete(id_value): Delete record by id
  • clear_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=True saves logs to baba_logs/YYYY-MM-DD_HH-MM-SS.log.

  • logging=False disables 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

babadb-1.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

babadb-1.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for babadb-1.1.1.tar.gz
Algorithm Hash digest
SHA256 5bf23021a6227c32bc273af867e99ecb354515b2cf4716e8500b4e85a1399509
MD5 2f3b5e492a3ba83bb0a90838b7cb8a80
BLAKE2b-256 a1de39094c5e52b3fe16f2800a8e0a3746192ab07f9530d8d7a4002253acd63b

See more details on using hashes here.

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

Hashes for babadb-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c422292ee0c662ca3f31b7f3d03c78f5f77f6f86245576bf130d6bccfa199c06
MD5 a9643083feb866cc11456f90312178c4
BLAKE2b-256 3af8b518b4cbb3b3d5443df08991aa26af2bb2047d416d11ccce4eb24a10bfa4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page