temporal-cortex-toon (Python)
Python bindings for the TOON format encoder/decoder and truth-engine, built with PyO3 and maturin.
Installation
pip install temporal-cortex-toon
Usage
from temporal_cortex_toon import encode, decode, filter_and_encode, expand_rrule
# JSON → TOON
toon = encode('{"name":"Alice","scores":[95,87,92]}')
print(toon)
# name: Alice
# scores[3]: 95,87,92
# TOON → JSON (perfect roundtrip)
json_str = decode(toon)
print(json_str)
# {"name":"Alice","scores":[95,87,92]}
# Semantic filtering: strip noisy fields before encoding
toon = filter_and_encode(
'{"name":"Event","etag":"abc","kind":"calendar#event"}',
["etag", "kind"],
)
print(toon)
# name: Event
# RRULE expansion
import json
events_json = expand_rrule(
"FREQ=WEEKLY;BYDAY=TU,TH", # RFC 5545 RRULE
"2026-02-17T14:00:00", # start date (local time)
60, # duration in minutes
"America/Los_Angeles", # IANA timezone
"2026-06-30T23:59:59", # expand until (optional)
None, # max count (optional)
)
events = json.loads(events_json)
for e in events:
print(f"{e['start']} → {e['end']}")
API
encode(json: str) -> str
Converts a valid JSON string into TOON format. Raises ValueError if the input is not valid JSON.
decode(toon: str) -> str
Converts a TOON string back into compact JSON. Raises ValueError if the input is not valid TOON.
filter_and_encode(json: str, patterns: list[str]) -> str
Strips fields matching the given patterns from JSON, then encodes to TOON. Patterns support:
"etag"— strip the top-level field"items.etag"— strip nested field via dot-path"*.etag"— wildcard: strip field at any depth
expand_rrule(rrule, dtstart, duration_minutes, timezone, until=None, max_count=None) -> str
Expands an RFC 5545 RRULE into concrete event instances. Returns a JSON string containing an array of {"start": "...", "end": "..."} objects with UTC datetimes.
Build from Source
# From the crate directory:
cd crates/temporal-cortex-toon-python
# Create a virtualenv and install
python3 -m venv .venv
source .venv/bin/activate
pip install maturin pytest
# Build and install the native extension
maturin develop
# Run tests
pytest tests/ -v
Testing
26 pytest tests across 5 suites:
- 9 encode tests — simple objects, nested, arrays, empty, null, booleans, strings
- 3 decode tests — simple, nested, valid JSON output
- 3 roundtrip tests — simple, nested, type preservation
- 4 filter tests — field removal, empty patterns, wildcards, error handling
- 7 RRULE tests — daily count, start/end fields, until, max count, weekly, error handling
cd crates/temporal-cortex-toon-python
source .venv/bin/activate
pytest tests/ -v
Architecture
src/lib.rs ← PyO3 #[pyfunction] wrappers around temporal-cortex-toon and truth-engine
pyproject.toml ← maturin build configuration
tests/ ← pytest test suite
The Python module (temporal_cortex_toon) is a thin wrapper that:
- Accepts Python strings
- Calls the underlying Rust functions (temporal-cortex-toon encode/decode, truth-engine expand)
- Maps Rust errors to Python
ValueErrorexceptions
License
MIT OR Apache-2.0
Metadata
Release files for temporal-cortex-toon 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| temporal_cortex_toon-0.3.1.tar.gz | 90.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| temporal_cortex_toon-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.34+ x86-64 | Details |
Total release size: 1.3 MB
Release files / temporal_cortex_toon-0.3.1.tar.gz
| Download URL | temporal_cortex_toon-0.3.1.tar.gz |
|---|---|
| Size | 90.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
477872de7a8530c82a3e67b43fd74f4198ccb5fade501070c8a5b1fb68880b2c
|
|
BLAKE2b-256 checksum How to use checksums |
e101134002b492cd340ec769f814a08354350ddcf2e0e668a6ae480bf1b43e08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.4
|
Release files / temporal_cortex_toon-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | temporal_cortex_toon-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
8d387404ffdad776e1af04cfbe6c796a004b62698ba424fbbe51c9ef58d4db75
|
|
BLAKE2b-256 checksum How to use checksums |
d287f27ff400c06562ed61d44b3d8b97a9a94d22d6f181cff229059ab4466bad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.4
|