modkit-api-responses
Small response-envelope and conditional-read helpers. Python 3.12+. The core has no runtime dependencies, imports no application or sibling package, and includes no client SDK.
import json
from modkit_api_responses import ReadRepresentation, conditional_response, success
body = json.dumps(success({"plant": "mint"})).encode()
result = conditional_response(ReadRepresentation(body), method="GET", if_none_match=None)
assert result.status == 200
Presentation
EnvelopeConfig configures distinct data/error/meta keys. success and failure return fresh outer dictionaries, not Pydantic models; nested payload ownership and serialization belong to the caller. Error details default to {}. No implicit contract name, version, catalog, logging, or key-case conversion.
build_meta(base=..., extra=...) omits None extra values and rejects collisions. Explicit unwrap_data unwraps only a plain dictionary with exactly the configured single key. strip_fields recursively removes configured string keys from a plain JSON tree, without mutating it or invoking object stringification. It rejects non-JSON, cycles and nonfinite floats; defaults are depth64 and 10,000 total nodes, configurable. It is not automatic secret detection. Excluded values are also validated/counted.
Conditional reads
Pass final serialized bytes and optional headers through ReadRepresentation, then call conditional_response. Only an existing baseline-200 GET/HEAD representation is supported. Run authentication, authorization, normal errors and earlier applicable RFC preconditions first. A failed If-Match must win; If-Modified-Since is ignored when If-None-Match is present. This package is not a full precondition evaluator or middleware. Unsupported method invocation is ValueError, not an automatic HTTP405 response.
ETags hash exact bytes using SHA256. matches_if_none_match uses weak comparison, supports quoted commas/empty tags/reasonable empty list elements and standalone *. Combine repeated If-None-Match field lines with commas. Malformed fields are ignored in their entirety; resource limits raise ValueError. Defaults: 8192 UTF-8 bytes, 128 tags, configurable positive bounds. Do not silently map limit errors to successful cached responses.
Cache default is no-store; private permits browser storage, public requires explicit opt-in. no-store is not an exemption from conditional304. Vary merges case-insensitively, preserves wildcard and rejects invalid tokens; it is not a privacy boundary. Header names are normalized lowercase; supplied headers snapshot immutably. ETag/Cache-Control replaced, stale length/framing removed, other headers preserved. HEAD and304 body empty, Content-Length omitted. Keep compression/other representation transformations before validation, or have downstream middleware regenerate/remove invalid validators. Streaming/files/ranges are outside scope.
Optional integrations
pip install 'modkit-api-responses[pydantic]' exposes fixed-shape StandardResponse[T], StandardError, StandardErrorResponse in adapters.pydantic. Those model fields are not renamed by EnvelopeConfig.
pip install 'modkit-api-responses[fastapi]' exposes encode_data and to_response in adapters.fastapi. Encode models, explicitly transform/wrap, serialize once, hash the resulting bytes, then return to_response(result). Returning a raw response bypasses framework response-model conversion/filtering; register/document schemas explicitly. Register HEAD explicitly. The adapter never JSON-serializes304 to null and avoids a false zero length on HEAD.
See examples/sample_app.py and migration notes. MIT; copyright notices retained. Version0.1 is an initial API; publication/name availability is not established by this checkout.
Development
python -m pip install -r requirements-dev.txt; python -m pytest; ruff check src tests examples scripts; python -m build; python -m twine check dist/*; python scripts/check_wheel.py dist/<wheel>. The checker tests a fresh venv outside checkout, both core and optional adapters; --core-only omits optional integration tests. CI defines three OSes; configured CI is not evidence of remote execution.
Metadata
Release files for modkit-api-responses 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| modkit_api_responses-0.1.0.tar.gz | 20.0 kB | With provenance | Details for modkit_api_responses-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| modkit_api_responses-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for modkit_api_responses-0.1.0-py3-none-any.whl |
Total release size: 30.7 kB
Release files / modkit_api_responses-0.1.0.tar.gz
| Download URL | modkit_api_responses-0.1.0.tar.gz |
|---|---|
| Size | 20.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
955fb28dfe915deb286721bbf4f6bc196e7f5915b39640a3df2edc7a84533104
|
|
BLAKE2b-256 checksum How to use checksums |
fcb32470c7ebee5bea9f293d6b6ac9fd526606ac44b42fbba2d0e7495251a277
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logRelease files / modkit_api_responses-0.1.0-py3-none-any.whl
| Download URL | modkit_api_responses-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3acdf89034c5de1c2f1db58781c4bbd8e2f4d25f5396237f3a5db2afafd58f0e
|
|
BLAKE2b-256 checksum How to use checksums |
af422e51c8648d74ca705e0a0e8e5b1ab9620c717a62970d3eca58ea14786054
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logSecurity for modkit-api-responses 0.1.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for modkit_api_responses-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logA 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.