Framework-free raw commerce contracts shared by Keble data providers and the raw API.
Project description
keble-data-infra-contract
Install the provider-neutral public contract with
pip install "keble-data-infra-contract>=0.6.0,<1".
Framework-free, provider-neutral raw-commerce contracts. This distribution owns validated request/response models, provider protocols, operation keys, manifests, and typed domain errors. It intentionally has no FastAPI, database, HTTP client, provider, platform, or idea dependency.
The distribution declares only registry-resolvable runtime dependencies. Do not
add workspace-relative tool.uv.sources here: downstream Git/subdirectory installs
must build this contract without inheriting paths outside the repository checkout.
Provider packages own implementations and native DTOs. The raw API consumes provider manifests and constructs HTTP paths from their typed operation keys.
Page[T] and RankingSnapshot[T] carry a provider-neutral usage list of
keble-helpers.UsageAccountingEvent. Providers measure physical tokens,
requests, items, media, or bytes; this contract only transports those facts.
It must never contain prices, currency conversion, allocation policy, or
deployment secrets. Cache hits return an empty list so old upstream spend is
not replayed to consumers.
Version 0.2.0 is the exact-usage release. It requires
keble-helpers>=1.51.0 and preserves media/storage/compute quantities plus
fully failed video-operation attempts without reconstructing prices. The
distribution has no Git or workspace source override, so consumers resolve the
same public contract in clean build and runtime environments.
Version 0.3.0 adds first-class evidence-bearing TRENDING operations without
aliasing search or rank. Products, creators, sellers, and videos have distinct
typed query contracts; every result carries stable provider identity, optional
product-family identity, structured standout evidence, source exhaustion, and
shrink diagnostics. Providers report raw source truth and never apply cross-page
dedupe. The central raw API alone applies the request's none, entity, or
product_family policy through an opaque continuation session.
Version 0.4.0 adds the provider-neutral indexed-commerce boundary required by
Shopify without reusing TikTok board or Amazon ASIN contracts:
StoreSearchQuery,StoreIdentityLookupQuery,StoreProductsQuery, andProductIdentityLookupQuery;- optional product-search cursors that cannot be combined with numbered pages;
PageInfo.end_cursorwhile preserving numbered-provider metadata;CommerceStoreObservationwith typed popularity values and stable identities;- provider-neutral
CommerceCatalogCoveragewith immutable full/window scope, terminal completeness, absolute cutoff, exhaustion, and outcome counters; - Store Leads product and image counts retained as separate sizing signals;
- indexed query provenance separated from ordered Store Leads/storefront source provenance and immutable artifact ids.
Provider-specific lifecycle values are normalized into closed universal store and listing state enums. Unknown fields, untyped extension bags, inferred identities, and source-provider collapse remain forbidden.
request = ProductTrendingQuery(
query="red clothing",
market="US",
dedupe_mode=TrendDedupeMode.PRODUCT_FAMILY,
)
Blank product intent is valid category browsing. A filtered/dedupe-empty page
may remain continuable; only definitive upstream evidence can set
TrendExhaustion.EXHAUSTED. TrendEvidence.summary is display-ready but must
also carry an auditable metric, event time, or provider-board position.
Version 0.5.0 replaces string-only upstream errors with a single immutable
DataInfraFailure payload and DataInfraFailureError. Provider manifests now
require a ProviderFailureAdapterProtocol; the raw API registers the declared
native exception classes without importing Keepa, Amazon, TikTok, FastMoss, or
EchoTik error types. Retry/payment/operator combinations are validated, payment
requires reviewed evidence, and physical usage/capacity observations remain
exact and sanitized.
The minimum helper line is 1.52.2, which preserves negative provider token
debt and a separate exact refill-reduction rate instead of rejecting, clamping,
or misclassifying those capacity facts.
parse_retry_after(...) is the single shared parser for positive delta-seconds
and canonical IMF-fixdate headers. It ignores malformed, past, zero, and
overflowing hints, returns timezone-aware UTC, and does not apply Platform's
versioned maximum-hint policy.
IdempotencyKeyConflictError is the provider-neutral signal for a caller key
already bound to another operation/request fingerprint. Its safe message never
contains the caller key. Data Infra API owns Redis hashing, claim/replay, HTTP
409, and retention; the contract deliberately owns no datastore policy.
Version 0.6.0 makes the expected non-success HTTP body unambiguous through
DataInfraFailureEnvelope. The envelope contains exactly one validated
failure and rejects parallel detail or extension bags; Data Infra API and
Data Platform must therefore evolve and release their serializers/parsers in
the same wave. A source-aware CI guard compares the current contract src/
tree with the newest package-scoped annotated tag and rejects changed source
whose package version was not advanced. Package metadata regressions also fail
closed.
The minimum helper line is 1.54.0. Currency amounts retain the stable
{"amount":{"value":...},"currency":...} wire shape, while amount.value
now has one explicit meaning: ISO minor units at
Currency.minor_unit_exponent. Use Money.from_minor_units for provider
integer units and Money.from_major_units(Decimal(...)) for human/provider
major-unit decimals; do not reintroduce cents or fixed-two-decimal conversion.
Side effects if changes:
- provider packages must adapt every declared native exception to this model;
- Data Infra API owns HTTP/Retry-After serialization of the payload;
- Idea/Platform own their separate durable job/recovery persistence models.
- provider adapters must use
parse_retry_afterrather than redeclaring HTTP date or numeric parsing.
Side effects if changes:
- provider packages and the raw API serialize these exact camel-case events;
- the Ideas platform deduplicates producer attempt keys and prices quantities with its own immutable profile effective at the event time.
uv run --package keble-data-infra-contract pytest -q keble-data-infra-contract/tests
uv run npx --yes pyright .
uv run python keble-data-infra-contract/src/keble_data_infra_contract/release_guard.py
uv build --package keble-data-infra-contract
Contract values inherit ContractModel, which accepts snake-case Python names
and camel-case wire aliases, rejects undeclared fields, and is frozen. Persisted
Mongo shapes do not belong here; provider/API packages own SchemaBase /
MongoObjectBase aggregates when durability is required.
ContractModel and the deliberately producer-tolerant Job/Result projection
both configure Pydantic through keble-helpers.PydanticModelConfig; a local
ConfigDict convention would split alias and validation ownership again.
Money, Currency, and AmazonMarketplace are imported from
keble-helpers. Provider-native response details remain inside the provider
package instead of crossing this boundary through an untyped extension bag.
Video enrichment uses the same framework-free boundary: immutable asset,
submission, job, completion-event, result, and normalized-projection models plus
one VideoEnrichmentGateway Protocol. HTTP submission and Mongo correlation
remain implementations owned by keble-data-infra-api.
Each video operation outcome carries canonical UsageAccountingEvent rows and
an opaque producer price-profile identity. The normalized projection preserves
both the per-operation status (including partial failure) and a flattened usage
view. It deliberately omits producer estimates and monetary values: ASR/OCR
route policy stays in Video Enrichment, while the Ideas platform resolves its
own immutable rates.
The job read also retains analysisOperationAttempts for every whole-workflow
retry. This is the accounting path for fully failed jobs and for failed provider
calls that precede a later successful result. Consumers must deduplicate by the
producer attempt key carried by each usage event; they must not infer zero cost
from the absence of a result.
Authorized provider transcripts use one canonical VideoTranscript/
VideoTranscriptSegment shape across submission, authoritative result reads, and
the local projection. Reuse evidence binds the normalized transcript checksum to
the data-infra source reference and media SHA-256; a title/description such as
ShortVideo.caption is not a spoken transcript and cannot bypass ASR.
Portable commerce metadata
CommerceProduct may carry provider-neutral description, feature bullets,
product type, full category path, source-language hint, and a precision-aware
release-date interval. RECENTLY_RELEASED is the canonical trend reason;
RECENTLY_LISTED is accepted only as a deprecated input alias and never
emitted. Consumers must not infer absent metadata or replace release time with
offer-history time.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keble_data_infra_contract-0.6.0.tar.gz.
File metadata
- Download URL: keble_data_infra_contract-0.6.0.tar.gz
- Upload date:
- Size: 67.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a1f1c8b21c6f2f74eb928c432df8e0788b42796adbc52e967df9211f947e7b6
|
|
| MD5 |
18524066cbdcd73ef2c08b1e7973558c
|
|
| BLAKE2b-256 |
ee647fd47adae8944c9d2e05c774937e0b3617d43d11da94e2ea0d6e43307e42
|
File details
Details for the file keble_data_infra_contract-0.6.0-py3-none-any.whl.
File metadata
- Download URL: keble_data_infra_contract-0.6.0-py3-none-any.whl
- Upload date:
- Size: 62.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d867e816a387955f539d5cfe125d5465fd5acf103b4760bb962ef99eaf64bfb2
|
|
| MD5 |
1841576558489a8c82fd51694bda19c7
|
|
| BLAKE2b-256 |
7efcc7210ca671cb4a2187e5c97a6e959545d13201dfc1c318d7b3599054e629
|