Skip to main content

keble-keepa

The source line requires keble-helpers>=1.54.0 so exact Keepa token/call usage uses the same public contract in development and registry installs. Provider pricing remains outside this package.

Side effects if changes:

  • Amazon provider services and Data Infra transport these usage events.
  • Changing the helper floor requires lock and downstream raw API verification.

keble-keepa is Keble's Keepa API and cache package. It owns Keepa object schemas, sync/async API access, Mongo cache CRUD, batch loading, time conversion helpers, and pytest fixtures/fakes for downstream packages.

Verified State

Checked on 2026-07-31 against pyproject.toml, package exports, keble_keepa/, and tests.

  • Source line: keble-keepa 1.5.1
  • Latest published PyPI release: 1.4.5
  • Python: >=3.13,<3.14
  • Critical deps: aiohttp, requests, keble-db, keble-helpers, keble-exceptions, python-dateutil
  • Source roots: api/, crud/, schemas/, testing/, utils/
  • Public exports: Keepa API objects, the async transport boundary (KeepaAsyncTransportProtocol, KeepaAioHttpTransport, KeepaAsyncRequest, KeepaAsyncResponse, KeepaReadRequestPlan), batch loader, cache helpers, time conversion helpers, and the keble_keepa.testing pytest plugin.

Release lines

1.5.x is deliberately git-only: the Keble connector program pins it by full commit SHA and these releases are not published to PyPI. Install 1.5.x from a pinned Git ref, not from an index.

The newest published release remains 1.4.5 (pip install "keble-keepa>=1.4.5,<2"). Both lines require the shared keble-db>=1.9.0 persistence contract and the shared upstream-failure plus exact-money vocabulary in keble-helpers>=1.54.0.

Legacy-code honesty

This is a long-lived package. It still contains pre-existing try/except, getattr, and loosely typed (Any) boundaries in code that predates the current workspace rules — for example KeepaApiMemoryCache.aget and the _get/_post/_aget/_apost query parameters. Those occurrences are intentionally left alone rather than mass-refactored. New and changed code in this package must introduce none.

Keepa Price Integer Boundary

Keepa price histories are normalized internally to fixed hundredths of a major currency unit, including synthetic * 100 normalization for JPY. Product converts that provider-specific integer to exact Decimal major units before constructing canonical Money; the shared ISO exponent then stores USD cents, JPY yen, and other currencies correctly. Never pass a Keepa price integer directly to Money.amount. Downstream calculations use the public keepa_price_int_to_major_units or money_from_keepa_price_int boundary rather than redeclaring Keepa's scale.

Prompt and recent-series presentation uses the same Decimal decoder. Integral float containers from parsed CSV rows are accepted, while fractional provider values and malformed zero-decimal rows fail closed instead of being rounded into a different displayed price.

Side effects if changes:

  • Keepa Analysis and Product Report derive price, revenue, and budget facts from this exact provider-unit boundary.
  • Changing the fixed-hundredths interpretation requires coordinated downstream schema, calculation, and persisted-data migration.

Runtime Contract

  • Sync Keepa calls use requests; async Keepa calls use aiohttp and should respect standard proxy environment variables when configured by callers.
  • Every async Keepa attempt goes through one narrow protocol boundary, KeepaAsyncTransportProtocol.send(request=KeepaAsyncRequest). KeepaApi accepts an optional async_transport=; passing None (the default) constructs the concrete KeepaAioHttpTransport from the client's own timeout/proxy session config, so default runtime behavior is unchanged. Injecting a transport replaces the ONLY physical attempt path — an implementation must perform exactly one attempt and must never retry, sleep, or classify failures itself.
  • Each async read projects its Keepa path and query parameters through a pure KeepaApi.build_*_request_plan(...) -> KeepaReadRequestPlan classmethod, so path/query correctness is testable without any HTTP layer and the sync and async capabilities keep one shared cache key space.
  • Bestseller boards expose both request_best_sellers and genuine-aiohttp arequest_best_sellers; the async method uses the same typed Redis/Mongo cache key and emits usage only after real upstream I/O.
  • Every stable read capability has a genuine aiohttp counterpart so async consumers never block an event loop: abrowsing_deal, acategory_lookup, acategory_search, alightning_deal, amost_rated_seller, aproduct_finder, aproduct_search, arequest_best_sellers, arequest_products, arequest_seller_information, and aretrieve_token_status. Each async method reuses its sync counterpart's Keepa path and query projection, so both share one cache key space.
  • retrieve_token_status / aretrieve_token_status are deliberately uncached in both directions: they report live remaining token capacity, so serving a cached balance would let a caller overspend Keepa's real budget.
  • Every typed response retains Keepa's tokensConsumed field. Async cache misses emit that exact provider token count through UsageAccountingRecorderProtocol; missing or zero reports remain USAGE_ONLY and therefore billing-unknown rather than being inferred free.
  • Cache hits emit no usage event even though cached response metadata is retained for traceability.
  • Short-lived Redis response serialization uses Pydantic JSON mode so exact Decimal refill/capacity values survive successful live calls and cache replay.
  • Every physical Keepa request is attempted once. The package does not sleep, retry, recursively split failed batches, or silently drop failed ASINs; provider exceptions reach Data Infra intact and durable retry belongs to the Platform worker.
  • Rejections retain HTTP status, request ID, typed Keepa error data, and exact capacity evidence. refillIn is milliseconds, negative tokensLeft remains valid evidence, and gross refill is distinct from token-flow reduction.
  • Failed async HTTP responses emit provider-reported tokensConsumed usage before the typed exception is raised; non-JSON failures remain usage-unknown rather than being inferred free.
  • Cache reads and writes must stay explicit about key, marketplace, and freshness behavior. Do not hide broad cache scans behind convenience APIs.
  • Downstream tests should use keble_keepa.testing fixtures/fakes before inventing package-local Keepa mocks. In particular use RecordingKeepaAsyncTransport (a typed KeepaAsyncTransportProtocol double) instead of patching aiohttp; it records every attempt and raises KeepaTestTransportExhausted rather than silently repeating a response.
  • keble_keepa.testing also exports KEEPA_LIVE_CANARY_CASES: one reviewed minimum-cost live case per Keepa task group (product, category, brand-seller, account). The whole matrix costs three billed tokens plus the free capacity read. Consumers such as the Keble connector import these typed values instead of copying ASINs, terms, or seller ids.

Testing

uv sync --group test
RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 RUN_DB_STACK=1 \
  uv run pytest -q -m "not live and not container"
uv run pytest -q -m "not live and not slow and not eval and not local_stack and not db_stack and not container"
uv run pytest -q -m eval
npx --yes pyright .

The first command is the local-full Keble development proof and runs Mongo-backed integration tests with isolated cache collections. The second is the portable-offline fallback for no-DB machines. Selecting -m eval is the eval opt-in; there is no generic RUN_EVALS gate.

Use explicit isolated local-full configuration rather than inheriting a Mongo replica-set address that advertises an unreachable hostname:

MONGO_DB_URI='mongodb://localhost:27217/?replicaSet=rs0&directConnection=true' \
MONGO_DB_DATABASE='__keble_keepa__pytest__local' \
REDIS_URI='redis://localhost:6479/13' \
RUN_INTEGRATION=1 RUN_REAL_DB=1 RUN_LOCAL_STACK=1 RUN_DB_STACK=1 \
  uv run pytest -q -m 'not live and not container'

.github/workflows/quality.yml runs the same four gates in CI: the portable-offline lane, an isolated Mongo/Redis local-full lane with an explicit post-run namespace-cleanliness check, Pyright, and uv build plus a clean wheel install. It also fails closed with CI_CREDENTIAL_PREREQUISITE if a private Git dependency is ever added without provisioned read access. CI never spends Keepa tokens: there is no live workflow and every live test is deselected by marker.

Real Keepa calls belong only in marked/env-gated live tests. Package-owned test helpers live under keble_keepa.testing; do not recreate root-level tests/config.py, root test packages, or legacy tests/test_* source folders.

Mongo/Redis/Keepa live settings load explicit process env first, then tests/.env, then the umbrella keble.backend/.env through keble_db.testing.resolve_test_env. Set KEBLE_BACKEND_ENV_FILE=/path/to/.env from unusual worktree or CI layouts. Do not copy backend secrets into this repo.

Live Keepa canaries should make one real provider call against an isolated cache collection. Do not add Keepa response-cache replay to live tests for speed; cache correctness belongs in integration tests with fake/shared fixtures.

Async cache tests receive a process-unique namespaced ExtendedAsyncRedis and delete all owned keys after every test. Keep this isolation when adding new cache consumers; an un-namespaced wrapper is a test and production leak risk.

Change Logs

Historical release notes and long AI change history live under logs/.

Product release metadata

Product.release_date_observation parses Keepa YYYY, YYYYMM, and YYYYMMDD values into a typed interval with retained precision. Consumers must use the interval for recency decisions; they must not invent a month or day for partial dates or substitute offer-history timestamps. original_language_code normalizes Keepa's finite language names to ISO codes and returns None when the source does not declare a recognized language.

Side Effect If Changes

  • Backend report generation, product discovery, keble-keepa-analysis, and AMZ product-report workflows depend on this package for Keepa access.
  • Cache query/index changes can affect production cache repair and live report correctness; verify query shape and cleanup.

Metadata

Release files for keble-keepa 1.5.1

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

Source distribution (sdist)

Source distribution for keble-keepa 1.5.1
File Size Uploaded Provenance Actions
keble_keepa-1.5.1.tar.gz 361.2 kB Without provenance Details for keble_keepa-1.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for keble-keepa 1.5.1
File Interpreter ABI Platform Actions
keble_keepa-1.5.1-py3-none-any.whl Python 3 none any Details for keble_keepa-1.5.1-py3-none-any.whl

Total release size: 509.7 kB

Release files / keble_keepa-1.5.1.tar.gz

Download URL keble_keepa-1.5.1.tar.gz
Size 361.2 kB
Tags Source
SHA-256 checksum
How to use checksums
36c6d3cd2d9522201babbc60858231e77d86761892de4f19d56ebe73f4daf8fe
BLAKE2b-256 checksum
How to use checksums
b0508f6a57dc1d22e325231476ca99f187fc491dddb9d04be5c2dcb5755b68a7
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / keble_keepa-1.5.1-py3-none-any.whl

Download URL keble_keepa-1.5.1-py3-none-any.whl
Size 148.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f1d8d44cb2d7a2a977d0730ff8cb5af5614210b8de1df87e2af134ca3e4754d
BLAKE2b-256 checksum
How to use checksums
c8abee7e5b92a99d5e9e7867e2bc5a2483350b5c9b24bf2dfb1731340bf35e4f
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for keble-keepa 1.5.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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