Skip to main content

Python library for JSONJS database loading

Project description

jsonjsdb

PyPI version Python CI codecov License: MIT

Python library for JSONJS databases with full CRUD support and relational queries.

Features

  • Read & Write: Full CRUD operations
  • Typed API: Optional TypedDict support with autocompletion
  • Relational queries: having.{table}(id) for one-to-many and many-to-many
  • Filtering: where() with operators (==, !=, >, in, is_null, etc.)
  • TypeScript compatible: Same file format as the TypeScript jsonjsdb library

Installation

pip install jsonjsdb

Quick Start

from jsonjsdb import Jsonjsdb

db = Jsonjsdb("path/to/db")

# Read
user = db["user"].get("user_1")
active = db["user"].where("status", "==", "active")

# Write
db["user"].add({"id": "u1", "name": "Alice", "tag_ids": []})
db["user"].update("u1", name="Alice Updated")
db.save()

Typed Access

from typing import TypedDict
from jsonjsdb import Jsonjsdb, Table

class User(TypedDict):
    id: str
    name: str
    tag_ids: list[str]

class MyDB(Jsonjsdb):
    user: Table[User]

db = MyDB("path/to/db")
user = db.user.get("user_1")  # Returns User | None (with autocompletion)

API Reference

CRUD

db.user.add({"id": "u1", "name": "Alice", ...})  # Add row (id required)
db.user.add_all([...])                           # Add multiple rows

db.user.get("u1")                                # → User | None
db.user.all()                                    # → list[User]

db.user.update("u1", name="New Name")            # Update fields
db.user.remove("u1")                             # → bool
db.user.remove_all(["u1", "u2"])                 # → int (count)

Filtering

db.user.where("status", "==", "active")          # Equality
db.user.where("age", ">", 18)                    # Comparison (>, >=, <, <=)
db.user.where("status", "in", ["a", "b"])        # In list
db.user.where("email", "is_null")                # Null check (is_not_null)

Relations

db.email.having.user("user_1")      # One-to-many: where user_id == "user_1"
db.user.having.tag("tag_1")         # Many-to-many: where tag_ids contains "tag_1"
db.folder.having.parent("folder_1") # Hierarchy: where parent_id == "folder_1"

Save / New Database

db.save()                # Save to original path
db.save("new/path")      # Save to new location

db = MyDB()              # Create empty in-memory DB
db.user.add({...})
db.save("path/to/db")    # Path required on first save

Runtime Fields

Exclude fields from persistence (in-memory only):

from jsonjsdb import Table

class UserTable(Table[User]):
    runtime_fields = {"_seen", "_processed"}

table = UserTable("user")
table.add({"id": "1", "name": "Alice", "_seen": True})

table.get("1")["_seen"]           # → True (in memory)
table.get_persistable_df()        # → DataFrame without _seen
# On save(), runtime_fields are automatically excluded

File Format

  • __table__.json — Index of tables with metadata
  • {table}.json — Data as array of objects
  • {table}.json.js — Same data for browser (JavaScript)

Column Conventions

Column Description
id Primary key (always string)
xxx_id Foreign key to table xxx
xxx_ids Many-to-many (comma-separated in file, list[str] in API)
parent_id Self-reference for hierarchies

License

MIT

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

jsonjsdb-0.2.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

jsonjsdb-0.2.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file jsonjsdb-0.2.0.tar.gz.

File metadata

  • Download URL: jsonjsdb-0.2.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jsonjsdb-0.2.0.tar.gz
Algorithm Hash digest
SHA256 76f21f33c8f199283f91773dd1a658f1bc8735d6bf07cea5f4762a5e54cd8bb9
MD5 057892ff8b98e4d6578bfce37786583d
BLAKE2b-256 9edcd64a32af36effe1ea4f05885f020d45c409d25a0d272312b9c3978b8da0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsonjsdb-0.2.0.tar.gz:

Publisher: release.yml on datannur/jsonjsdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jsonjsdb-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: jsonjsdb-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jsonjsdb-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0d377162c2a83f83995ac5b7840b27d870b87b08d6db44a29a022c67804c8bf
MD5 bb9edd51d2f2869ff798e03a017e9e5b
BLAKE2b-256 4efc82e720d41cfcb2cba3cfd934c386791814dfa23dbe9acb41cd60fe4d7092

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsonjsdb-0.2.0-py3-none-any.whl:

Publisher: release.yml on datannur/jsonjsdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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