continuo-python-runtime 0.11.0__py3-none-any.whl → 0.13.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. continuo_python_runtime/cli.py +108 -37
  2. continuo_python_runtime/content_check.py +73 -0
  3. continuo_python_runtime/contract/kinds.py +37 -21
  4. continuo_python_runtime/contract/loader.py +207 -389
  5. continuo_python_runtime/contract/model.py +13 -6
  6. continuo_python_runtime/contract/pack.py +299 -0
  7. continuo_python_runtime/contract/paths.py +34 -1
  8. continuo_python_runtime/contract/read_tables.py +85 -0
  9. continuo_python_runtime/errors.py +13 -1
  10. continuo_python_runtime/harness.py +21 -6
  11. continuo_python_runtime/hash_inputs.py +63 -0
  12. continuo_python_runtime/hashing.py +54 -72
  13. continuo_python_runtime/lint.py +194 -6
  14. continuo_python_runtime/packages.py +56 -0
  15. continuo_python_runtime/validation/preflight.py +410 -0
  16. continuo_python_runtime/validation/runner.py +20 -3
  17. continuo_python_runtime-0.13.0.dist-info/METADATA +600 -0
  18. continuo_python_runtime-0.13.0.dist-info/RECORD +36 -0
  19. continuo_python_runtime/contract/merge.py +0 -197
  20. continuo_python_runtime/contract/secret_ref.py +0 -31
  21. continuo_python_runtime-0.11.0.dist-info/METADATA +0 -411
  22. continuo_python_runtime-0.11.0.dist-info/RECORD +0 -32
  23. {continuo_python_runtime-0.11.0.dist-info → continuo_python_runtime-0.13.0.dist-info}/WHEEL +0 -0
  24. {continuo_python_runtime-0.11.0.dist-info → continuo_python_runtime-0.13.0.dist-info}/entry_points.txt +0 -0
  25. {continuo_python_runtime-0.11.0.dist-info → continuo_python_runtime-0.13.0.dist-info}/licenses/LICENSE +0 -0
  26. {continuo_python_runtime-0.11.0.dist-info → continuo_python_runtime-0.13.0.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,600 @@
1
+ Metadata-Version: 2.5
2
+ Name: continuo-python-runtime
3
+ Version: 0.13.0
4
+ Summary: Runtime harness, contract tooling, and CI lint for Continuo python nodes.
5
+ Author: Simone Carolini
6
+ Maintainer: Simone Carolini
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ License-File: NOTICE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Requires-Python: >=3.14
14
+ Requires-Dist: boto3==1.43.114
15
+ Requires-Dist: continuo-contracts==0.2.0
16
+ Requires-Dist: continuo-engine-contract==0.10.0
17
+ Requires-Dist: pyarrow==26.0.0
18
+ Requires-Dist: pyyaml==6.0.3
19
+ Requires-Dist: sqlglot==30.23.0
20
+ Description-Content-Type: text/markdown
21
+
22
+ # Continuo Python Runtime
23
+
24
+ [![CI](https://github.com/carolsimone/continuo-python-runtime/actions/workflows/ci.yml/badge.svg)](https://github.com/carolsimone/continuo-python-runtime/actions/workflows/ci.yml)
25
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
26
+ [![Release](https://img.shields.io/github/v/release/carolsimone/continuo-python-runtime?label=release)](https://github.com/carolsimone/continuo-python-runtime/releases)
27
+
28
+ Runtime harness, contract tooling, and CI lint for Continuo python nodes.
29
+ This repo is what domain data teams (marketing, finance, …) template from to
30
+ ship a python node into Continuo: write an ODCS contract and a `run(ctx)`
31
+ script, push to `main`, and CI does the rest — lint, validate, build and push
32
+ the image, pack the contracts, upload the bundle and register the release with
33
+ Continuo.
34
+
35
+ ## What this repo is
36
+
37
+ Five artifacts come out of this repository:
38
+
39
+ - **The `continuo-python-runtime` PyPI package** — the `continuo-runtime` CLI
40
+ (`validate` / `pack` / `hash` / `packages` / `lint` / `run` /
41
+ `validation-op`) and the harness library (`conform()`, `RunContext`, the
42
+ error taxonomy) that domain repos install.
43
+ - **The `continuo-engine-contract` PyPI package** — the `WarehouseAdapter`
44
+ port, the contract schema, the shared SQL/type/config guards, and the
45
+ sentinel result-block format. Adapter authors outside this repo pin it.
46
+ - **The three engine-adapter PyPI packages** (`continuo-postgres-adapter`,
47
+ `continuo-trino-adapter`, `continuo-duckdb-adapter`) — one `WarehouseAdapter` implementation per
48
+ warehouse engine, each published independently under the same tag. A
49
+ domain repo normally never installs these directly (the engine image
50
+ already has the matching one baked in); they exist as standalone PyPI
51
+ packages for the "build your own container" shape (see below) and for
52
+ third-party adapter authors to reference.
53
+ - **Per-engine base images**, one per warehouse engine
54
+ (`continuo-python-runtime-postgres`, `continuo-python-runtime-trino`,
55
+ `continuo-python-runtime-duckdb`), that
56
+ domain repos build `FROM`. Each image bakes in the runtime and a single
57
+ `WarehouseAdapter` for that engine, and serves both roles that adapter has:
58
+ the node harness (`ENTRYPOINT ["continuo-runtime"]`, `CMD ["run"]`) and the
59
+ validation runner (`continuo-runtime validation-op`).
60
+ - **`template/`** — a copy-ready domain repo: `Dockerfile`, `contracts/`,
61
+ `scripts/`, and the `release.yml` CI/CD workflow.
62
+
63
+ One `vX.Y.Z` git tag releases all of it: `publish-pypi.yml` builds all five
64
+ PyPI distributions into a single `dist/`, verifies them (and full engine
65
+ images built from them) on amd64 and arm64, and only then publishes them
66
+ together. It then builds all three engine images natively per architecture —
67
+ each installing its matching pinned adapter version from that same release —
68
+ pulls and smoke-tests the exact pushed digests, and finally gives the verified
69
+ amd64 + arm64 digests one multi-arch tag. See `CONTRIBUTING.md` (Releasing).
70
+
71
+ ### What this repo owns
72
+
73
+ This repository owns the entire python-node surface: the engine contract, the three
74
+ engine adapters, the validation runner, and the node harness. There is no
75
+ separate validation-side port, adapter class, entry-point group or image: one
76
+ `WarehouseAdapter` per engine serves both the data plane (`fetch` /
77
+ `ensure_table` / `load`, plus the opt-in `table_columns` / `append` / `upsert`
78
+ capabilities) and validation (`ensure_schema` / `drop_schema` /
79
+ `build_empty_from_sql` / `build_empty_from_columns` / `clone_empty_from_prod` /
80
+ `check_binds`), and one image per engine runs both roles.
81
+
82
+ | Package (distribution name) | Module | Lives in | Role |
83
+ | --- | --- | --- | --- |
84
+ | `continuo-python-runtime` | `continuo_python_runtime` | this repo (root) | Harness (CLI, `conform()`, `RunContext`, error taxonomy) **and** the validation runner (`continuo-runtime validation-op`). Published to PyPI. |
85
+ | `continuo-engine-contract` | `continuo_engine_contract` | this repo, `contract/` | The `WarehouseAdapter` port, contract schema, the SQL/type/config guards adapters must run, and the result-block format. Published to PyPI. |
86
+ | `continuo-postgres-adapter` | `continuo_postgres_adapter` | this repo, `adapters/postgres/` | `PostgresAdapter` — one class, both roles. Published to PyPI. |
87
+ | `continuo-trino-adapter` | `continuo_trino_adapter` | this repo, `adapters/trino/` | `TrinoAdapter` — one class, both roles, for Trino/Iceberg. Published to PyPI. |
88
+ | `continuo-duckdb-adapter` | `continuo_duckdb_adapter` | this repo, `adapters/duckdb/` | `DuckDBAdapter` — one class, both roles, for DuckDB on a DuckLake (Postgres catalog, Parquet on S3). Published to PyPI. |
89
+
90
+ All five are uv workspace members (`[tool.uv.workspace]` in the root
91
+ `pyproject.toml`), so `uv sync --all-packages --all-groups` at the repo root
92
+ installs everything for local development.
93
+
94
+ **All five packages in the table above are published to PyPI**, under the
95
+ same `vX.Y.Z` tag. The three engine images then **install the matching pinned
96
+ adapter version from PyPI** — `Dockerfile.postgres` installs
97
+ `continuo-postgres-adapter==X.Y.Z`, `Dockerfile.trino` installs
98
+ `continuo-trino-adapter==X.Y.Z` and `Dockerfile.duckdb` installs
99
+ `continuo-duckdb-adapter==X.Y.Z` — rather than building it from this repo's
100
+ source tree, so each image still ships exactly one adapter and the runtime
101
+ still discovers it through the `continuo_engine.adapters` entry-point group
102
+ at run time. The image **name** (`continuo-python-runtime-<engine>`) and the
103
+ adapter's pip **distribution** name (`continuo-<engine>-adapter`) are two
104
+ different artifacts of the same adapter — same engine, same version, same
105
+ runtime behavior, different packaging; see "Build your own container" below
106
+ for a build shape that installs the pip package directly instead of `FROM`
107
+ the image. All five packages are still built, type-checked, and tested by CI
108
+ on every change.
109
+
110
+ ### The result block is a frozen wire contract
111
+
112
+ `continuo_engine_contract.result` writes a sentinel-framed JSON block as the
113
+ last line of stdout, and Continuo's Go side parses it byte-for-byte
114
+ (`pkg/validationresult` in the `continuo` repository). That wire format — the
115
+ sentinel markers, the framing, and the field names inside the block — is
116
+ **frozen**. The additions are an optional `reason` key, written after
117
+ `unique_id` only when an outcome has a machine-readable code (for example
118
+ `image_contract_mismatch`), and the op's own keys that the `seed_preflight` and
119
+ `probe_views` ops write after `reason`; a block without either keeps its bytes,
120
+ and the sentinels, `schema_version` and the five standard keys do not change. Reuse
121
+ it; never change it from this side alone. A change here that
122
+ the Go parser has not been taught is a production outage, not a refactor.
123
+
124
+ ## Quickstart for domain teams
125
+
126
+ 1. Copy `template/` into a new repository.
127
+ 2. Edit `template/.github/workflows/release.yml` and set `SERVICE` to your
128
+ service name (one service name per domain repo).
129
+ 3. Configure repository variables in GitHub (Settings → Secrets and
130
+ variables → Actions): `REGISTRY` (your Docker registry), `BUCKET` (your
131
+ S3 bucket for the contract bundle), `RELEASE_ENDPOINT` (the base
132
+ URL of your continuo install, `scheme://host[:port]` with no path, the origin of continuo's
133
+ `auth.publicUrl`). The
134
+ workflow calls `<RELEASE_ENDPOINT>/api/v1/releases` with its GitHub Actions
135
+ OIDC token, so the repository must be bound to your service in continuo's
136
+ `ciAuth.bindings` (see [Releasing from CI](https://github.com/carolsimone/continuo/blob/main/deploy/README.md#releasing-from-ci-github-actions)),
137
+ and an operator bootstraps the service's first release.
138
+ 4. Configure repository secrets: `AWS_ACCESS_KEY_ID` and
139
+ `AWS_SECRET_ACCESS_KEY` for the S3 upload. The template workflow pushes
140
+ the built image to GHCR using the workflow's own `GITHUB_TOKEN` (granted
141
+ `packages: write`) — no registry secret is needed for that. If you point
142
+ `REGISTRY` at a different or private registry, add your own `docker
143
+ login` step to `release.yml`.
144
+ 5. Write one ODCS contract per node under `contracts/`, named
145
+ `<table>.odcs.yaml` (see `template/contracts/example.odcs.yaml` and
146
+ "Contract files" below), and a script under `scripts/` that implements
147
+ `run(ctx)` (see `template/scripts/example.py`). A node that only needs to
148
+ land a csv file needs no script at all — see
149
+ `template/contracts/example_csv.odcs.yaml` and "Node kinds" below.
150
+ 6. Push to `main`. The `release.yml` workflow lints the scripts, validates
151
+ the contracts, builds and pushes the image, packs the contracts into
152
+ `odcs-bundle.json`, uploads it to S3, and POSTs the release with
153
+ `"kind": "python-odcs"`.
154
+
155
+ ## Contract files
156
+
157
+ Each node has one contract: an ODCS v3.2.0 data contract in `contracts/`,
158
+ named after its table, `<table>.odcs.yaml`, or `<schema>.<table>.odcs.yaml`
159
+ when two nodes of one service share a table name. The `continuo-contracts`
160
+ library reads each file strictly (YAML 1.2 core, with no aliases, no duplicate
161
+ keys and one document per file) and checks it. `validate`, `pack`, `hash` and
162
+ the harness load the folder the same way; the harness skips the read-query
163
+ checks.
164
+
165
+ ```yaml
166
+ apiVersion: v3.2.0
167
+ kind: DataContract
168
+ id: analytics.example # <schema>.<table>, in lower case
169
+ name: example # the table
170
+ version: "0" # continuo numbers published versions itself; this value is ignored
171
+ description:
172
+ purpose: Replace with your node
173
+ team:
174
+ name: your-team # the team that owns the node
175
+ customProperties:
176
+ - {vendor: continuo, property: schedule, value: daily}
177
+ - {vendor: continuo, property: criticality, value: SECONDARY}
178
+ - {vendor: continuo, property: script, value: scripts/example.py}
179
+ - vendor: continuo
180
+ property: readQueries
181
+ value:
182
+ orders: select order_id, customer_id, amount from analytics.upstream_orders
183
+ customers: select customer_id, name from analytics.upstream_customers
184
+ schema:
185
+ - name: example
186
+ physicalType: table
187
+ properties:
188
+ - {name: order_id, physicalType: INTEGER, required: true}
189
+ - {name: customer_name, physicalType: "VARCHAR(64)"}
190
+ - {name: amount, physicalType: "NUMERIC(10,2)", required: true}
191
+ ```
192
+
193
+ - `id` is `<schema>.<table>` in lower case; `name` and the schema object's
194
+ `name` are the table.
195
+ - `team.name` is the node's owner and `description.purpose` its description.
196
+ - continuo's own settings are `customProperties` items with
197
+ `vendor: continuo`. Every node sets `schedule` and `criticality`
198
+ (`REGULATORY`, `CORE` or `SECONDARY`); the node's kind decides the rest
199
+ (see "Node kinds" below). An optional `service` names the node's service,
200
+ and `pack` refuses a contract whose `service` is not its `--service`.
201
+ - The contract has exactly one schema object, `physicalType: table`. Its
202
+ `properties` are the table's columns, in order: each has a `name`, a
203
+ `physicalType` (`BIGINT`, `INTEGER` or `INT`, `DOUBLE PRECISION`,
204
+ `NUMERIC(p,s)` or `DECIMAL(p,s)`, `VARCHAR(n)`, `CHAR(n)`, `TEXT`,
205
+ `TIMESTAMP`, `DATE` or `BOOLEAN`) and, for a column that never holds NULL,
206
+ `required: true`.
207
+
208
+ `validate` refuses any other file in `contracts/` whose name ends in `.yml` or
209
+ `.yaml`, in any case, two files that declare the same table, and a folder with
210
+ no contract. `docs/boundary-contract.md` lists every field a contract may
211
+ carry, and how a contract in another format converts to ODCS.
212
+
213
+ ### Read queries
214
+
215
+ `validate`, `pack` and `hash` hand every read query to a real SQL parser
216
+ (sqlglot, through `continuo_engine_contract.sql.ensure_single_read`). Each
217
+ query must be one `SELECT` (or `WITH`) statement, and every table it reads
218
+ must name its schema: `analytics.orders`, never `orders`. The one name that
219
+ goes without a schema is a reference to a CTE that is in scope where the name
220
+ is used, so in `WITH orders AS (SELECT * FROM orders) SELECT * FROM orders` the
221
+ `orders` inside the CTE is a table and must name its schema. continuo refuses,
222
+ when it resolves a release, a read query that names a table without its schema,
223
+ so CI refuses at least what the release refuses.
224
+
225
+ SQL a driver accepts but a parser refuses fails these checks, most often a
226
+ driver's bind placeholder such as psycopg2's `%(name)s`, which `ctx.read(name)`
227
+ could never fill. Engine-specific syntax (postgres `~`, `@>`, …) needs
228
+ `--dialect <engine>`, which a repo should pass anyway, since Continuo parses
229
+ and bind-checks every read in the install's own warehouse dialect:
230
+
231
+ ```bash
232
+ continuo-runtime validate contracts/ --dialect postgres # or trino, duckdb
233
+ ```
234
+
235
+ The harness does not run these read checks again when a node starts, so a
236
+ read that passes here is not judged again under a different grammar in
237
+ production. See `docs/boundary-contract.md` §13.1.
238
+
239
+ ## Node kinds
240
+
241
+ The `kind` property (a `customProperties` item, not the contract's root
242
+ `kind: DataContract`) selects how the node produces its rows.
243
+ Every rule below (`extraColumns`, the columns, "Conform rules") applies to
244
+ every kind identically — `kind` only changes how the pre-conform table is
245
+ produced, never how it is checked or written.
246
+
247
+ - **`python-node`** (the default; the property may be left out) — a script
248
+ node. It needs `script` and `readQueries`, a mapping of one or more named
249
+ SQL queries, as described in "The script API" below.
250
+ - **`python-csv`** — a contract-only node: it has no script and reads no
251
+ table. Its `csvSource` is the file's address, `s3://bucket/key` or an
252
+ `https://` url (`http://` is refused by `validate`, not at run time).
253
+ The harness fetches the file, parses it with RFC 4180 defaults, and feeds
254
+ the result straight into `conform()` — the declared column types decide
255
+ the warehouse schema, not whatever pyarrow infers from the csv. Because
256
+ there is no script, `script`, `readQueries`, `secretRef` and `assets` are
257
+ refused on this kind. The csv's header row must contain every declared
258
+ column (checked again, independently, at release time before promotion);
259
+ columns present in the header but not declared are governed by the same
260
+ `extraColumns` policy as a script node's output — `raise` (default) fails
261
+ the run, `warn` drops them and logs a warning. See
262
+ `template/contracts/example_csv.odcs.yaml`.
263
+ - **`python-api`** — a script node that fetches its own data (typically over
264
+ HTTP) and declares no `readQueries`. `ctx.read` has nothing to return. It
265
+ may name one Kubernetes Secret with `secretRef: continuo-api-<name>`;
266
+ continuo attaches that Secret to the node's pod, so each of its keys is an
267
+ env var the script reads with `os.environ[...]`. The contract never holds a
268
+ secret value or env var name; the Secret itself is created in the cluster
269
+ by the operator.
270
+
271
+ ### Files a script reads (`assets`)
272
+
273
+ A `python-node` or `python-api` script that reads a file from the repository
274
+ (a model, a lookup table, a JSON config) lists it in the `assets` property,
275
+ one path relative to the repository root per entry, written with forward
276
+ slashes and with no empty, `.` or `..` part:
277
+
278
+ ```yaml
279
+ customProperties:
280
+ - {vendor: continuo, property: script, value: scripts/scored_orders.py}
281
+ - vendor: continuo
282
+ property: assets
283
+ value: [data/rates.json, models/scorer.bin]
284
+ ```
285
+
286
+ `pack` reads each listed file and folds its bytes into `shared_code_hash`
287
+ under its path, so editing one changes the node's `content_hash` and starts a
288
+ validation. A path that is also an import of the script is one unit. `pack`
289
+ and `hash` fail with a `ContractError` for a path that is missing, is not a
290
+ file or resolves outside the repository, and `validate` refuses a path listed
291
+ twice. The image must `COPY` the files, because `assets` only tells the hash
292
+ about them. A `python-csv` node has no script, so `assets` is refused on it.
293
+
294
+ ### Task timeout
295
+
296
+ Any node may set `timeoutMinutes` — an integer from 1 to 10,080 (one week) —
297
+ to declare how long its task may run before continuo gives up on it. A value
298
+ outside that range, or one that is not an integer, fails `validate`, `pack`
299
+ and `hash`. Like the owner (`team.name`), `schedule`, `criticality` and the
300
+ description, it is outside the code projection that `config_hash` hashes, so
301
+ changing it never changes the node's `content_hash`.
302
+
303
+ ## Write modes
304
+
305
+ The `modeType` property chooses how the harness writes a node's table on each
306
+ run:
307
+
308
+ | `modeType` | Each run | Rows from earlier runs |
309
+ | --- | --- | --- |
310
+ | `replace` (default) | empties the table, inserts this run's rows | gone |
311
+ | `append` | inserts this run's rows | kept |
312
+ | `upsert` | inserts rows with a new key, overwrites rows whose key exists | kept unless overwritten; never deleted |
313
+
314
+ ```yaml
315
+ customProperties:
316
+ - {vendor: continuo, property: kind, value: python-api}
317
+ - {vendor: continuo, property: modeType, value: upsert}
318
+ schema:
319
+ - name: fx_rates
320
+ physicalType: table
321
+ properties:
322
+ - {name: rate_date, physicalType: DATE, required: true, primaryKey: true, primaryKeyPosition: 1}
323
+ - {name: base, physicalType: "VARCHAR(3)", required: true, primaryKey: true, primaryKeyPosition: 2}
324
+ - {name: quote, physicalType: "VARCHAR(3)", required: true, primaryKey: true, primaryKeyPosition: 3}
325
+ - {name: rate, physicalType: "DECIMAL(12,6)"}
326
+ ```
327
+
328
+ - `python-csv` nodes only `replace`.
329
+ - An `upsert` node needs a key: `primaryKey: true` on each key column. Each
330
+ key column is `required: true` (a NULL key never matches) and is not
331
+ `DOUBLE PRECISION`; a key of several columns numbers its columns with
332
+ `primaryKeyPosition`, from 1. The key's names are unique
333
+ case-insensitively. On a `replace` or `append` node a key only describes
334
+ the table: the harness writes no key and the hash leaves it out. A
335
+ Postgres `replace` table that wants uniqueness uses `indexes` with
336
+ `unique: true` in its `config` property.
337
+ - Every write is atomic: all of the run's rows or none. An `append` or
338
+ `upsert` run with zero rows writes nothing (a `replace` run with zero rows
339
+ still empties the table).
340
+ - `append` is a plain insert: a run that committed but was reported failed
341
+ and is retried stores its rows twice. `upsert` is idempotent.
342
+ - An `upsert` run whose own rows repeat a key fails with `ConformError` and
343
+ writes nothing.
344
+ - Before an `append` or `upsert` the harness compares the live table with
345
+ the contract's columns — names case-insensitively, nullability exactly; order and
346
+ types are not compared — and fails with `LoadError` naming every missing
347
+ column, unexpected column and nullability mismatch. Changing an `append` or
348
+ `upsert` table (columns, types, nullability, key or mode) needs a new table
349
+ name (`_v2`) under a new contract; continuo rejects the release otherwise.
350
+ Adding a nullable column is no exception: the existing rows cannot be
351
+ backfilled.
352
+ - The installed engine must support the mode; all three shipped adapters do.
353
+ A bring-your-own adapter declares `AppendCapable` / `UpsertCapable` from
354
+ `continuo-engine-contract` (and can run its conformance suite); without them
355
+ an `append`/`upsert` node fails with `LoadError: <Adapter> does not support
356
+ <mode>` before its script runs.
357
+ - Engines: on Postgres the key is the table's `PRIMARY KEY`, created with the
358
+ table; DuckLake and Trino/Iceberg have no constraints, so the key is
359
+ guaranteed by the write path only. On Trino an `upsert` table needs Iceberg
360
+ `format_version` 2 (the default).
361
+ - `full_refresh` stays refused for every python node: a rebuild would destroy
362
+ an accumulating table.
363
+
364
+ ## The script API
365
+
366
+ A node script is a Python file with exactly one required entry point:
367
+
368
+ ```python
369
+ def run(ctx):
370
+ ...
371
+ ```
372
+
373
+ - `ctx` is a `RunContext` (`continuo_python_runtime.context.RunContext`).
374
+ Its only method is `ctx.read(name)`, where `name` is one of the query
375
+ names of the contract's `readQueries` — reading anything else raises
376
+ `ReadError`. Each declared read is fetched once and
377
+ memoized; `ctx.read(name)` returns a `pyarrow.Table`.
378
+ - `run(ctx)` can return anything Arrow-convertible: a `pyarrow.Table`
379
+ as-is, a pandas `DataFrame` (converted via
380
+ `pa.Table.from_pandas(..., preserve_index=False)`), or any object
381
+ implementing the Arrow C stream protocol (`__arrow_c_stream__`) — for
382
+ example a polars DataFrame. Returning anything else raises `ScriptError`.
383
+ - The dataframe library is your choice. No dataframe library is baked into
384
+ the base image — the package's own runtime dependencies are `pyarrow`,
385
+ `PyYAML`, `continuo-engine-contract` and `continuo-contracts`. Add whatever you script
386
+ against (pandas, polars, …) as a `RUN pip install` line in your own
387
+ `Dockerfile`, on top of the base image. The base image runs as non-root
388
+ (uid 65532), which pip cannot install under, so switch to root for the
389
+ install and back afterward — `USER root`, then the `RUN pip install`
390
+ line, then `USER 65532:65532` — since the executor's pod spec expects
391
+ the image to end at uid 65532. See `template/Dockerfile` for the pattern.
392
+ - Scripts do not import warehouse drivers, write raw SQL literals, or call
393
+ data-access methods directly — `continuo-runtime lint` rejects those:
394
+ - forbidden driver imports (`psycopg2`/`sqlalchemy`/`trino`/etc.),
395
+ - SQL string literals (in plain strings, f-strings, and `+` concatenation),
396
+ - forbidden data-access calls (`execute`/`read_sql`/etc.), including ones
397
+ reached via a `from ... import` alias (e.g. `from pandas import
398
+ read_sql as rs` then calling `rs(...)`),
399
+ - private/protected attribute access (`obj._x`) — except on `self`/`cls`,
400
+ so a script's own class-private helpers (`self._helper()`) aren't
401
+ flagged,
402
+ - code the content hash cannot see. The hash folds the script and the files
403
+ it imports, found by reading imports, so a node that runs anything else
404
+ can change without its `content_hash` changing. Lint refuses `runpy`, a
405
+ change to `sys.path` (`append`, `insert`, assignment, `del`, and
406
+ `site.addsitedir`), a `sitecustomize` or `usercustomize` module (and a file
407
+ of that name), `compile()` and `types.FunctionType`, and `pickle.load`,
408
+ `pickle.loads` and `pickle.Unpickler`. `pack` applies the same rules to
409
+ every file in a node's import closure, and refuses a `sitecustomize.py` or
410
+ `usercustomize.py` at the repository root, which Python imports before the
411
+ harness starts. A file a script reads, such as a model or a lookup table,
412
+ belongs in the node's `assets`, where its bytes are hashed.
413
+
414
+ The SQL-literal rule is best-effort: docstrings are exempt, but other
415
+ prose may still occasionally match. The hard guarantees enforced by lint
416
+ are the driver-import and data-access-call rules, together with the fact
417
+ that `RunContext` only exposes `ctx.read()` — all warehouse access goes
418
+ through it.
419
+ - Scripts may import shared in-repo helpers. Before executing a script the
420
+ harness puts the repo root (`APP_ROOT`) and the script's own directory on
421
+ `sys.path`, so both `import helpers` (a sibling of the script) and
422
+ `from lib.shared import ...` (anywhere under the repo root) work, including
423
+ from inside `run()`. Every helper a script reaches transitively is folded
424
+ into `shared_code_hash`, so editing one re-fingerprints the node — but the
425
+ hash does not put the file in the image: **`COPY` every directory your
426
+ scripts import from in your `Dockerfile`**, or the release is valid and the
427
+ node dies with `ModuleNotFoundError` on its first run. Because the repo root
428
+ precedes the standard library on `sys.path`, avoid naming a top-level module
429
+ after a stdlib one (`types.py`, `json.py`, `logging.py`, …).
430
+ - The harness — not the script — performs the write. It calls `conform()`
431
+ on whatever `run()` returned and issues the only INSERT; the script never
432
+ writes directly.
433
+
434
+ ## Conform rules
435
+
436
+ `conform()` (`continuo_python_runtime/conform.py`) enforces the columns the
437
+ node's contract declares on the table `run()` returned, in this order:
438
+
439
+ | Check | Behavior |
440
+ | --- | --- |
441
+ | Duplicate columns | Any duplicate column name in the returned table always raises `ConformError`. |
442
+ | Extra columns | Governed by the contract's `extraColumns` policy: `raise` (default) fails the run; `warn` drops the undeclared column(s) and logs a warning. |
443
+ | Missing columns | Any declared column absent from the returned table always raises `ConformError`. |
444
+ | Column order | The table is reselected into the declared column order. |
445
+ | Strict cast | Each column is cast to its declared Arrow type with `safe=True`. Casts pyarrow's `safe=True` would silently accept but that are not value-lossless are rejected before the cast even runs: floating → decimal (rounds to scale), non-boolean → boolean (coerces truthiness), timestamp → date (drops time-of-day). Any other cast failure also raises `ConformError`. |
446
+ | Not-null | A column declared `required: true` that contains any null raises `ConformError`. |
447
+ | VARCHAR/CHAR length | A column declared `VARCHAR(n)`/`CHAR(n)` whose longest value exceeds `n` raises `ConformError`. |
448
+
449
+ ## Error taxonomy
450
+
451
+ Every runtime failure is one of six `HarnessError` subclasses
452
+ (`continuo_python_runtime/errors.py`). The sentinel result block's message
453
+ is prefixed `<ErrorClass>: ` so failures can be triaged without parsing free
454
+ text. The harness also logs the same message at ERROR on stderr, with the
455
+ traceback of the exception it wraps (a driver error, the script's own
456
+ exception), so the stored log of a failed run names its failure: Continuo cuts
457
+ the result block out of the log before storing it.
458
+
459
+ | Class | Meaning | Typical fix target |
460
+ | --- | --- | --- |
461
+ | `ContractError` | Contract missing or invalid, node not found for `NODE_ID`, or the declared script is missing/unreachable. | The contract file or its `script` path. |
462
+ | `ImageContractMismatch` (a `ContractError`) | The image does not hold the contract, script, imports or assets the release hashed: the `content_hash` in `CONTENT_HASH` differs from the one the image's files give, or a file the release hashed is missing from the image. The block also carries `"reason":"image_contract_mismatch"`. | Rebuild the image from the released commit, with CI and the image on the same runtime. |
463
+ | `ReadError` | `ctx.read()` was called with an undeclared name, or a declared read failed at the warehouse. | The contract's `readQueries`, or the upstream query/warehouse access. |
464
+ | `ScriptError` | `run()` raised, has no callable `run`, or returned a value that isn't Arrow-convertible. | The node script. |
465
+ | `ConformError` | Structural mismatch (extra/missing/duplicate columns), a strict-cast failure, a not-null violation, a VARCHAR/CHAR overflow, or an `upsert` run whose rows repeat a primary key. | The script's output shape, or the contract's columns. |
466
+ | `LoadError` | Adapter construction failed, the installed engine does not support the node's `modeType`, the live table's shape differs from the contract's columns (append/upsert), or the DDL/INSERT failed at the warehouse during the write. | Warehouse connectivity/permissions, the engine image, or the target table. |
467
+
468
+ ## Engine selection
469
+
470
+ A domain repo picks its warehouse engine by which base image it builds
471
+ `FROM`:
472
+
473
+ ```dockerfile
474
+ FROM ghcr.io/carolsimone/continuo-python-runtime-postgres:v0.13.0
475
+ # or
476
+ FROM ghcr.io/carolsimone/continuo-python-runtime-trino:v0.13.0
477
+ # or
478
+ FROM ghcr.io/carolsimone/continuo-python-runtime-duckdb:v0.13.0
479
+ ```
480
+
481
+ The engine is part of the image **name**; the tag is the bare version, so
482
+ Continuo's Helm chart can pin an image as `<name>:vX.Y.Z@sha256:<digest>`.
483
+
484
+ Each image bakes in exactly one `WarehouseAdapter` for that engine — the
485
+ pinned PyPI version of the `continuo-postgres-adapter`,
486
+ `continuo-trino-adapter` or `continuo-duckdb-adapter` package built from this
487
+ repo's `adapters/postgres/`, `adapters/trino/` or `adapters/duckdb/` source
488
+ (see the table above) — registered under the
489
+ `continuo_engine.adapters` entry-point group (entry names `postgres` /
490
+ `trino` / `duckdb`). The runtime discovers it via `discover_adapter()` at run time, so a
491
+ single image serves every node in the service and the release-time
492
+ validation Job for it. The executor injects the warehouse connection as
493
+ environment variables (engine-native, e.g.
494
+ `POSTGRES_HOST`/`POSTGRES_DB`/`POSTGRES_USER`) plus the node-selection
495
+ environment (`NODE_ID`, `TABLE_NAME`, `TARGET_SCHEMA`) that
496
+ `continuo-runtime run` reads to pick the node. `CONTRACT_DIR`, the folder of
497
+ the image's `*.odcs.yaml` contracts (`/app/contracts` by default), and
498
+ `APP_ROOT`, the repository root a node's `script` path is resolved against,
499
+ are optional.
500
+
501
+ ### Build your own container
502
+
503
+ A domain repo does not have to build `FROM` the published engine image.
504
+ `template/` ships two Dockerfiles for the two build shapes (see
505
+ `template/README.md` § "Choosing a base" for the full comparison):
506
+
507
+ - **Shape 1 — `template/Dockerfile`** — `FROM` the published engine image
508
+ (`continuo-python-runtime-<engine>`), as shown above. Simplest; the image
509
+ already has the runtime and adapter installed and pinned.
510
+ - **Shape 2 — `template/Dockerfile.pip`** — your own base image, installing
511
+ `continuo-python-runtime` and one `continuo-<engine>-adapter` from PyPI
512
+ via a hash-locked `requirements.lock` (`template/requirements.lock`). Use
513
+ this when you must control the base image yourself.
514
+
515
+ Both shapes end up running the same runtime and the same adapter version;
516
+ which one you pick only changes who controls the base OS layer underneath
517
+ them.
518
+
519
+ ## Seed preflight and view probe
520
+
521
+ Two validation ops read the warehouse and change nothing. They run through the
522
+ same runner image as the other validation ops (`VALIDATION_OP`), need no
523
+ `DBT_TARGET_SCHEMA`, and print one result block as the last line of stdout.
524
+
525
+ A seed reload drops and recreates the seed's production table. On an engine where
526
+ a drop destroys the objects that read the table (`drop_semantics` `cascade`,
527
+ postgres) that takes every view, function and constraint built on the seed with
528
+ it, including objects continuo does not own. On an engine where those objects
529
+ survive and fail on their next read (`late_binding`, trino and duckdb) they
530
+ may go stale. `seed_preflight` lists what a reload would touch and compares it
531
+ with what the operator has allowed or acknowledged; `probe_views` tries named
532
+ views after a reload and says which no longer bind.
533
+
534
+ `seed_preflight` runs in two places. `check` runs in the seed task's own pod just
535
+ before dbt and stops the reload with exit 1 when the check concludes it must.
536
+ `report` runs in the release's seed-build Job and only reports what a `check`
537
+ would conclude; it exits 0 whatever it finds.
538
+
539
+ ### `seed_preflight` inputs
540
+
541
+ | Variable | Meaning |
542
+ |---|---|
543
+ | `SEED_PREFLIGHT_MODE` | `check` or `report`. |
544
+ | `SEED_PREFLIGHT_ENGINE_FAMILY` | `schema_bound` or `late_binding`, the family the release plan expects of the engine. |
545
+ | `PROD_SCHEMA`, `TABLE_NAME` | The seed's production relation. |
546
+ | `SEED_PREFLIGHT_ALLOWED`, `SEED_PREFLIGHT_ACKNOWLEDGED` | JSON arrays of `"<schema>.<name>"`, default `[]`. An object is allowed when `<schema>.<name>`, in lower case, is in either list (entries are trimmed and lower-cased). |
547
+ | `NODE_ID` | Optional; the block's `unique_id`. Default `<PROD_SCHEMA>.<TABLE_NAME>`. |
548
+
549
+ The adapter's own variables (`POSTGRES_*`, `TRINO_*`, ...) are needed as for any
550
+ other op. An adapter's family is `schema_bound` when its `drop_semantics` is
551
+ `cascade`, and `late_binding` when it is `late_binding`.
552
+
553
+ ### `seed_preflight` block
554
+
555
+ After the standard keys (and `reason` when one applies): `op` (`seed_preflight`),
556
+ `mode`, `checked` (the warehouse was asked and its listing came back), `engine_family` (as given),
557
+ `drop_semantics` (the adapter's), `completeness` (`exact`, `best_effort`, or
558
+ `none` when nothing was listed) and `dependents`, a list of
559
+ `{schema, name, kind, owner, depth, allowed}` sorted by depth, schema and name.
560
+ `status` is `error` for exit codes 1 and 2, and `failures` is 1 then.
561
+
562
+ `reason` is what a `check` concludes. `report` prints the same `reason` on a
563
+ `success` block.
564
+
565
+ | Situation | `reason` | `check` | `report` |
566
+ |---|---|---|---|
567
+ | a missing or malformed input, no adapter, missing adapter env | none | exit 2 | exit 2 |
568
+ | the adapter's family differs from `SEED_PREFLIGHT_ENGINE_FAMILY`, or it declares none | `engine_mismatch` | exit 1 | exit 0 |
569
+ | the adapter cannot list dependents, `schema_bound` | `unowned_dependents` | exit 1 | exit 0 |
570
+ | the adapter cannot list dependents, `late_binding` | none | exit 0 | exit 0 |
571
+ | the connection fails | `warehouse_unreachable` | exit 1 | exit 0 |
572
+ | the listing fails, `schema_bound` | none | exit 1 | exit 0 |
573
+ | the listing fails, `late_binding` | none | exit 0 | exit 0 |
574
+ | listed, `schema_bound`, an object is not allowed | `unowned_dependents` | exit 1 | exit 0 |
575
+ | anything else listed (on `late_binding` the objects not allowed are external views that may go stale, named in `message`) | none | exit 0 | exit 0 |
576
+
577
+ A seed table that does not exist yet has no dependents and passes. A stop's
578
+ `message` starts with its `reason` and names each object outside the set as
579
+ `<schema>.<name> (<kind>, owner <owner>)`.
580
+
581
+ ### `probe_views`
582
+
583
+ `PROBE_VIEWS` is a JSON array of `"<schema>.<name>"`, split on the first dot;
584
+ `NODE_ID` is optional (default `probe_views`). Each view is read with
585
+ `SELECT * FROM "<schema>"."<name>" LIMIT 0`. The block has `op`
586
+ (`probe_views`), `checked` (the warehouse was reachable) and `views`, a list of
587
+ `{schema, name, ok, error}` in the order given, where `error` is the first line
588
+ of the failure, at most 500 characters, and empty when `ok`. A view that fails
589
+ its probe never fails the op: the exit code is 0, and `message` reads
590
+ `<n> of <total> views failed: <names>`. A warehouse that cannot be reached gives
591
+ exit 0, `checked` false, `views` empty and `reason` `warehouse_unreachable`.
592
+ Only a missing or malformed input, no adapter, missing adapter env or an
593
+ unexpected error is exit 2.
594
+
595
+ ## Further reading
596
+
597
+ - `docs/boundary-contract.md` — the boundary between continuo and a domain
598
+ repo (§13): the five surfaces (the contract bundle, the hashes `pack`
599
+ computes, the release call, the runtime image, and the domain repo's CI)
600
+ that this repo implements, and every field a contract may carry.
@@ -0,0 +1,36 @@
1
+ continuo_python_runtime/__init__.py,sha256=otNaXEPsTtRXJV5FLtDUsFO8VD4OC-MLAzwhtimHfOE,70
2
+ continuo_python_runtime/cli.py,sha256=Els6893QLyvSziGBjCJ3_8Ax9dbxtT7AZ0Ed-cEK6bs,8620
3
+ continuo_python_runtime/closure.py,sha256=6e-IAQp8Lieb0bGKP1F6JE4TgVBJ_COTGXRUult2xeI,12991
4
+ continuo_python_runtime/conform.py,sha256=a9CKCA-gT9Zerzr6c5H8aByTFOUd6uBMo02sNKSDnXg,9199
5
+ continuo_python_runtime/content_check.py,sha256=FbngEt-lEwpfxO-qrhsDWXbBignmpP3ATLQ4hdkcWR4,2972
6
+ continuo_python_runtime/context.py,sha256=K-9XXYlQ4OZ250rCOq6EJNq7fg_D5sK6tOcu7DLZfVg,1856
7
+ continuo_python_runtime/csv_loader.py,sha256=a5Hwu-YIzIiko8X1_vqShsnzjs2-OsKEUSCHLXg_dio,3346
8
+ continuo_python_runtime/csv_source.py,sha256=7g8Tu6ieiJLvWH4Ep4nwYlOdGkjeePr12K5UHuO8TNc,4136
9
+ continuo_python_runtime/errors.py,sha256=WCqMMbuy5iXMB-FUzbVmB6AuUbjU95y2iyGGv8zj-LU,1361
10
+ continuo_python_runtime/harness.py,sha256=CxDXcVcBWK3J70rwtzY_1ytucjFBThTfY3-9oONeiHk,18102
11
+ continuo_python_runtime/hash_inputs.py,sha256=lKCiCFhfeE80o030JfjPosonEbr_4zWK7CsEgM_g0FM,2376
12
+ continuo_python_runtime/hashing.py,sha256=naBygHNmiPiJi6K6ZWBYdr21vw2ja_-A8qQF7vJ7iSs,3230
13
+ continuo_python_runtime/lint.py,sha256=Q8G-AOv6hx0d9hVXAJ5xpBvMZZpNaWRsoj9ES0NxsBg,21575
14
+ continuo_python_runtime/packages.py,sha256=pFADmg7em7_q42ijKIDqk1BTkuYm-xwcLz5eE9M_ZmI,2080
15
+ continuo_python_runtime/shape.py,sha256=C-5ClSxPYgoO9pUiGqw7pCnmlBbsEl-sIm7Twbf-H4o,3693
16
+ continuo_python_runtime/types.py,sha256=_ssxNE2Lq5782n9_Ihs-u_6ybCCy8XaL6iYbE35tBug,5057
17
+ continuo_python_runtime/contract/__init__.py,sha256=S79x6j_P0CmaSuCGzeWoK1U0507KvD2MZXwQl9DFWMM,37
18
+ continuo_python_runtime/contract/kinds.py,sha256=nGX1KdYgENzUETbc48V6ru7qU9K8dOUQ54N05ZRAwf0,6163
19
+ continuo_python_runtime/contract/loader.py,sha256=iDp-RZaKzwMiOvPDGHXpfptBtXCJAb2rUz1DkRLg87s,12998
20
+ continuo_python_runtime/contract/model.py,sha256=NCjOZni6n9oEK0K2QyoQcu6D9snefqz1wx2l_M_RgKg,1754
21
+ continuo_python_runtime/contract/pack.py,sha256=9dcHYohaM4m5MUGD54Zorage2c16XloSEORj2Pl-KWs,12926
22
+ continuo_python_runtime/contract/paths.py,sha256=uncZxz11Lfqom4eXFZeErU3dZUy8ShI9NpmiIJ20Abc,2804
23
+ continuo_python_runtime/contract/read_tables.py,sha256=bz3CHplIh9L3ecUuTudiu4D6y4aGcvdiTbopOkF5C2M,4036
24
+ continuo_python_runtime/csv_readers/__init__.py,sha256=9TKvjC37C77uRaJQZuO0--zVj2OvuNwpJE6nWx7j2S8,806
25
+ continuo_python_runtime/csv_readers/https.py,sha256=tMJ9k5F0b9SAydpon0ZlOznfjvjhF2BBLltyVmvRneE,4998
26
+ continuo_python_runtime/csv_readers/s3.py,sha256=zmvHs3TxlN2alPKrdaHzPyREmkve2nBiAsHRXXe1mE0,2246
27
+ continuo_python_runtime/validation/__init__.py,sha256=hz5oGXsoaUoygR0_pBby9PS6cEfrre518EE0HGB58eE,79
28
+ continuo_python_runtime/validation/preflight.py,sha256=3DSVbPMPqsYg5yMEEDv_1YedN2_e7aYcSh8d2i7vEf8,16093
29
+ continuo_python_runtime/validation/runner.py,sha256=fsTI_XdFG_LWhv9IrgknLI-_FxM1GQXoLmV7xIoIvF8,15034
30
+ continuo_python_runtime/validation/s3.py,sha256=q8nRrT9R7L1-M4dSlDnkL7CUJMPmq86MHY_UKYFlEf8,1785
31
+ continuo_python_runtime-0.13.0.dist-info/METADATA,sha256=W6zmUuws6Obzu-bzUszmmNyumk2NXDnQHCC0R5yYn_E,34998
32
+ continuo_python_runtime-0.13.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
33
+ continuo_python_runtime-0.13.0.dist-info/entry_points.txt,sha256=ZvIwSm9f9B9ZmZMf6CyF5Zt4QONn8rqaIk-u-B1CF2Y,70
34
+ continuo_python_runtime-0.13.0.dist-info/licenses/LICENSE,sha256=hfXfFCk-8gnps4YvHA6bjCNaSYqOrq2gAdqkXYycAQc,11345
35
+ continuo_python_runtime-0.13.0.dist-info/licenses/NOTICE,sha256=ykgYyQkAMx3uas90FZHzt0aTca9IgJQCLpZ4d74Pl3U,465
36
+ continuo_python_runtime-0.13.0.dist-info/RECORD,,