Terset for Python
Terset writes JSON records as compact, typed tables using format v2. Python 3.10 or newer. Zero runtime dependencies.
Install
Coming soon on PyPI. This package is not published yet.
pip install terset
Use
from terset import decode, encode, rules_for
data = [{"id": "1", "name": "Ada"}, {"id": "2", "name": "Ben"}]
text = encode(data)
print(text)
print(decode(text) == data)
Output (the gaps are tabs):
[2]
id name
1 Ada
2 Ben
True
encode(value) accepts a dictionary or list at the root. Values can be
strings, finite numbers, booleans, None, dictionaries with string keys,
and lists. It returns canonical Terset text. Put rules_for(text) before the data
when a reader needs the format explained. It validates canonical text and returns
the base rules, plus rules for keyed tables and dotted headers when present.
The exported RULES keeps all rules for any text. decode(text) returns the same
JSON value and rejects text the encoder would not produce.
Lists of at least two dictionaries become tables when the header and rows
save UTF-8 bytes. Named tables start with name[N]:. Root tables start
with [N] on its own line. Compact JSON lists have no count.
Missing fields, empty strings and None stay distinct.
A map in a direct root field can use name{N}: when the complete named
block is strictly shorter than name: JSON. Its first column is @key,
which holds each entry's key and is not a field. Root maps stay fields.
Uniform nested objects with identical ordered simple keys expand into
dotted headers, recursively. Literal dotted field names are quoted.
Other nested values stay compact JSON. The decoder rejects count mismatches
and accepts only the current canonical format.
See the full format v2 specification.
Python details
- The format uses JavaScript binary64 numbers.
1.0writes as1. Decoded integer literals within[-2**53, 2**53]become Pythonintvalues. Tokens with a fraction or exponent, and integers outside this range, becomefloatvalues. Python integers must be exactly representable as binary64 numbers; otherwise encoding raisesTypeError. This avoids silently rounding integers such as9007199254740993. - Numeric negative zero, infinities, NaN, cycles, non-JSON types and depth
above 500 raise
TypeError. Use plain built-in dictionaries and lists. - Dictionary order is preserved, with JavaScript's array-index keys first
in numeric order. For example,
"2"precedes"10";"01"keeps its insertion position among other keys. - Unicode stays unchanged, including normalization forms and lone surrogates. Explicit UTF-16 surrogate pairs become Python astral code points. Keys that become identical through this conversion are rejected.
- Format validation errors raise
ValueError, including non-finite numbers and excessive depth. Passing a non-string todecoderaisesTypeError.
encode uses the covariant JsonInputRoot and JsonInputValue aliases,
based on read-only Mapping and Sequence interfaces. This lets typed
lists and dictionaries pass without widening their element types. Runtime
validation still requires plain built-in lists and dictionaries.
decode returns concrete JsonRoot, JsonObject and JsonValue types.
The package includes py.typed.
Limits
The format rejects numeric negative zero and nesting deeper than 500.
With deep data and an already deep caller stack,
encode, decode and rules_for can raise RecursionError.
This depends on the available stack depth, not the Python version.
Local tests
From the repository root, without installing the package:
python3 -B -m unittest discover -s packages/terset-py/tests -v
Tests read the shared cases generated by the TypeScript encoder and check exact output, decoding, the rules string, and invalid inputs. To regenerate the cases from the repository root with Node 24:
node packages/terset/tests/generate-cases.ts
License
MIT. Copyright (c) 2026 TrueWear, LLC. The license text is included in LICENSE.
Metadata
Release files for terset 0.2.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 | Provenance | Actions |
|---|---|---|---|---|
| terset-0.2.1.tar.gz | 17.1 kB | With provenance | Details for terset-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| terset-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for terset-0.2.1-py3-none-any.whl |
Total release size: 28.0 kB
Release files / terset-0.2.1.tar.gz
| Download URL | terset-0.2.1.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ed0b622fddc960925b77ac7cc600188f368f47fe30b46d5313b5e5b70f6ee481
|
|
BLAKE2b-256 checksum How to use checksums |
21cfabe119518dade7595bbb1e3961f6bbe853aaa44edd205f5f653c9000ec04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logRelease files / terset-0.2.1-py3-none-any.whl
| Download URL | terset-0.2.1-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f898636259b00632b346475e6459f123ae06670417a2dcc15aec284ab3211d1
|
|
BLAKE2b-256 checksum How to use checksums |
855a67fc98c3195de1aca381a473cd81a963cf54fef07665a812ea1a7b13fb9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logSecurity for terset 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for terset-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.