jeevesagent.data.lineage¶
Freshness and lineage policies for CertifiedValue.
A CertifiedValue (defined in jeevesagent.core.types)
carries provenance metadata: source, fetched_at, optional
valid_until, schema_version, and a tuple of upstream value IDs
in lineage.
This module supplies the policy types and helpers. Two flavours:
FreshnessPolicy— declare a maximum age per source prefix;valid_untilalways wins when set on the value itself.LineagePolicy— declare an allow-list of source prefixes every value in a lineage chain must originate from.
Two helper styles for each:
check_*returnsTrue/Falseso callers can branch.require_*raises the appropriateFreshnessError/LineageErrorso callers can rely on exception propagation.
Classes¶
Maximum age for certified values from each source. |
|
Allow-list of source prefixes for the entire lineage chain. |
Functions¶
|
Return |
|
Return |
|
Raise |
|
Raise |
Module Contents¶
- class jeevesagent.data.lineage.FreshnessPolicy[source]¶
Maximum age for certified values from each source.
per_sourcemaps a source-prefix (matched withstartswith) to atimedelta. The first prefix that matches wins.defaultis used when no prefix matches; if alsoNone, the policy treats all values as fresh.- classmethod from_dict(per_source: dict[str, datetime.timedelta] | None = None, *, default: datetime.timedelta | None = None) FreshnessPolicy[source]¶
- max_age_for(source: str) datetime.timedelta | None[source]¶
- default: datetime.timedelta | None = None¶
- per_source: tuple[tuple[str, datetime.timedelta], Ellipsis] = ()¶
- class jeevesagent.data.lineage.LineagePolicy[source]¶
Allow-list of source prefixes for the entire lineage chain.
A
CertifiedValueis acceptable if every entry invalue.lineage(interpreted as a source prefix) starts with one of the allowed prefixes.
- jeevesagent.data.lineage.check_freshness(value: jeevesagent.core.types.CertifiedValue, policy: FreshnessPolicy, *, now: datetime.datetime | None = None) bool[source]¶
Return
Trueifvaluesatisfiespolicyatnow.Logic:
If
valid_untilis set on the value, fail ifnow > valid_until.Look up
policy.max_age_for(source). IfNone(no rule), the value is fresh by default.Otherwise fail if
now - fetched_at > max_age.
- jeevesagent.data.lineage.check_lineage(value: jeevesagent.core.types.CertifiedValue, policy: LineagePolicy) bool[source]¶
Return
Trueif every lineage source is allowed.The value’s own
sourceis also required to be in the allow-list — there’s no point trusting a chain whose tip you don’t.
- jeevesagent.data.lineage.require_freshness(value: jeevesagent.core.types.CertifiedValue, policy: FreshnessPolicy, *, now: datetime.datetime | None = None) None[source]¶
Raise
FreshnessErrorwhencheck_freshness()fails.
- jeevesagent.data.lineage.require_lineage(value: jeevesagent.core.types.CertifiedValue, policy: LineagePolicy) None[source]¶
Raise
LineageErrorwhencheck_lineage()fails.