Skip to main content

Async JSONL-based database with ORM bindings to Python dataclasses

Project description

cavedb

PyPI - License PyPI - Types PyPI - Version PyPI - Python Version

An async JSONL-based database with ORM bindings to Python dataclasses.

Name is stylised all-lowercase.

Features

Define table models as dataclasses-subclasses of Entity to begin using ORM features.

from cavedb import Entity

# A user.jsonl table, will create user.jsonl file
@dataclass
class User(Entity):
    usename: str                           # Required field
    age: int | None = field(default=None)  # Nullable field

Start using threadsafe and fully async database Sessions to query and write data to storage.

from cavedb import Session

# Zero configuration required
async with Session() as session:
    user = await session.select(User).first()
    # -> User(_id=UUID(bf911f00-117e-4a66-8f62-e0429492d5b0), username='john', age=25)

Full typing support through Generics. You will never have to guess what is returned.

session.select(User)          # -> <SelectQuery>
session.select(User).first()  # -> <User | None>
session.select(User).stream() # -> <AsyncGenerator[User, None]>
session.select(User).all()    # -> <list[User]>
User.id                       # -> <EntityField>
User.id != None               # -> <FieldClause>

Stored data is in JSONL format files one-per-table and easily human-readable!

{"_id":"bf911f00-117e-4a66-8f62-e0429492d5b0","username":"john","age":25}
{"_id":"fc4d0ada-6ea0-423e-a096-973a3a2779ee","username":"julia","age":27}
{"_id":"b3f647bf-d15e-4891-b383-2951f099a9a3","username":"jacob","age":null}

Create queries with ease:

users = await session.select(User).where(
    User.name != "john",
    User.age != None,
).all()
# -> [User(_id=UUID(fc4d0ada-6ea0-423e-a096-973a3a2779ee), username='julia', age=27)]

Upsert objects through session:

async with Session() as session:
    user = User(name="jack", age=50)
    user.id # -> UUID(...) - Readonly, already managed for you

    # Use just as any other dataclass
    user.age -= 23

    # Register in session for upserting
    session.add(user)

    # Commit changes (autocommit is set on session close - if no exceptions occur)
    await session.commit()

    # Choose your own paradigm: Commit As You Go / Unit Of Work

Threadsafe and true async when working with persistant storage in files.

Limitations

  1. Required PK field id as UUID.
  2. Missing FK relations and JOIN/select in load operations

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

cavedb-1.0.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

cavedb-1.0.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file cavedb-1.0.2.tar.gz.

File metadata

  • Download URL: cavedb-1.0.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for cavedb-1.0.2.tar.gz
Algorithm Hash digest
SHA256 77d2857837abd659f0255f024870912e47fd3e260e8f1981bf6bc6b507cbd97c
MD5 9af5850c2e6e3436c44f6df9af0da607
BLAKE2b-256 82e6da1295246c340e443ea9751acc8567003259718c3f9a52d74b631f12843a

See more details on using hashes here.

File details

Details for the file cavedb-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: cavedb-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for cavedb-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 26dd811669178dea6dddc3e215a8daf7a6e7486f1e1633262f8e7c53e0fefcfb
MD5 147b270e1219f0850dd18c848a66f878
BLAKE2b-256 b35cb05b9bc5665c85f2cdf2fc5a7311b6a8375a3a980e1ba82e4ddb287f2fe8

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