Skip to main content

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

Metadata

Release files for cavedb 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cavedb 1.0.2
File Size Uploaded
cavedb-1.0.2.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cavedb 1.0.2
File Interpreter ABI Platform
cavedb-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / cavedb-1.0.2.tar.gz

Download URL cavedb-1.0.2.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
77d2857837abd659f0255f024870912e47fd3e260e8f1981bf6bc6b507cbd97c
BLAKE2b-256 checksum
How to use checksums
82e6da1295246c340e443ea9751acc8567003259718c3f9a52d74b631f12843a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release files / cavedb-1.0.2-py3-none-any.whl

Download URL cavedb-1.0.2-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
26dd811669178dea6dddc3e215a8daf7a6e7486f1e1633262f8e7c53e0fefcfb
BLAKE2b-256 checksum
How to use checksums
b35cb05b9bc5665c85f2cdf2fc5a7311b6a8375a3a980e1ba82e4ddb287f2fe8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page