Skip to main content

Pond Handle

Every Ripple receives a Pond object as its only argument. It holds a DuckDB connection to the Pond's own database and the methods for reading and writing data. You never construct one yourself.

@ripple
def daily_sales(pond):
pond.read_table("transactions.transaction")
pond.write_table("daily_sales", pond.con.sql("SELECT ... FROM \"transaction\" ..."))

Table and Object references take two forms throughout:

  • "table": one of this Pond's own tables.
  • "source.table": a table published by the Source Pond source, which must be listed in [sources].

A reference is split at its first dot. For a name that itself contains a dot, put it in backticks: "`daily.v2`" is this Pond's own daily.v2, and "sales.`daily.v2`" is the Source's. Dotted names work but are best avoided. A reference to a Source the Pond doesn't declare raises ValueError, suggesting backticks if you meant a dotted name of your own.

The Incremental methods (append_table, merge_table, apply_zset, read_delta, is_new, trickle) are documented on Trickle I/O and Trickle Builder.

Attributes​

AttributeTypeDescription
conduckdb.DuckDBPyConnectionConnection to the Pond's database (its registry), shared by all its Ripples. Tables written here are published when the Pond Run succeeds.
namestrThe Pond's name.
versionstrThe deployed version, such as "1.2.0".
fdatetimeThe freshness of this Pond Run, timezone-aware UTC. It stays the same across retries and crash recovery of the same run, so it is safe to use as a watermark or provenance stamp. In a local run it is the run's start time.
previous_fdatetimeThe freshness of the previous successful run. On the first run it is datetime.min in UTC, so the window (previous_f, f] covers everything.

Reading tables​

read_table​

pond.read_table(ref) -> duckdb.DuckDBPyRelation

Returns a relation over a table's current contents.

For a Source table, it also registers a view with the table's bare name, so the SQL that follows can refer to it directly (FROM product). If one of this Pond's own tables already has that name, the view isn't created, but the returned relation still works. Each Source is read as it stood when the run started: a plain table at the version the Source had published by then, and a Trickle with the rows it had published by then. That can be later than the run's own freshness, which is the oldest of its Sources'. Every Ripple in a run therefore sees the same Source data, even if the Source publishes again while the run is in progress.

For a Trickle, the result is the clean current state, without the _duckstring_f and _duckstring_d system columns.

ParameterTypeDescription
refstr"table" or "source.table".

Raises MissingSourceAsset (a subclass of FileNotFoundError) when a Source table hasn't been published. Duckstring treats this as waiting rather than failing: the Pond is parked until the Source publishes again, with no retry spent and no alert sent.

Raises duckstring.core.RippleOrderError when reading one of the Pond's own tables that another Ripple writes, if that Ripple isn't among this Ripple's parents (directly or further up). The read could otherwise see the previous run's data. count_table checks the same.

note

Refer to Source tables by their registered view name in SQL. Referring to a Python variable that holds a relation (FROM rel) relies on DuckDB scanning Python frames, which is unreliable under the Duck's threaded executor.

count_table​

pond.count_table(ref) -> int

Returns the current number of rows in a table without scanning it where possible. For a Trickle, the count comes from file metadata and the net weight of the change log.

ParameterTypeDescription
refstr"table" or "source.table".

Writing tables​

write_table​

pond.write_table(name, relation, *, if_changed=False, cluster_by=None, interleave=True, cluster_bits=None) -> bool

Replaces the table name in the Pond's database with the contents of relation, in one transaction. A write that collides with another Ripple's write is retried rather than failing.

Every table in the Pond's database is published when the whole Pond Run succeeds. If any Ripple fails, nothing from the run is published.

ParameterTypeDescription
namestrTable name. Tables whose names start with _duckstring_ are internal and never published, and columns with that prefix are rejected at publish.
relationduckdb.DuckDBPyRelationThe new contents.
if_changedboolWrite only if detect_change finds that relation differs from the published table. When it doesn't, nothing is written and the published table is kept as it is.
cluster_by, interleave, cluster_bitsOrder the table as it's written, as for merge_table, so reads filtering on those columns skip most of it. The table is sorted on every write. Without cluster_by, it keeps the order relation produced.

Returns True if the table was written. Without if_changed it always is.

Raises DeltaError for an invalid clustering, such as a column relation doesn't have.

To keep history for downstream incremental reads, use append_table or merge_table instead.

Objects​

Objects are named, non-tabular outputs: a trained model, a serialised vectoriser, a rendered report. Each is a single file or a directory, published and replaced as one unit.

write_object​

pond.write_object(name, src, *, if_changed=False) -> bool

Stages an Object to be published with the run's tables. A later Ripple failure leaves the previously published Object in place.

ParameterTypeDescription
namestrObject name: letters, digits and underscores, starting with a letter or underscore, optionally with single dots between parts (model.pkl). Read a dotted name back with backticks.
srcpath, bytes or binary file-likeA file path, a directory path (published as one Object), raw bytes, or an open binary file.
if_changedboolPublish only if the content differs from the published Object, compared by a SHA-256 of the payload. When it doesn't, the published Object is kept, with the freshness of the run that last changed it.

Returns True if the Object was staged for publishing. Without if_changed it always is.

Raises RuntimeError outside a Pond Run.

read_object​

pond.read_object(ref) -> bytes

Returns the bytes of a single-file Object. Reading one of this Pond's own Objects returns the version staged in this run if there is one, otherwise the published one.

ParameterTypeDescription
refstr"name" or "source.name".

Raises duckstring.objects.ObjectError for a directory Object; use object_path instead.

object_path​

pond.object_path(ref) -> pathlib.Path

Returns a local path to an Object, file or directory. An Object held in object storage is downloaded once per run to a scratch directory. Treat the path as read-only.

ParameterTypeDescription
refstr"name" or "source.name".
import pickle

@ripple
def train(pond):
model = fit(pond.read_table("sales.sale_line").df())
pond.write_object("model.pkl", pickle.dumps(model))

@ripple(parents=[train])
def score(pond):
model = pickle.loads(pond.read_object("`model.pkl`"))
...

App data​

An App's Records and Media are read with these. An App line is named name@major, as in "feedback@1". Neither is a Source, so nothing tells the engine when they change: an Inlet reading them always runs when asked, and in a Pond with Sources the Ripple reading them sets always_run=True. Under pond run, they're read from the Puddles: a Records table from puddles/records/{name}_v{major}/{table}.parquet and Media from puddles/media/{name}/m{major}/.

read_records​

pond.read_records(ref) -> duckdb.DuckDBPyRelation

Returns an App line's Records table as a relation, read when the relation runs. To keep a history of what the App changed, merge_table the result with its key.

ParameterTypeDescription
refstr"name@major.table", such as "feedback@1.ratings".

media​

pond.media(line, folder="") -> MediaInput

Returns an App line's Media, or a folder of it, as this Ripple's Run sees it.

ParameterTypeDescription
linestr"name@major", such as "feedback@1".
folderstrA folder within the line's Media, such as "attachments". By default, all of it.

A MediaInput has:

MemberDescription
files()Every file, as {"path", "size", "modified"} dictionaries sorted by path. Paths are relative to the line's Media, and modified is an ISO 8601 time.
added()The files new or changed since this Ripple's previous completed Run. Every file on a first Run or after a Rebuild.
removed()The paths of files gone since this Ripple's previous completed Run.
open(path, mode="rb")A file, opened for reading.
path(path)A file as a local path, fetched into scratch space when Media is in an object store.
versionA digest of every file's path, size and modification time.
changedWhether version differs from what this Ripple's previous completed Run read. Always True on a first Run and after a Rebuild.

Change detection​

Duckstring skips a Pond Run when none of its Sources changed since the last run. These methods let a Ripple take part in that decision, and find out which tables and Objects changed so it can skip just the work that depends on the rest.

Every published table and Object has its own change freshness: the freshness of the run that last changed it. A Trickle table changes when a run writes rows to it. An Object changes when it's written. A plain table counts as changed every time it's written, unless it's written with if_changed=True (or checked with detect_change and then not written), in which case a run that finds it unchanged keeps the published version, and its change freshness stays where it was. Downstream, that table then reads as unchanged, so read_delta returns an empty delta for it and the Trickle builder doesn't recompute in full because of it.

changed​

pond.changed(*refs) -> bool

Whether any of refs changed, as seen by this run. With no arguments, whether this run has changed any of the Pond's own tables or Objects so far.

ReferenceChanged when
A Source's plain tableThe version this run reads is newer than the one the previous run read.
A Source's append or merge TrickleRows were added, changed or removed since what the previous run read, or the change can't be read as changes (the Pond's first run, or the previous run's read is older than the Source's retained history).
A Source's ObjectIt was written after what the previous run read.
One of this Pond's own tables or ObjectsThis run wrote it and didn't keep the published copy. A Trickle write counts only if it changed the table.
ParameterTypeDescription
refsstrTable or Object references, "name" or "source.name".

The own forms only see writes made through the handle (write_table, write_object, append_table, merge_table, apply_zset and the builder's terminals) and checks made with detect_change. A table changed with SQL on pond.con doesn't count.

Raises RippleOrderError for one of the Pond's own tables written by a Ripple that isn't this Ripple or one of its ancestors, as for read_table, and MissingSourceAsset for a Source table or Object that hasn't been published.

To mark the whole run unchanged when none of the Pond's own output changed, ask from a Ripple that runs after the others:

@ripple(parents=[load_rates, load_products])
def done(pond):
if not pond.changed():
pond.skip()

To skip one Ripple's work when an input it reads didn't change:

@ripple
def price_tiers(pond):
if not pond.changed("products.product"):
return # price_tiers stays as it was
...

detect_change​

pond.detect_change(name, value, *, exact=False) -> bool

Whether value differs from what is published as this Pond's own table or Object name. Nothing is written.

ParameterTypeDescription
namestrOne of this Pond's own tables or Objects.
valuerelation, path, bytes or binary file-likeA duckdb.DuckDBPyRelation is compared as a table. Anything else is compared as an Object; a file-like is read, then rewound when it can be.
exactboolTables only. Compare the rows themselves (EXCEPT ALL in both directions) against the Pond's copy of the table, instead of fingerprints. Slower, but it can't be fooled by a hash collision.

A table is compared by fingerprint: a hash over every row, independent of row order and counting duplicate rows, combined with the column names and types. It costs one scan of value. An Object is compared by a SHA-256 of its payload, with a directory hashed file by file.

Returns True whenever it can't show the two are the same: nothing published yet, a table last written without a fingerprint, a fingerprint taken by a different DuckDB version (an upgrade costs one republish per table), or a Pond database that no longer holds the published table (a failed run left newer data there, which later Ripples would read).

If it returns False and the run doesn't then write name, the published copy is kept. Writing anyway is always allowed and counts as a change, so you can confirm a fingerprint match your own way first. write_table(..., if_changed=True) and write_object(..., if_changed=True) are shorthands for checking and then writing. A write_table of the same relation object right after a check records its fingerprint, so the next run can compare against it.

sources_changed​

pond.sources_changed() -> bool

Whether any Source's output changed since this Pond last ran. Always True in a local run. Mainly useful in a Ripple declared with always_run=True, which runs regardless and can use this to skip its data work.

skip​

pond.skip() -> None

Marks this Pond Run as producing no change. Downstream Ponds then treat this Pond's output as unchanged, and a Pond whose Sources are all unchanged passes without running. Freshness still advances. Calling it from any Ripple marks the whole run, so call it once you know nothing the Pond publishes changed, usually from a Ripple that runs last. Has no effect in a local run.

changed() with no arguments is the usual signal for calling it. The Trickle write methods also return whether they changed anything:

@ripple
def by_product(pond):
pond.read_table("priced.priced_line")
totals = pond.con.sql("SELECT product_id, SUM(revenue) AS total_revenue FROM priced_line GROUP BY product_id")
changed = pond.merge_table("revenue_by_product", totals, pk="product_id")
if not changed:
pond.skip()

Run reports​

A Ripple can record facts about its Pond Run, such as how old the data an Inlet loaded already was. Duckstring carries them downstream with the data: every Pond below keeps the reports of each upstream Run whose data it read. Nothing in orchestration reads them.

report​

pond.report(reports: dict) -> None

Records reports, a dict of JSON values, for this Run. Datetimes and dates are stored as ISO strings; anything else JSON can't hold raises TypeError. Several calls in a Run merge, later keys winning, and the reports of a Pond's Ripples merge in Ripple-name order. A Run that calls skip still carries its reports.

@ripple
def load(pond):
... # load the newest hour the source has published
pond.report({"data_as_of": newest_hour})

reports​

pond.reports() -> dict

Returns the reports of the upstream Runs whose data this Run read, keyed by the reporting Pond (name@major), then by the freshness of its Run:

{"pageviews@1": {datetime(2026, 11, 9, 20, 0, tzinfo=timezone.utc): {"data_as_of": "2026-11-09T17:00:00+00:00"}}}

It holds the reports that reached the Pond's Sources since its previous Run, every one of them on a first Run. A Pond that runs less often than its Sources sees a report for each Source Run it caught up on. Reports come from every Pond upstream, not only the direct Sources. This Run's own reports aren't included.