tiergraph
Ordered tiers, declared relations, and an algebra over them
tiergraph holds parallel ordered sequences and the declared links between them as one immutable graph, checked when it is built. Every view — selection, traversal, containment, timing, folds — is computed from that one graph.
The shape is the track view of an audio or video editor: rows of items, ordered within a row, aligned across rows, with links between rows. Aligned annotations over a signal have it; so do layered timelines and structured documents whose parts reference each other.
You have this problem already if:
- you can construct a state your own code treats as invalid;
- you keep a derived index beside the store and must remember to update both; or
- your serialized format breaks when you add a field.
The package requires Python 3.12 or later. Install it from PyPI:
python -m pip install tiergraph
For development, install an editable checkout with the development tools:
git clone https://github.com/lenzo-ka/tiergraph.git
cd tiergraph
python -m pip install -e ".[dev]"
See an alignment
This caption graph links each word to its phones. Select cat, walk the declared
alignment, and the answer is visible in the input:
from tiergraph import ItemSelector, Walk, WalkDirection, evaluate_selection
from tiergraph.build import document
builder = document("https://example.com/captions", prefix="caption")
words = builder.tier(
"words",
("a", "cat", "sat"),
item_type="word",
membership="word-membership",
)
phones = builder.tier(
"phones",
("AH", "K", "AE", "T", "S", "AE-2", "T-2"),
item_type="phone",
membership="phone-membership",
)
aligns = builder.link(
"aligns",
words,
phones,
((0, 0), (1, 1), (1, 2), (1, 3), (2, 4), (2, 5), (2, 6)),
acyclic=True,
)
graph = builder.build()
cat = evaluate_selection(graph, ItemSelector(words.ref(1)))
reached = Walk(cat, aligns.name, WalkDirection.FORWARD).evaluate().nodes
assert [node.reference for node in reached.nodes] == [
phones.ref(1),
phones.ref(2),
phones.ref(3),
]
The complete runnable example keeps the displayed phone labels separate from
their durable ids and prints ['K', 'AE', 'T']; see
examples/caption_alignment.py.
The model is informed by Sue Hertz's Delta representation and the Heterogeneous Relation Graphs (HRGs) of the Festival Speech Synthesis System. tiergraph's interchange format also owes something in spirit to Apple's QuickTime, a general time-based media format, where tracks of any media type share one timeline, each with its own timescale and related by references, and each track is typed by its media handler and sample description, so the container stays general while every resource brings its own schema. tiergraph keeps their emphasis on explicit tiered structure while defining a typed, immutable model and a versioned interchange format.
What you can do with it
Store aligned layers that stay valid. Tiers, items, typed attributes, and declared relations live in one immutable graph that refuses an invalid state when it is built. Build one with the tiergraph.build builder or the direct constructors, or read one from a Praat TextGrid. See construction and annotation formats.
Edit and reconcile it. Checked transactions report displacement; journals add preview, undo, redo, bounded history, and portable patches. Deterministic differences, subtree replacement and swaps, selected bulk edits, graph cleanup, path and timing reconciliation, and graph distance build on the same editing primitives. The command line exposes the primitive, replacement, bulk, cleanup, patch, diff, distance, and program operations. See editing.
Query it. Selectors with set algebra, typed value predicates, quantifiers over related items, offset-interval joins, and walks over declared relations return canonical node sets. See selection and traversal and predicates and offset joins.
Match sequences. Regular patterns of item tests run over a tier, over each container's children, or over an order the graph declares across tiers and boundaries, and over every path of a lattice. See sequence patterns.
Fold and parse. A fold evaluates a dependency relation under a semiring you choose: least cost, path counts, recognition, posteriors, or witnesses from the same graph. Synchronous grammars parse token input into a chart graph and fold over it. See folding and grammars.
Interchange. Canonical JSON with an explicit format version and a published schema, TextGrid in and out, and span views as JSON, JSON Lines, text, HTML, or DOT. See serialization and span views.
Attach external resources. Ordered, durably identified items describe typed payloads by digest, size, media type, and schema. Ordinary relations attach any number of resources to graph items or other resources, while strict bundles choose embedded or linked storage per payload. See external resources.
Store a versioned corpus. The explicitly imported tiergraph.tgdb module
keeps ordered collections of complete graphs, atomic multi-graph passes,
replay-checked history, content-addressed payloads, and bounded indexed queries
in one local store. See
corpus storage.
Queries that come from someone else can carry a work budget.
tiergraph is a library and a format rather than a database or an annotation
tool. It suits structure whose layers are declared in advance. A workload that
edits a graph many times should collect the edits in a GraphEditor and freeze
once, since every frozen Graph is validated when it is built.
What tiergraph is for compares it with
related tools and lists what it does not try to do.
Command line
The tiergraph command reads graph documents from files or stdin and runs the
same machinery as the Python API. For example:
$ tiergraph validate graph.json
$ tiergraph inspect graph.json
$ tiergraph select graph.json --where 'score>=0.5' --prefix ex
$ tiergraph match graph.json --pattern '{class=V} / {class=C} _' --prefix ex \
--ordering '{"order":"tier","tier":{"namespace":"urn:ex","local_name":"phones"}}' focus
$ tiergraph span render graph.json --profile span-profile.json --format textgrid
See the generated CLI reference for every command and its options.
Documentation
Start with getting started, which reads a TextGrid, queries it, and writes it back, then builds a graph and uses the command line. Concepts describes the data model, and the documentation map lists every guide by task. The API reference covers every top-level export and the documented secondary surfaces; the CLI reference is generated from the parser.
The companion tiergraph_dot package renders any Graph as deterministic
Graphviz DOT and ships in the same distribution. Continuing from the example
above, where graph was built:
import tiergraph_dot
dot = tiergraph_dot.dumps(graph)
Stability
The current development version and every published pre-1.0 release are alpha software. Before 1.0, a 0.X.0 release is in effect a major release and carries no compatibility guarantee for the public Python API: names may be removed or renamed in one, with no migration path. A consumer is expected to track the current version rather than pin an older one and wait. The JSON wire format, construction machine format, and span-view JSON format carry explicit version stamps so a reader can identify the format it receives. A format stamp identifies a contract; it does not imply that every version can read or migrate every older format.
After 1.0, the intended policy is to announce a deprecated public Python API in a minor release, retain it with a warning for at least one subsequent minor release, and remove it only in a later release. Security, correctness, or otherwise impractical compatibility constraints may require a faster change, which will be documented in the release. This is an intended post-1.0 policy, not a compatibility promise for the current alpha series.
Format versions
A tiergraph document declares the format version it was written in. A reader accepts documents of the version it implements and refuses any other, naming the version it found and the one it expected.
Documents are versioned interchange: they move data between tools that agree on a version. They are not an archival format, and reading a document written by a later release is not supported.
Within a release line the format only grows; the format notes describe the version policy and the canonical spelling.
License
BSD 2-Clause. The full text is in LICENSE.
Metadata
Release files for tiergraph 0.9.0
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 |
|---|---|---|---|---|
| tiergraph-0.9.0.tar.gz | 1.6 MB | With provenance | Details for tiergraph-0.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tiergraph-0.9.0-py3-none-any.whl | Python 3 | none | any | Details for tiergraph-0.9.0-py3-none-any.whl |
Total release size: 2.2 MB
Release files / tiergraph-0.9.0.tar.gz
| Download URL | tiergraph-0.9.0.tar.gz |
|---|---|
| Size | 1.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e49d8e2f928d5b961efab1b1d38acf291ed29a811dfbc6b7576f8936f66befd
|
|
BLAKE2b-256 checksum How to use checksums |
27366be9b7100882128dfa01b2f027cc877e92e1272f5792c71c771b1a565355
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 12, 2026.
Transparency logRelease files / tiergraph-0.9.0-py3-none-any.whl
| Download URL | tiergraph-0.9.0-py3-none-any.whl |
|---|---|
| Size | 592.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ed4a355dc4d608f08cddc39d8ad2c7a116dd2f449c42d01bfc346950aaca4b7
|
|
BLAKE2b-256 checksum How to use checksums |
d78ded82b9ca03b1907f10f04bf6812e8ef14d223fe2423355f2ffd5577a8cc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 12, 2026.
Transparency logSecurity for tiergraph 0.9.0
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 tiergraph-0.9.0.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 Oct 12, 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.