TOON encoder/decoder and Truth Engine (temporal resolution, timezone conversion, RRULE expansion, availability merging) for AI calendar agents
Project description
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file temporal_cortex_toon-0.3.1.tar.gz.
File metadata
- Download URL: temporal_cortex_toon-0.3.1.tar.gz
- Upload date:
- Size: 90.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
477872de7a8530c82a3e67b43fd74f4198ccb5fade501070c8a5b1fb68880b2c
|
|
| MD5 |
f1462fda0289da83a9cd5f53938f4930
|
|
| BLAKE2b-256 |
e101134002b492cd340ec769f814a08354350ddcf2e0e668a6ae480bf1b43e08
|
File details
Details for the file temporal_cortex_toon-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: temporal_cortex_toon-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d387404ffdad776e1af04cfbe6c796a004b62698ba424fbbe51c9ef58d4db75
|
|
| MD5 |
ec81e2ca90bd5993abbe5a0dbc32fc66
|
|
| BLAKE2b-256 |
d287f27ff400c06562ed61d44b3d8b97a9a94d22d6f181cff229059ab4466bad
|