Skip to main content

ducats

Maintains a DuckDB catalog of file coverage — sat/product columns + a start/end timestamp per file — kept in sync with what's actually on disk. The job it does is sync; the job it deliberately does not do is implement every question you might ask ("which file covers this instant", "which METOP-B files fall in any January", "where are the gaps") as a bespoke function. Once a product is synced, those are plain SQL against a table.

Why

glob() lists files vectorized; regexp_extract pulls fields out of filenames vectorized. For archives with tens of thousands of files, syncing is fast and the resulting table is small — cheap enough to keep on disk and query directly, from this package, another Python process, a notebook, or the plain duckdb CLI.

Install

pip install ducats

(Formerly ducat; renamed because that name is taken on PyPI. The import package and the CLI are ducats too.)

Quickstart

Register a product (see Plugging in a new product below), then:

uv run ducats sync --products-module myproject.gap_products --catalog-path /data/catalog.duckdb
uv run ducats status --catalog-path /data/catalog.duckdb

Then just query:

# which file covers this instant?
uv run ducats query --catalog-path /data/catalog.duckdb --sql \
  "SELECT file FROM my_hourly_files WHERE start_ts <= '2026-03-24 10:00:00' AND end_ts >= '2026-03-24 10:00:00'"

# which files fall in any January?
uv run ducats query --catalog-path /data/catalog.duckdb --sql \
  "SELECT file FROM my_hourly_files WHERE month(start_ts) = 1"

Or skip the CLI and open the file directly — it's a normal DuckDB database:

duckdb /data/catalog.duckdb -c "SELECT file FROM my_hourly_files WHERE month(start_ts) = 1"

Two things worth a real function

Most questions are a one-line WHERE clause once a table's synced — not worth wrapping. Two aren't, because they involve real computation (a generated series anti-joined against what's present, or a window function over ordered intervals), so ducats.queries provides them:

query for archives where... flags...
find_grid_gaps files arrive at a fixed cadence (e.g. one per UTC hour) buckets with zero files
find_contiguity_gaps files are variable-length intervals that should chain end-to-start (e.g. orbit swaths) adjacent pairs whose next.start - this.end falls outside [min_gap, max_gap]
uv run ducats gaps --catalog-path /data/catalog.duckdb --table my_hourly_files \
  --mode grid --bucket 1h

uv run ducats gaps --catalog-path /data/catalog.duckdb --table my_hourly_files \
  --mode contiguity --min-gap 0s --max-gap 1h

Plugging in a new product

A product is a ProductConfig: where its files live, an Extractor that reads group columns + a start/end timestamp out of each file.

from ducats.extract import RegexExtractor
from ducats.registry import ProductConfig, register_product

register_product(ProductConfig(
    name="my_hourly_files",
    base_dir="/data/my_product",
    glob="**/*.nc",
    extractor=RegexExtractor(
        pattern=r"my_product_(\d{14})_(\d{14})\.nc$",
        group_cols={},          # no natural grouping here
        start_group=1,
        end_group=2,
    ),
    group_cols=[],
))

Put that in a module (say myproject/gap_products.py) and run:

uv run ducats sync --products-module myproject.gap_products --catalog-path /data/catalog.duckdb

Nothing is auto-discovered — a product only exists in a given run if its module was explicitly imported via --products-module. That keeps "what's registered" unambiguous instead of depending on import side effects from unrelated code.

Two ways to extract fields

  • RegexExtractor — everything needed (timestamps, grouping keys) is in the filename. Stays entirely inside SQL; fast even at tens of thousands of files. Use this whenever it applies.
  • PythonExtractor — the info is inside the file (a NetCDF/HDF5 global attribute, a sidecar JSON, ...). Registers a Python scalar UDF with DuckDB that opens one file and returns a STRUCT of the fields you need; DuckDB calls it once per row. Slower (one file open per matched file) but the same shape comes out, so nothing downstream cares. See the docstring in ducats/extract.py for a worked example.

Either extractor just needs to leave a temp table named items with columns file, <group_cols...>, start_ts, end_ts — write your own if neither fits.

PythonExtractor accepts cache_path: point it at a file and extracted rows persist across runs, so repeat runs over a mostly-unchanged archive only call fn for files not already cached. This is a different thing from catalog persistence below — it avoids re-opening files, not re-running Python. No staleness detection — if fn's output for a path or the fields schema changes, delete the cache file to force a rebuild.

Catalog persistence

ducats.catalog is the sync layer:

from ducats.catalog import open_catalog, sync_product
from myproject.gap_products import my_hourly_files  # a ProductConfig you registered

con = open_catalog("/data/catalog.duckdb")  # omit the path for in-memory, throwaway
sync_product(con, my_hourly_files)
con.sql("SELECT count(*) FROM my_hourly_files").show()

sync_product always leaves the table matching the current glob — files that disappeared from disk are dropped from it too. Point open_catalog at a real path and the sync work only has to happen again for files that weren't there last time; anything already in the table stays, and other processes/tools can open the same file and query it without touching this package at all.

Using the computed queries as a library

from datetime import timedelta
from ducats.queries import find_grid_gaps
from ducats.report import format_grid_reports

reports = find_grid_gaps(con, "resample", group_cols=["sat", "res"], bucket=timedelta(hours=1))
print(format_grid_reports(reports))

find_grid_gaps/find_contiguity_gaps return dataclasses (GridGapReport/ContiguityReport), not text — ducats.report is a separate, optional formatting layer, so you can consume the structured results directly (e.g. to page on-call, or feed a dashboard) without scraping printed text.

Examples

Product-specific config (filename patterns, group wiring, contiguity tolerances) lives in the consuming repo, not ducats. For a real-world example, see ascat_szf.yaml in eumdac-store.

Development

uv sync
uv run pytest

Metadata

Release files for ducats 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ducats 0.2.0
File Size Uploaded Provenance Actions
ducats-0.2.0.tar.gz 22.1 kB With provenance Details for ducats-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ducats 0.2.0
File Interpreter ABI Platform Actions
ducats-0.2.0-py3-none-any.whl Python 3 none any Details for ducats-0.2.0-py3-none-any.whl

Total release size: 35.6 kB

Release files / ducats-0.2.0.tar.gz

Download URL ducats-0.2.0.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
44ac51527bc88f18b32d8b9930c4824d9da2eea02af0738d2565dcce77339633
BLAKE2b-256 checksum
How to use checksums
c74dcc071361fb6d48adb101e27c814992454b9505e2eab38f011c2161cc1325
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 27, 2026.

Transparency log

Release files / ducats-0.2.0-py3-none-any.whl

Download URL ducats-0.2.0-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15af4f4f846d1b57f4f09a748d062cb3744e8a02f9494d8dccc5eb01fe1d8a31
BLAKE2b-256 checksum
How to use checksums
68cb160c3b6750bec44c483c9b85dfb5bc0d700c0f17a14adca4e200be7f10ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 27, 2026.

Transparency log

Security for ducats 0.2.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.

Select from 2 files

Attestation for ducats-0.2.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 Nov 27, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page