API Reference
Core
tollkeeper.Tollkeeper
Entry point for the write-audit-publish pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
Backend
|
Storage backend (e.g. |
required |
Example::
Tollkeeper(CsvBackend(staging, publish)).table("sales").write(fn).audit([NullCheck("id")]).publish()
Source code in src/tollkeeper/core.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
tollkeeper.TollkeeperSession
A single write-audit-publish session for one table version.
Created by Tollkeeper.table(). Supports fluent chaining::
Tollkeeper(backend).table("sales").write(fn).audit([checks]).publish()
Source code in src/tollkeeper/core.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
publish()
Promote the staged version to production.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the session was already rolled back. |
RuntimeError
|
If |
Source code in src/tollkeeper/core.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
rollback()
Discard the staged version without publishing.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the session was already published. |
Source code in src/tollkeeper/core.py
170 171 172 173 174 175 176 177 178 179 180 181 | |
write(fn)
Execute the write function against the staged version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[str], None]
|
Callable that receives the version reference and writes data to it. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
Re-raises any exception from |
Source code in src/tollkeeper/core.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
tollkeeper.CheckReport
dataclass
Aggregated results from an audit pass.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
list[CheckResult]
|
List of individual |
Source code in src/tollkeeper/core.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
tollkeeper.AuditFailedError
Bases: Exception
Raised when a hard DQ audit (on_failure="stop") finds violations.
Source code in src/tollkeeper/core.py
31 32 33 34 35 36 37 38 39 | |
Backends
tollkeeper.backends.base.Backend
Bases: ABC
Abstract base for Tollkeeper storage backends.
A backend manages the lifecycle of a versioned table: creating an isolated staging area, promoting it to production, or rolling it back. Implement this to add support for a new storage layer (CSV files, Iceberg, Delta, etc.).
Source code in src/tollkeeper/backends/base.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
create_version(table)
abstractmethod
Create an isolated staging version and return a version reference.
The reference is backend-specific: a file path, branch name, snapshot ID, etc. The caller writes data to whatever the reference points at.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Logical table name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
str
|
An opaque version reference string passed to subsequent methods. |
Source code in src/tollkeeper/backends/base.py
14 15 16 17 18 19 20 21 22 23 24 25 26 | |
publish_version(table, version_ref)
abstractmethod
Promote the staged version to production.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Logical table name. |
required |
version_ref
|
str
|
Reference returned by |
required |
Source code in src/tollkeeper/backends/base.py
28 29 30 31 32 33 34 35 | |
rollback_version(table, version_ref)
abstractmethod
Discard a staged version without publishing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Logical table name. |
required |
version_ref
|
str
|
Reference returned by |
required |
Source code in src/tollkeeper/backends/base.py
37 38 39 40 41 42 43 44 | |
tollkeeper.backends.csv.CsvBackend
Bases: Backend
Tollkeeper backend for local CSV files.
Stages data as a temporary CSV in staging_dir, then copies to
publish_dir on publish or deletes on rollback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
staging_dir
|
Path
|
Directory for temporary staging files. |
required |
publish_dir
|
Path
|
Directory where final published CSVs land. |
required |
Example::
backend = CsvBackend(staging_dir=Path("/tmp/tollkeeper"), publish_dir=Path("/data/output"))
Tollkeeper(backend).table("sales").write(lambda ref: shutil.copy(src, ref)).audit([...]).publish()
Source code in src/tollkeeper/backends/csv.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
cleanup_staging(max_age_seconds=3600)
Remove Tollkeeper staging files older than max_age_seconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_age_seconds
|
float
|
Maximum age in seconds before a staging file is considered orphaned. |
3600
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of removed file paths. |
Source code in src/tollkeeper/backends/csv.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
tollkeeper.backends.iceberg.IcebergBackend
Bases: Backend
Tollkeeper backend for Apache Iceberg tables using branch-based isolation.
Creates a temporary branch for staging writes, then fast-forwards main
on publish or drops the branch on rollback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
Catalog
|
A PyIceberg |
required |
Example::
from pyiceberg.catalog.sql import SqlCatalog
catalog = SqlCatalog("default", warehouse="/tmp/warehouse", uri="sqlite:///catalog.db")
backend = IcebergBackend(catalog)
Tollkeeper(backend).table("db.sales").write(lambda ref: table.append(df, branch=ref)).audit([...]).publish()
Source code in src/tollkeeper/backends/iceberg.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
create_version(table)
Create a Tollkeeper branch on the Iceberg table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Fully qualified Iceberg table identifier (e.g. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Branch name (e.g. |
str
|
parameter when writing via PyIceberg. |
Source code in src/tollkeeper/backends/iceberg.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
publish_version(table, version_ref)
Fast-forward main to the branch snapshot, then remove the branch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Fully qualified Iceberg table identifier. |
required |
version_ref
|
str
|
Branch name returned by |
required |
Source code in src/tollkeeper/backends/iceberg.py
48 49 50 51 52 53 54 55 56 57 | |
rollback_version(table, version_ref)
Drop the Tollkeeper branch without publishing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Fully qualified Iceberg table identifier. |
required |
version_ref
|
str
|
Branch name returned by |
required |
Source code in src/tollkeeper/backends/iceberg.py
59 60 61 62 63 64 65 66 67 68 69 70 | |
Checks
tollkeeper.checks.base.BaseCheck
Bases: ABC
Abstract base for data quality checks.
Subclass this to create checks using any engine (Polars, Pandas, Presto, etc.).
The run method receives a version reference (e.g. a file path or table name)
and returns a CheckResult.
Source code in src/tollkeeper/checks/base.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
run(version_ref, *, conn=None)
abstractmethod
Execute the check against the given version reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version_ref
|
str
|
Backend-specific reference to the staged data. |
required |
conn
|
Any | None
|
Optional engine connection for remote check execution.
When |
None
|
Returns:
| Type | Description |
|---|---|
CheckResult
|
A |
Source code in src/tollkeeper/checks/base.py
35 36 37 38 39 40 41 42 43 44 45 46 | |
tollkeeper.checks.base.CheckResult
dataclass
Result of a single DQ check execution.
Attributes:
| Name | Type | Description |
|---|---|---|
check_name |
str
|
Name of the check that produced this result. |
passed |
bool
|
Whether the check passed. |
details |
str
|
Human-readable details (e.g. |
Source code in src/tollkeeper/checks/base.py
8 9 10 11 12 13 14 15 16 17 18 19 20 | |
tollkeeper.checks.polars.NullCheck
Bases: BaseCheck
Fails if the specified column contains any null values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Column name to check for nulls. |
required |
Source code in src/tollkeeper/checks/polars.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
tollkeeper.checks.polars.RowCountCheck
Bases: BaseCheck
Fails if the row count is below the minimum threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_rows
|
int
|
Minimum number of rows required to pass. |
required |
Source code in src/tollkeeper/checks/polars.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
tollkeeper.checks.polars.ExpressionCheck
Bases: BaseCheck
Fails if any row does not satisfy a Polars expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Check name (used in reports). |
required |
expr
|
Expr
|
A Polars expression that evaluates to boolean per row. |
required |
Example::
ExpressionCheck("positive_age", pl.col("age") > 0)
Source code in src/tollkeeper/checks/polars.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
tollkeeper.checks.polars.SqlCheck
Bases: BaseCheck
Fails if any row does not satisfy a SQL WHERE condition.
Uses Polars SQLContext to evaluate the condition. The staged data
is registered as a table named data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Check name (used in reports). |
required |
condition
|
str
|
SQL WHERE clause (e.g. |
required |
Example::
SqlCheck("valid_age", "age > 0 AND age < 150")
Source code in src/tollkeeper/checks/polars.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
tollkeeper.checks.polars.UniqueCheck
Bases: BaseCheck
Fails if any combination of the given columns has duplicate rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
list[str]
|
List of column names that should form a unique key. |
required |
Example::
UniqueCheck(["region", "date"])
Source code in src/tollkeeper/checks/polars.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
Signals
tollkeeper.signals.base.Signal
dataclass
A record indicating a table's data has been audited.
Source code in src/tollkeeper/signals/base.py
22 23 24 25 26 27 28 29 30 31 | |
tollkeeper.signals.base.SignalStore
Bases: ABC
Abstract base for signal stores that track audit completion.
Source code in src/tollkeeper/signals/base.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
check(table, execution_ctx=None)
abstractmethod
Return signal if it exists, else None.
Source code in src/tollkeeper/signals/base.py
48 49 50 | |
close()
Release underlying resources. Override in subclasses that hold connections.
Source code in src/tollkeeper/signals/base.py
96 97 | |
delete(table, execution_ctx=None)
abstractmethod
Delete signal and process downstream cascade/notify.
Source code in src/tollkeeper/signals/base.py
44 45 46 | |
delete_dq_results(table, execution_ctx=None)
abstractmethod
Delete all DQ results for a table/execution (before re-running checks).
Source code in src/tollkeeper/signals/base.py
77 78 79 | |
get_downstream(table, execution_ctx=None)
abstractmethod
Return (table, ctx, cascade_policy) for all downstream dependents.
Source code in src/tollkeeper/signals/base.py
92 93 94 | |
get_dq_results(table, execution_ctx=None)
abstractmethod
Return all DQ results for a table/execution.
Source code in src/tollkeeper/signals/base.py
73 74 75 | |
register_dep(upstream_table, downstream_table, cascade_policy='notify', upstream_ctx=None, downstream_ctx=None)
abstractmethod
Declare that downstream depends on upstream.
Source code in src/tollkeeper/signals/base.py
81 82 83 84 85 86 87 88 89 90 | |
wait(table, execution_ctx=None, *, timeout_s=300, poll_s=10)
Block until signal appears or timeout.
Source code in src/tollkeeper/signals/base.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
write(signal)
abstractmethod
UPSERT signal row. Creates or overwrites.
Source code in src/tollkeeper/signals/base.py
40 41 42 | |
write_dq_result(result)
abstractmethod
UPSERT a DQ check result.
Source code in src/tollkeeper/signals/base.py
69 70 71 | |
tollkeeper.signals.sqlite.SqliteSignalStore
Bases: SignalStore
Signal store backed by a SQLite database.
Source code in src/tollkeeper/signals/sqlite.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
tollkeeper.signals.dbapi.DbApiSignalStore
Bases: SignalStore
Signal store backed by any PEP 249 (DB-API 2.0) connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
Any
|
A DB-API 2.0 connection (psycopg2, mysql-connector, sqlite3, etc.). |
required |
paramstyle
|
str
|
Parameter marker style — "qmark" (?) or "format" (%s). Defaults to "qmark". |
'qmark'
|
Source code in src/tollkeeper/signals/dbapi.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |