Metadata-Version: 2.5
Name: spec2py-runtime
Version: 0.1.0
Summary: Runtime library for spec2py-generated API clients: transport, retries, auth, pagination, streaming and uploads on httpx2 and Pydantic v2.
Project-URL: Homepage, https://github.com/f4hy/spec2py
Author-email: Brendan Fahy <bmfahy@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Typing :: Typed
Requires-Python: >=3.14
Requires-Dist: anyio>=4.6
Requires-Dist: httpx2>=2.13
Requires-Dist: pydantic>=2.12
Description-Content-Type: text/markdown

# spec2py-runtime

The runtime library behind clients generated by
[spec2py](https://github.com/f4hy/spec2py). Generated code only describes
operations; everything that happens at request time lives here, so a fix
arrives with a dependency upgrade instead of a regeneration.

| Area | Behaviour |
| --- | --- |
| Transport | httpx2, with pluggable `transport=` / `http_client=` for tests and custom stacks |
| Retries | Exponential backoff with jitter. Honours `Retry-After`, `retry-after-ms` and `x-should-retry`. Retries idempotent methods, and POSTs once an idempotency key is attached (generated automatically when the API declares an idempotency header). |
| Auth | `ApiKeyAuth` (header, query or cookie), `BearerAuth`, `BasicAuth`, `OAuth2ClientCredentials` (fetch, cache, refresh, retry on 401), `MultiAuth`, or any `httpx2.Auth` |
| Pagination | `CursorPagination`, `OffsetPagination`, `PageNumberPagination`, `LinkHeaderPagination`; `Page` / `AsyncPage` / `AsyncPaginator` iterate lazily and expose `.data` and `.next_cursor` |
| Streaming | SSE and NDJSON decoded into typed events (`Stream`, `AsyncStream`) |
| Uploads | Multipart from file objects, paths, bytes or `(name, content, type)` tuples |
| Errors | `APIError` → `APIStatusError` → `NotFoundError`, `RateLimitError`, ...; bodies parsed into declared models |
| Observability | `Hooks(on_request=..., on_response=...)` |
| Models | `BaseModel` with lenient parsing, `Tolerant` enums, lazy validator builds |

Requires Python 3.14.

## Validation and compatibility

Responses reject missing required fields and invalid field values by default.
Unknown fields are retained and unknown enum values are tolerated. Set
`strict_response_validation=False` explicitly for best-effort parsing; its
results can contain raw values or missing attributes and need defensive handling.
Requests revalidate generated model instances, including nested instances.

The initial generator and generated clients require `spec2py-runtime>=0.1.0,<0.2.0`.
Within the 0.1 series, runtime patch releases preserve the generated-code API.
Breaking runtime changes require a new minor series and regeneration to adopt it.
When emission starts using a new runtime feature, raise the minimum patch version
in both the generator dependency and generated project metadata. Development
snapshots before 0.1.0 are not release candidates for this compatibility range.
