Skip to main content

Async JSONL-based database with ORM bindings to Python dataclasses

Project description

cavedb

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.1.tar.gz (7.9 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.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cavedb-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a9421e436cbea28bf807758c2669bc22ae85fe0b15a1292d131d697d4844b2f7
MD5 d95a4172c636c5c9c1246f1252c73f19
BLAKE2b-256 d91aa7c4aa0b870e0160b71862c8253ea64d8d7bd92d96cc42adfe8599217035

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cavedb-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3360b9f112adc1d66e4ec6f610cef8dc2d15e9a08f2095d820368e5431c7839a
MD5 31b7ab709fcbc1411b06668fce645f9f
BLAKE2b-256 aa04db1fb20019e16e4dff76355c1bbab185658227daeadb7d2d8bd0e47acef2

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