Skip to main content

Reference implementation of the JSONLT (JSON Lines Table) specification for Python.

Project description

JSONLT Python package

CI Codecov CodSpeed Badge Python 3.10+ License: MIT

jsonlt is the Python reference implementation of the JSON Lines Table (JSONLT) specification.

JSONLT is a data format for storing keyed records in append-only files using JSON Lines. The format optimizes for version control diffs and human readability.

[!NOTE] This package is in development and not yet ready for production use.

Installation

pip install jsonlt-python

# Or

uv add jsonlt-python

Quick start

Basic operations

from jsonlt import Table

# Open or create a table with a simple key
table = Table("users.jsonlt", key="id")

# Insert or update records
table.put({"id": "alice", "role": "admin", "email": "alice@example.com"})
table.put({"id": "bob", "role": "user", "email": "bob@example.com"})

# Read a record by key
user = table.get("alice")
print(user)  # {"id": "alice", "role": "admin", "email": "alice@example.com"}

# Check if a key exists
if table.has("bob"):
    print("Bob exists")

# Delete a record
table.delete("bob")

# Get all records
for record in table.all():
    print(record)

Compound keys

JSONLT supports multi-field compound keys:

# Using a tuple of field names for compound keys
orders = Table("orders.jsonlt", key=("customer_id", "order_id"))

orders.put({"customer_id": "alice", "order_id": 1, "total": 99.99})
orders.put({"customer_id": "alice", "order_id": 2, "total": 149.99})

# Access with compound key
order = orders.get(("alice", 1))

Transactions

Use transactions for atomic updates with conflict detection:

from jsonlt import Table, ConflictError

table = Table("counters.jsonlt", key="name")

# Context manager commits on success, aborts on exception
with table.transaction() as tx:
    counter = tx.get("visits")
    if counter:
        tx.put({"name": "visits", "count": counter["count"] + 1})
    else:
        tx.put({"name": "visits", "count": 1})

# Handle conflicts from concurrent modifications
try:
    with table.transaction() as tx:
        tx.put({"name": "counter", "value": 42})
except ConflictError as e:
    print(f"Conflict on key: {e.key}")

Finding records

from jsonlt import Table

table = Table("products.jsonlt", key="sku")

# Find all records matching a predicate
expensive = table.find(lambda r: r.get("price", 0) > 100)

# Find with limit
top_3 = table.find(lambda r: r.get("in_stock", False), limit=3)

# Find the first matching record
first_match = table.find_one(lambda r: r.get("category") == "electronics")

Table maintenance

from jsonlt import Table

table = Table("data.jsonlt", key="id")

# Compact the table (removes tombstones and superseded records)
table.compact()

# Clear all records (keeps header if present)
table.clear()

API overview

Table class

The Table class is the primary interface for working with JSONLT files.

Method Description
Table(path, key) Open or create a table at the given path
get(key) Get a record by key, returns None if not found
has(key) Check if a key exists
put(record) Insert or update a record
delete(key) Delete a record, returns whether it existed
all() Get all records in key order
keys() Get all keys in key order
items() Get all (key, record) pairs in key order
count() Get the number of records
find(predicate, limit=None) Find records matching a predicate
find_one(predicate) Find the first matching record
transaction() Start a new transaction
compact() Compact the table file
clear() Remove all records
reload() Force reload from disk

The Table class also supports idiomatic Python operations:

  • len(table) - number of records
  • key in table - check if key exists
  • for record in table - iterate over records

Transaction class

The Transaction class provides snapshot isolation and buffered writes.

Method Description
get(key) Get a record from the transaction snapshot
has(key) Check if a key exists in the snapshot
put(record) Buffer a record for commit
delete(key) Buffer a deletion for commit
commit() Write buffered changes to disk
abort() Discard buffered changes

Exception hierarchy

All exceptions inherit from JSONLTError:

Exception Description
ParseError Invalid file format or content
InvalidKeyError Invalid or missing key
FileError File I/O error
LockError Cannot obtain file lock
LimitError Size limit exceeded
TransactionError Transaction state error
ConflictError Write-write conflict detected

Documentation

For detailed documentation, tutorials, and the full specification, visit jsonlt.org/docs.

License

MIT License. See LICENSE for details.

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

jsonlt_python-0.1.0a3.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

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

jsonlt_python-0.1.0a3-py3-none-any.whl (39.3 kB view details)

Uploaded Python 3

File details

Details for the file jsonlt_python-0.1.0a3.tar.gz.

File metadata

  • Download URL: jsonlt_python-0.1.0a3.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jsonlt_python-0.1.0a3.tar.gz
Algorithm Hash digest
SHA256 694528cc62d697149da0fcb304f4c61a0caccc7e2747913fba015b1a90a40442
MD5 30bfe660ac2d6ee5deaa68882b7f9914
BLAKE2b-256 767171c21bd308abdb8be2d75a5ae30099fce8356603c71958fa33ade852f1e0

See more details on using hashes here.

File details

Details for the file jsonlt_python-0.1.0a3-py3-none-any.whl.

File metadata

  • Download URL: jsonlt_python-0.1.0a3-py3-none-any.whl
  • Upload date:
  • Size: 39.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jsonlt_python-0.1.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 ef3524e7dcb4fc256b65293d94c81d8ef01491bb4b828f27ccf10a2d79f7483d
MD5 ba3c3aabd2e8ef605c054896c935a4cf
BLAKE2b-256 77dbea6c0f8493342024a73724f63db4bb403d3ba1e4ffee9ccc06673c280c8d

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