Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

sleap-roots-contracts

Shared result + provenance contract for the sleap-roots ↔ Bloom pipeline.

This is a small, dependency-light library — code-agnostic toward Bloom (no Bloom import, no DB/network/filesystem I/O) — that defines the shape of a per-scan pipeline result and its provenance (Pydantic v2 models), emits a versioned JSON Schema artifact, and ships a trait-definitions registry. The Python producers (sleap-roots-predict, sleap-roots-traits) import it; Bloom consumes the emitted schema.

It also defines the analysis-input contract — the canonical shape of the wide trait table that crosses the sleap-roots-analyze ↔ Bloom boundary. validate_analysis_input(df, *, strict=False) structurally validates that table against fixed canonical role names (genotype + optional sample_id / replicate / image_path) plus an open set of opaque numeric trait columns, returning a structured ValidationResult. It operates on a pandas DataFrame, so pandas is an optional install extra — pip install sleap-roots-contracts[pandas] — while the runtime core stays pydantic + pyyaml. Canonical example tables ship in the package (sleap_roots_contracts.examples.load_analysis_input_example(...)) so consumers can load a validating frame straight from the released wheel.

It also defines the model-selection contractModelCard and Selector, the Python-side shape shared by sleap-roots-training (which writes a production model's selection metadata as wandb artifact metadata at promotion) and sleap-roots-predict (which reads cards to choose a model per root type and calls to_model_ref(runtime_sleap_nn_version)). Since 0.1.0a8 one card describes one physical model: it carries a scalar root_type plus a non-empty selectors list, where each Selector is one whole validated (species, mode, age_min, age_max) context the model was approved for. A card matches when some single selector matches all of species, mode and age — never the cross product, so a generalist model cannot advertise a combination nobody trained, and an age must be compared against a matching selector's window rather than any card-level bound. root_type stays scalar because it is intrinsic to the weights. Selector.mode and ModelCard.root_type are the controlled Mode and RootType vocabularies, matched exactly. Unlike the result and analysis-input contracts above, it is a producer↔producer contract that never crosses the Bloom boundary, so it is not emitted to the JSON Schema.

Since 0.1.0a6 it also defines the label-selection contractLabelCard, the Python-side label-provenance shape written by the /build-labeling-package workflow (which already computes this metadata and discarded it at publish) and read by training/lineage tooling to answer "where did these labels come from?". Like ModelCard, it is a producer↔producer contract and is not emitted to the JSON Schema.

The contract-owned Mode = {cylinder, multiplant cylinder, plate} vocabulary types the mode field on both registries' cards — Selector.mode on the model side, LabelCard.mode on the label side — making it the single source of truth that closes the cylinder/cyl split between them. Consumers needing the value set for a manual membership check use typing.get_args(Mode) rather than re-declaring it.

Since 0.1.0a5 it also defines the prediction-manifest contractPredictionArtifact/ PredictionManifest, the Python-side shape of predict's per-scan .slp output, written by sleap-roots-predict and read by bloomctl to construct cyl_scan_intermediates blob bytes. Like ModelCard, it is a producer↔producer contract and is not emitted to the JSON Schema.

Since 0.1.0a7 it also defines the run-manifest contractRunManifest/ RUN_MANIFEST_FILENAME, the run-scoping shape written by bloomctl and read by sleap-roots-predict/sleap-roots-traits to scope processing to exactly the scan_keys a run was given. Like ModelCard, it is a producer↔producer contract and is not emitted to the JSON Schema.

Since 0.1.0a4 it also ships the param-resolution oracleresolve_params(metadata, overrides=None) -> ResolvedParams maps a single Bloom cyl_scans_extended scan-metadata row to the {species, mode, age} params that select a ModelCard. It is a pure producer-side function (not emitted to the JSON Schema), and it is the single source of truth for that mapping: its resolved values feed param_hashidempotency_key, so a second copy in a consumer would silently break first-writer-wins idempotency. sleap-roots-predict and bloomctl both import it. It reads Bloom's column names (species_name, plant_age_days) as dict keys — a deliberate, documented soft coupling, hoisted into the module constants SPECIES_NAME_FIELD / PLANT_AGE_DAYS_FIELD.

It is sub-project #1 of the sleap-roots ↔ Bloom integration program. Design and plan: docs/01-contract-library-design.md and docs/02-contract-library-plan.md.

Develop

uv sync
uv run pytest -v
uv run black --check src tests && uv run ruff check src tests

Key ideas

  • Pydantic is canonical; schema/*.json is generated and drift-guarded in CI.
  • Trait values are long-format rows (no jsonb); provenance is a jsonb blob on the source.
  • Hashes (param_hash, idempotency_key) are producer-side only; Bloom treats them as opaque strings.
  • Distributed via PyPI (no Docker image — this is a library).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sleap_roots_contracts-0.1.0a8.tar.gz (31.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sleap_roots_contracts-0.1.0a8-py3-none-any.whl (39.9 kB view details)

Uploaded Python 3

File details

Details for the file sleap_roots_contracts-0.1.0a8.tar.gz.

File metadata

  • Download URL: sleap_roots_contracts-0.1.0a8.tar.gz
  • Upload date:
  • Size: 31.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sleap_roots_contracts-0.1.0a8.tar.gz
Algorithm Hash digest
SHA256 ba4bd2257ebc347df7f8674f69526f3c33621dd91980f4a55a1a8f3fe4136403
MD5 97c60debec65a7ff0efb691c5dab1bef
BLAKE2b-256 a7390794e9206e08c57b32194171d52431f8f1efb1aebb061f55f0454f34cdda

See more details on using hashes here.

File details

Details for the file sleap_roots_contracts-0.1.0a8-py3-none-any.whl.

File metadata

  • Download URL: sleap_roots_contracts-0.1.0a8-py3-none-any.whl
  • Upload date:
  • Size: 39.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sleap_roots_contracts-0.1.0a8-py3-none-any.whl
Algorithm Hash digest
SHA256 bf34c4d0ba9d9cfd59628cb917200cf17c8813a9ab8efe4a86062f63e0ce3bdb
MD5 e4ebc916fdc1654dba58c9a2c558ccf6
BLAKE2b-256 d57b268e7b35ffb3f248c0bf1a03b0d9705148712102da40e0555e2b60b3de42

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page