This release is a pre-release and may not be stable for production use.
terrine
Terrine turns event tables and an explicit unit roster into analytical and ML datasets with point-in-time features and future outcomes. You declare what each row means, its time zero and source completeness; Terrine compiles the dataset and preserves the difference between observed zero and unknown.
The example below produces these value columns (anchor_id and t0 omitted here):
| unit | before | before__complete | before__reason | after | after__complete | after__reason |
|---|---|---|---|---|---|---|
| a | 1 | true | null | 2 | true | null |
| b | 0 | true | null | 0 | true | null |
Install
Requires CPython 3.13 or 3.14. Install the DuckDB backend and pandas for this example:
uv pip install 'terrine[duckdb,pandas]'
Use terrine[duckdb] for Arrow-only workflows, or add the polars extra for Polars.
Build a study dataset
Run this locally: the temporary DuckDB database contains two users, including b with no events. Nothing is uploaded.
from tempfile import TemporaryDirectory
import ibis
import terrine as tr
with TemporaryDirectory(prefix="terrine-first-") as directory:
con = ibis.duckdb.connect(f"{directory}/analytics.duckdb")
try:
con.raw_sql("CREATE TABLE users AS SELECT * FROM (VALUES ('a'), ('b')) t(user_id)")
con.raw_sql("CREATE TABLE events AS SELECT 'a' AS user_id, unnest([TIMESTAMP '2025-01-01 12:00:00', TIMESTAMP '2025-01-02 00:00:00', TIMESTAMP '2025-01-02 12:00:00']) AS occurred_at")
model = tr.Model.from_tables(
con, units={"user": tr.UnitSource("users", "user_id")},
events={"sessions": tr.Events("events", "occurred_at", {"user": "user_id"}, complete=("2025-01-01", "2025-01-03"))},
)
design = tr.recipes.time_series(
"user", every="1d", start="2025-01-02", end="2025-01-03",
features={"before": tr.agg("sessions_count", window=("-1d", "0s"))},
outcomes={"after": tr.agg("sessions_count", window=("0s", "1d"))},
)
data = design.build(model).to_pandas()
print(data.sort_values("unit").to_string(index=False))
finally:
con.disconnect()
Model → Design → Frame → Dataset: bind tables, describe rows, build lazily, then collect or optionally stage a pinned generation.
The event at midnight belongs to after, not before. The compact pandas view keeps each value's __complete / __reason columns; Arrow retains all observation metadata.
See your first dataset for budgets, refusals and staging.
Datasets you can build
Each tr.recipes constructor returns an ordinary, editable Design; the low-level API remains available.
| Dataset | What a row represents |
|---|---|
| Time series | A roster unit at each scheduled anchor. |
| Trial panels | An eligible unit at each trial time zero. |
| Event panels | A selected event and relative period. |
| Conditional events | An expression evaluated relative to a label-filtered event, not a separate constructor. |
| LTV / cohorts | A unit's cumulative value at an age since cohort entry. |
| Survival / life tables | A unit's elapsed event/censor duration, or a group's risk interval. |
| State panels | A unit-period transition from prior to response state. |
| Event sequences | An event anchor with a bounded, ordered sequence. |
Common feature patterns: rolling windows, active-before eligibility, attributes at t0, recency and true/false labels.
Five rules
- Choose t0. Every row has an explicit time zero: fixed, scheduled or event-based.
- Use half-open windows.
[start, end)includes the start, excludes the end; offsets are elapsed durations, not calendar dates. - Features before, outcomes after. Features and eligibility cannot look beyond the pre-t0 cutoff; outcomes describe follow-up.
- Declare completeness.
Model.from_tablesrequirescomplete=on everyEventsdescriptor; withModel.from_catalog, only sources selected by the Design needCoverage. Both declare complete local days, never inferred from the latest event. - Null is not zero. A complete empty count is zero; unavailable values stay null with
__reason. Unknown eligibility refuses export rather than silently dropping a row.
Supported warehouses
| Backend | Dataset execution | Staging / publication |
|---|---|---|
| DuckDB | Reference backend; local tables | Supported |
| PostgreSQL 16 | Direct Frame materialization | DuckDB only |
| BigQuery | Direct Frame materialization | DuckDB only |
| Snowflake | Direct Frame materialization | DuckDB only |
See backend compatibility for extras, consistent-read semantics, supported operations, precision and executable warehouse examples.
Guides
- All guides · Capabilities · Inherent limits · Refusal codes
- Training/scoring and saved dataset definitions · Library hand-offs (Terrine makes no causal estimates or identification claims)
- Durable runtime and saved plans · Owned inputs
- Restricted dataset tools · Airflow, Dagster and dbt
- Cost and data residency · Synthetic worlds with independent expected rows
Contributing? See CONTRIBUTING.md for setup, test tiers and the Contributor License Agreement.
License
Apache License 2.0; see NOTICE.
Metadata
Release files for terrine 0.1.0.dev0
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 |
|---|---|---|---|---|
| terrine-0.1.0.dev0.tar.gz | 1.5 MB | With provenance | Details for terrine-0.1.0.dev0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| terrine-0.1.0.dev0-py3-none-any.whl | Python 3 | none | any | Details for terrine-0.1.0.dev0-py3-none-any.whl |
Total release size: 1.9 MB
Release files / terrine-0.1.0.dev0.tar.gz
| Download URL | terrine-0.1.0.dev0.tar.gz |
|---|---|
| Size | 1.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ddb35b27554df7af06191ed1dca9299c158bb02aa01056ffaef9818b45c3320
|
|
BLAKE2b-256 checksum How to use checksums |
b89d0e0063000c334046bc40d229e618d9cb52d7d7bca51a32438c5e0661a9a5
|
| 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 27, 2026.
Transparency logRelease files / terrine-0.1.0.dev0-py3-none-any.whl
| Download URL | terrine-0.1.0.dev0-py3-none-any.whl |
|---|---|
| Size | 397.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
79f8fdcf861e65a09536a3d4b144d13436283bcf43fea7dc66174b1f6f2e1dc4
|
|
BLAKE2b-256 checksum How to use checksums |
fdea6eba449565a8d119279959c6cd9e6b8041d5e1b7e96b893ba8e6e3cf12d4
|
| 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 27, 2026.
Transparency logSecurity for terrine 0.1.0.dev0
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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for terrine-0.1.0.dev0.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 27, 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.