Typed Amazon raw-data provider services for Keble.
Project description
keble-amz
The source line requires keble-helpers>=1.52.2 so exact Keepa/media/storage
usage quantities resolve identically from Git development pins and public
registry installs. Pricing remains the consuming platform's responsibility.
Side effects if changes:
- Data Infra imports these provider usage events through the Amazon manifest.
- Changing the helper floor requires lock, package-contract, and raw API source graph verification together.
keble-amz 2.x is the framework-free Amazon raw-data provider package. The
legacy 1.x monolith remains preserved on maintenance branch 1.0.28; current
source no longer embeds Keepa, cost analysis, ScraperAPI, or bundled wheels.
Version 2.2 owns the public category/traversal contract while a composition
root may inject Shuffle or another private traversal implementation.
The 2.2 provider artifact has a complete public-index dependency graph. It does
not import or declare the private keble-amz-shuffle package, so a bare
pip install keble-amz==2.2.0 can import keble_amz. Data Infra separately
composes the authenticated Shuffle adapter when native trending is enabled.
The remaining runtime bounds use Data Infra contract 0.4, keble-db>=1.9.0,
and one-attempt keble-keepa>=1.4.1. The 1.4.1 floor preserves exact
Decimal capacity evidence when successful live responses enter Keepa's
short-lived Redis cache.
Architecture
keble-data-infra-contract
↑
keble-amz: AmazonServices ──> keble-keepa
│ │ │
│ └──> Amazon-owned typed LLM planner + traversal port
│ ↑
│ private Shuffle adapter (composition only)
└── RedisLeaseManager <- Mongo/Redis cache
AmazonServices exports three baseline operations and conditionally exposes a
fourth when the API composes Shuffle plus the typed model:
lookup_products(ProductLookupQuery)— exact batched ASIN lookup;search_products(ProductSearchQuery)— Keepa title finder plus product load;rank_products(ProductRankingQuery)— current official Amazon category bestseller board.trending_products(ProductTrendingQuery)— category-first, evidence-bearing recent products with native source continuation; never a search/query fallback.
For initial nonblank intent, Amazon selects only real root/child category IDs
through typed Pydantic-AI output. Category and discovery words are removed from
the residual before Product Finder: trending clothing produces a category
plan with no title keyword, while red clothing keeps only red. Blank intent
browses roots without an LLM call. Shuffle reads raw non-deduped pages, expands
wrapper-collapsed children only after definitive source exhaustion, and stops
at true logical depth three. Data Infra alone owns cross-page entity/family
dedupe.
Every returned product carries structured metrics/timestamps plus a neutral summary explaining why it stands out. Root/child model calls and Keepa finder/ product loads all emit exact usage events; Amazon never attaches prices.
Provider clients execute one physical request and never own delayed retry.
Amazon's manifest exports AmazonFailureAdapter, which maps declared Keepa,
timeout, and transport failures into sanitized DataInfraFailure values with
exact capacity, usage, request identity, and recovery disposition. Quota or an
unverified HTTP status never becomes a payment failure.
Provider methods return only keble-data-infra-contract values. Keepa DTOs,
cache policy, and usage accounting remain owned by keble-keepa. Shared
Money, AmazonMarketplace, hashing, and Redis owner-token leases are reused
from Keble packages rather than redeclared.
AmazonServices accepts one package-neutral usage recorder and forwards it to
finder, board, and partial-cache product loading. Each real Keepa cache miss
therefore contributes its provider-reported tokensConsumed event; Amazon
does not infer tokens, attach prices, or replay usage for cache hits. The raw
API captures these events and returns them on the shared page contract.
The package exports no FastAPI app or router. keble-data-infra-api consumes
the manifest and owns all paths, OpenAPI, error handlers, and runtime clients.
Cache and concurrency
Keepa remains the only normalized provider cache. Amazon wraps complete
operation requests in RedisLeaseManager single-flight keys. Every contender
re-enters the Keepa handler after acquiring ownership, so it rechecks Mongo and
spends no upstream call after the first owner persists the result.
Redis lease acquisition and the cache-recheck-or-upstream critical section emit Sentry child spans when the API initializes telemetry. Span names contain only the stable Keepa operation and never ASINs, keywords, request JSON, responses, or credentials.
Lookup delegates to KeepaApiBatchLoader, preserving exact per-ASIN cache
keys, caller order, duplicates, partial hits, negative hits, newest-write-wins
repair, request batching, and usage accounting.
Verification
Python 3.13 and uv are required:
uv lock --check
uv run pytest -q \
-m "not live and not slow and not eval and not local_stack and not db_stack and not container"
KEBLE_BACKEND_ENV_FILE=/path/to/keble.backend/.env \
RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 \
uv run pytest -q tests/integration
KEBLE_BACKEND_ENV_FILE=/path/to/keble.backend/.env RUN_KEEPA_LIVE=1 \
uv run pytest -q tests/live -m "live and keepa_live"
uv run npx --yes pyright .
uv build
Integration/live tests use unique Redis namespaces and Mongo collections and clean them after each run. Secrets resolve by explicit name through the shared backend-env test helper and are never copied into this repository.
Portable product metadata and release qualification
Amazon product mapping carries brand, description, feature bullets, product type, full category path, rating/review observations, source-language hints, and Keepa release-date precision into the Data Infra contract. Recent-release qualification is emitted only when the complete release interval is inside the requested window. Offer/listing history remains ordering evidence and never stands in for a product release date.
Project details
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_amz-2.2.1.tar.gz.
File metadata
- Download URL: keble_amz-2.2.1.tar.gz
- Upload date:
- Size: 101.2 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 |
f004edeec45fa5a32d9ddfdf1fe9b6e3e3b8e024329e43710996eae0ca4f1716
|
|
| MD5 |
eef7b0afa74476885fbfdf5e0cbd8a10
|
|
| BLAKE2b-256 |
3b2a992b59d0be5e9d2b674648418d8da35a5635526e5180efe6d1a59e8d4d5a
|
File details
Details for the file keble_amz-2.2.1-py3-none-any.whl.
File metadata
- Download URL: keble_amz-2.2.1-py3-none-any.whl
- Upload date:
- Size: 23.7 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 |
4c1a4e6e188d33a3311b91cf6d378b1be7f0e2a0f9e8d017be2ed6e2868b637f
|
|
| MD5 |
42f5d4307e38b91ee4e84f22be77d3d1
|
|
| BLAKE2b-256 |
067a2a4af64fe4a1cbdf9e4a9ec65505c5c330204186cf0010d543fc5a0ba7db
|