action0-req 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {action0_req-0.1.0 → action0_req-0.2.0}/.github/workflows/ci.yml +9 -9
- {action0_req-0.1.0 → action0_req-0.2.0}/.github/workflows/release.yml +4 -4
- action0_req-0.2.0/CHANGELOG.md +70 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/CLAUDE.md +2 -2
- {action0_req-0.1.0 → action0_req-0.2.0}/PKG-INFO +26 -9
- {action0_req-0.1.0 → action0_req-0.2.0}/README.md +24 -7
- {action0_req-0.1.0 → action0_req-0.2.0}/docs/api.md +2 -1
- action0_req-0.2.0/docs/changelog.md +2 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/docs/index.md +5 -0
- action0_req-0.2.0/docs/usage.md +610 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/pyproject.toml +1 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/src/action0/req/__init__.py +7 -1
- action0_req-0.2.0/src/action0/req/body.py +1628 -0
- action0_req-0.2.0/src/action0/req/response.py +518 -0
- action0_req-0.2.0/tests/action0/req/test_body.py +2022 -0
- action0_req-0.2.0/tests/action0/req/test_response.py +1051 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/uv.lock +106 -1
- action0_req-0.1.0/docs/usage.md +0 -355
- action0_req-0.1.0/src/action0/req/body.py +0 -396
- action0_req-0.1.0/src/action0/req/response.py +0 -248
- action0_req-0.1.0/tests/action0/req/test_body.py +0 -234
- action0_req-0.1.0/tests/action0/req/test_response.py +0 -269
- {action0_req-0.1.0 → action0_req-0.2.0}/.gitignore +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/.python-version +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/LICENSE +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/docs/conf.py +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/src/action0/req/headers.py +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/src/action0/req/py.typed +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/src/action0/req/request.py +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/src/action0/req/status.py +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/tests/action0/req/test_headers.py +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/tests/action0/req/test_init.py +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/tests/action0/req/test_request.py +0 -0
- {action0_req-0.1.0 → action0_req-0.2.0}/tests/action0/req/test_status.py +0 -0
|
@@ -19,19 +19,19 @@ jobs:
|
|
|
19
19
|
strategy:
|
|
20
20
|
fail-fast: false
|
|
21
21
|
matrix:
|
|
22
|
-
python-version: ["3.11", "3.12", "3.13", "3.14"]
|
|
22
|
+
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
|
|
23
23
|
experimental: [false]
|
|
24
24
|
include:
|
|
25
|
-
# 3.
|
|
25
|
+
# 3.16 is still a pre-release: run it, but don't fail the whole
|
|
26
26
|
# workflow while parts of the toolchain don't support it yet
|
|
27
|
-
- python-version: "3.
|
|
27
|
+
- python-version: "3.16"
|
|
28
28
|
experimental: true
|
|
29
29
|
|
|
30
30
|
steps:
|
|
31
|
-
- uses: actions/checkout@
|
|
31
|
+
- uses: actions/checkout@v7
|
|
32
32
|
|
|
33
33
|
- name: Install uv
|
|
34
|
-
uses: astral-sh/setup-uv@
|
|
34
|
+
uses: astral-sh/setup-uv@v10.0.1
|
|
35
35
|
with:
|
|
36
36
|
python-version: ${{ matrix.python-version }}
|
|
37
37
|
|
|
@@ -60,10 +60,10 @@ jobs:
|
|
|
60
60
|
name: docs build
|
|
61
61
|
runs-on: ubuntu-latest
|
|
62
62
|
steps:
|
|
63
|
-
- uses: actions/checkout@
|
|
63
|
+
- uses: actions/checkout@v7
|
|
64
64
|
|
|
65
65
|
- name: Install uv
|
|
66
|
-
uses: astral-sh/setup-uv@
|
|
66
|
+
uses: astral-sh/setup-uv@v10.0.1
|
|
67
67
|
|
|
68
68
|
- name: Install dependencies
|
|
69
69
|
run: uv sync --locked --group docs
|
|
@@ -72,7 +72,7 @@ jobs:
|
|
|
72
72
|
run: uv run --group docs sphinx-build -W --keep-going -b html docs docs/_build/html
|
|
73
73
|
|
|
74
74
|
- name: Upload pages artifact
|
|
75
|
-
uses: actions/upload-pages-artifact@
|
|
75
|
+
uses: actions/upload-pages-artifact@v5
|
|
76
76
|
with:
|
|
77
77
|
path: docs/_build/html
|
|
78
78
|
|
|
@@ -96,4 +96,4 @@ jobs:
|
|
|
96
96
|
steps:
|
|
97
97
|
- name: Deploy to GitHub Pages
|
|
98
98
|
id: deployment
|
|
99
|
-
uses: actions/deploy-pages@
|
|
99
|
+
uses: actions/deploy-pages@v5
|
|
@@ -9,10 +9,10 @@ jobs:
|
|
|
9
9
|
name: check and build
|
|
10
10
|
runs-on: ubuntu-latest
|
|
11
11
|
steps:
|
|
12
|
-
- uses: actions/checkout@
|
|
12
|
+
- uses: actions/checkout@v7
|
|
13
13
|
|
|
14
14
|
- name: Install uv
|
|
15
|
-
uses: astral-sh/setup-uv@
|
|
15
|
+
uses: astral-sh/setup-uv@v10.0.1
|
|
16
16
|
|
|
17
17
|
- name: Install dependencies
|
|
18
18
|
run: uv sync --locked
|
|
@@ -37,7 +37,7 @@ jobs:
|
|
|
37
37
|
- name: Build sdist and wheel
|
|
38
38
|
run: uv build
|
|
39
39
|
|
|
40
|
-
- uses: actions/upload-artifact@
|
|
40
|
+
- uses: actions/upload-artifact@v7
|
|
41
41
|
with:
|
|
42
42
|
name: dist
|
|
43
43
|
path: dist/
|
|
@@ -53,7 +53,7 @@ jobs:
|
|
|
53
53
|
# OIDC token for PyPI trusted publishing
|
|
54
54
|
id-token: write
|
|
55
55
|
steps:
|
|
56
|
-
- uses: actions/download-artifact@
|
|
56
|
+
- uses: actions/download-artifact@v8
|
|
57
57
|
with:
|
|
58
58
|
name: dist
|
|
59
59
|
path: dist/
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to action0-req are listed here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the version
|
|
5
|
+
numbers follow [Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## 0.2.0 — 2026-11-26
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `SpooledBody`: a body producer that is written first and read
|
|
12
|
+
afterwards. It keeps the data in memory up to `max_memory` bytes and
|
|
13
|
+
moves it to an anonymous temporary file beyond that. It is re-readable,
|
|
14
|
+
also by several consumers at once, offers read-only, seekable file
|
|
15
|
+
views via `file()`, and is removed deterministically by `close()` or a
|
|
16
|
+
`with` block. `awrite()`, `achunks()` and `aclose()` do their file I/O
|
|
17
|
+
in a worker thread.
|
|
18
|
+
- `Response.body_file()`: the response body as a seekable binary file
|
|
19
|
+
object, whatever form the body has. A streamed body is spooled, and
|
|
20
|
+
the stream closed; a `FileBody` hands out its file without a copy
|
|
21
|
+
(`FileBody.close()` closes a file opened for that).
|
|
22
|
+
- `Response.save_body()` and `Response.asave_body()`, plus the functions
|
|
23
|
+
`save_body()` and `asave_body()`: copy a body into a path or an open
|
|
24
|
+
file object chunk by chunk, with `append=True` for resumed downloads.
|
|
25
|
+
A path is opened only once the body has delivered its first chunk, so
|
|
26
|
+
a body that cannot be read leaves an existing file untouched. A write
|
|
27
|
+
that fails closes the stream.
|
|
28
|
+
- `Response.close()` and `Response.aclose()`; a response is now a sync
|
|
29
|
+
and async context manager. They release what the body holds and do
|
|
30
|
+
nothing for in-memory bodies. When a `with` block is left by an
|
|
31
|
+
exception, a failure to close is attached to that exception as a note
|
|
32
|
+
instead of replacing it.
|
|
33
|
+
- `IterableBody(..., close=...)` and `AsyncIterableBody(..., aclose=...)`:
|
|
34
|
+
a callback releasing the resource behind the stream. It runs exactly
|
|
35
|
+
once: after the body has been consumed, when a consumer stops early,
|
|
36
|
+
or on `close()` / `aclose()`. Both classes are context managers.
|
|
37
|
+
Closing also closes a generator behind the body, so one that was read
|
|
38
|
+
in part runs its `finally` blocks right away.
|
|
39
|
+
`AsyncIterableBody.close()` is the synchronous counterpart for a body
|
|
40
|
+
with nothing left to release; it raises while the callback is pending.
|
|
41
|
+
- trio support for asynchronous file I/O: `FileBody.achunks()` and the
|
|
42
|
+
new asynchronous file operations use trio's thread pool when running
|
|
43
|
+
below trio. Before, `FileBody.achunks()` worked on asyncio only.
|
|
44
|
+
Cleanup — closing a file, writing out what has arrived — also runs
|
|
45
|
+
when the task has been cancelled.
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
- `FileBody.achunks()` no longer leaves the file it opened unclosed when
|
|
50
|
+
the consuming task is cancelled: the close also runs when the task is
|
|
51
|
+
cancelled repeatedly, as anyio does on a timeout.
|
|
52
|
+
- `FileBody.achunks()` on asyncio: a cancelled read of a regular file or
|
|
53
|
+
a seekable file object is finished before the cancellation is passed
|
|
54
|
+
on, so it no longer moves the file position under the next reader. A
|
|
55
|
+
source that may block for good (a named pipe, a device, a non-seekable
|
|
56
|
+
file object) is still left behind at once — now in a daemon thread of
|
|
57
|
+
its own, which neither occupies the loop's thread pool nor delays its
|
|
58
|
+
shutdown, and which closes the file it opened.
|
|
59
|
+
|
|
60
|
+
## 0.1.1 — 2026-08-08
|
|
61
|
+
|
|
62
|
+
### Changed
|
|
63
|
+
|
|
64
|
+
- Installation instructions: the package is published on PyPI.
|
|
65
|
+
|
|
66
|
+
## 0.1.0 — 2026-08-08
|
|
67
|
+
|
|
68
|
+
First release: the `Header`, `Status` and `Method` constants, `Headers`,
|
|
69
|
+
`Request`, `Response` and the `BodyProducer` protocol with `BytesBody`,
|
|
70
|
+
`FileBody`, `IterableBody` and `AsyncIterableBody`.
|
|
@@ -44,8 +44,8 @@ The package is being built up module by module under `src/action0/req/`. Planned
|
|
|
44
44
|
- `headers.py` — `Headers`: ordered, case-insensitive, multi-value aware mapping of header fields, internally a `list[tuple[str, str]]` of lines preserving the representation (order and casing) exactly. The `MutableMapping` view is single-value (last line per field, like `Params`); `get_all()`/`get_values()` (RFC 9110 comma-splitting)/`add()`/`set()`/`remove()`/`update()`/`as_lines()`/`as_dict()`/`as_str()` handle multiple lines. No underscore→dash normalization (header smuggling footgun). `__eq__` ignores field order and name casing but respects per-field line order; `repr()`/`str()` redact the values of `Headers.secret_names` with `***` — only the wire rendering `as_str()` keeps them. Also `Header`: `StrEnum` of the IANA HTTP field name registry (permanent + deprecated + provisional registrations, generated from the registry CSV on 2026-08-07) plus a block of unregistered de-facto `X-…` names.
|
|
45
45
|
- `status.py` — `Status`: custom `IntEnum` of the IANA status code registry with `phrase` and `is_informational`/`is_success`/`is_redirection`/`is_client_error`/`is_server_error` properties. Deliberately not `http.HTTPStatus`: the stdlib's code list and category properties vary across 3.11–3.15. Two pre-RFC-9110 aliases (`PAYLOAD_TOO_LARGE`, `UNPROCESSABLE_ENTITY`).
|
|
46
46
|
- `request.py` — `Method`: `StrEnum` of the RFC 9110 verbs + `PATCH` + `QUERY`. `Request`: method (uppercased str), `url` (`action0.url.Url` — copied on ingestion, `query=` kwarg replaces the URL's query like the `Url` constructor), `headers` (`Headers`), `body` (`bytes | str | BodyProducer | None`, stored as set), `http_version` and a `meta` dict (application metadata: never on the wire, excluded from `__eq__`, shallow-copied by `copy()`; the constructor copies the given mapping) as plain attributes. Typed body accessors `body_bytes()`/`body_str()`/`body_producer()` convert between the three forms using the Content-Type charset (default utf-8). `copy(**overrides)` (own `Url`/`Headers`; a `BodyProducer` body is shared), part-wise `__eq__` (body compared as set), `repr()` redacts via `Url.__repr__` and omits headers/body, `as_str(include_body=False, separator="\r\n")` renders the wire format with origin-form target and derived `Host` (secrets included; a `BodyProducer` is never consumed — placeholder).
|
|
47
|
-
- `body.py` — `BodyProducer`: runtime-checkable `Protocol` for streaming bodies: `content_length()` (`None` = unknown), sync `chunks()`, async `achunks()`, `as_bytes()`. Implementations: `BytesBody` (in-memory, single chunk), `FileBody` (path or open binary file object + `chunk_size`; paths open freshly per iteration → re-iterable, seekable file objects are rewound per iteration and never closed, non-seekable ones are single-use with unknown length; `achunks()` does all file ops via `asyncio.to_thread`), `IterableBody` (wraps `Iterable[bytes]`, unknown length, generator sources single-use), `AsyncIterableBody` (wraps `AsyncIterable[bytes]`, async-only: sync `chunks()`/`as_bytes()` raise `RuntimeError`). Also the `BodyTypes` alias and the private conversion helpers (`_charset`, `_body_bytes`/`_body_str`/`_body_producer`, `_rendered_body`) shared by `Request` and `Response` — the classes keep their own thin, documented accessor methods.
|
|
48
|
-
- `response.py` — `Response`: `status` (any int; `Status` members welcome), `headers`, `body`, `reason` (server-sent phrase; the `phrase` property falls back to the `Status` registry, `""` for unknown codes), `http_version`, an optional `request` back-reference (metadata: shared, not copied, excluded from `__eq__`) and a `meta` dict like `Request`'s. Category properties (`is_success`, …) computed from the numeric range so unregistered codes work. Same body accessors as `Request
|
|
47
|
+
- `body.py` — `BodyProducer`: runtime-checkable `Protocol` for streaming bodies: `content_length()` (`None` = unknown), sync `chunks()`, async `achunks()`, `as_bytes()`. Implementations: `BytesBody` (in-memory, single chunk), `FileBody` (path or open binary file object + `chunk_size`; paths open freshly per iteration → re-iterable, seekable file objects are rewound per iteration and never closed, non-seekable ones are single-use with unknown length; `achunks()` does all file ops in a worker thread via the private `_in_thread` helper: `asyncio.to_thread`, or — when there is no running asyncio loop but `trio` is in `sys.modules` — `trio.to_thread.run_sync`; trio is never imported — it is a dev dependency for the tests only. Three dispatch variants: `_in_thread` never abandons a started call — on asyncio it waits for it through cancellations and re-raises afterwards (the result is lost then, so code opening a file in a thread records the handle itself); `_in_thread_shielded`, for cleanup (closing a file, the final flush), on trio also starts in a scope that is cancelled already; `_in_thread_abandonable` leaves the thread behind on cancellation — on asyncio a daemon thread of its own (`_in_daemon_thread`) instead of the loop's pool, on trio `abandon_on_cancel` (`cancellable` before 0.23). `FileBody.achunks()` uses it only for what may block for good: a path that is not a regular file (open and reads; the private `_OwnedFile` lets the abandoned call close the file) and a non-seekable file object. Regular files and seekable file objects are read with `_in_thread`, so a cancelled read never moves the position under the next reader. For `Response.body_file()` a `FileBody` hands out its seekable file via the private `_file_view()`: the given file object, or for the path of a regular file a newly opened file per call, tracked and closed by its public `close()`; `None` (→ spooled) for non-seekable/non-regular sources and for subclasses overriding `chunks()`/`achunks()`/`as_bytes()`), `IterableBody` (wraps `Iterable[bytes]`, unknown length, generator sources single-use; optional `close=` callback run exactly once — after consumption, on abandoned iteration or on `close()` — because a never-started generator's `finally` does not run; `close()` also closes a generator source — generators only, other iterables with a `close()` are left alone, and not a generator that is running right now: then the callback is what releases, and without one `close()` raises `RuntimeError`), `AsyncIterableBody` (wraps `AsyncIterable[bytes]`, async-only: sync `chunks()`/`as_bytes()` raise `RuntimeError`; `aclose=` callback/`aclose()` as the async twin; `aclose()` also closes an async generator source unless another task is running in it (then as in `IterableBody`: callback, or `RuntimeError` without one); the sync `close()` is a no-op unless the callback is still pending or a started async generator is still open — then it raises `RuntimeError`), `SpooledBody` (written first, read afterwards: a `SpooledTemporaryFile` with its automatic rollover turned off — the class rolls over itself once `max_memory` is exceeded, so `awrite()` can stay inline while in memory and move the rollover and all later writes into a worker thread; the private `_Spool` subclass tracks the rollover and refuses one on a closed spool; every reader has a position of its own — `chunks()`/`achunks()` track an offset, `file()` returns a new read-only `io.BufferedReader` over the private `_SpoolView` per call (closing it leaves the body alone, no `fileno()`) — and a lock makes each seek+read/write on the one file object a single step, so overlapping readers are safe (`achunks()` reads inline only via the non-waiting `_read_inline`, never blocking the loop on the lock; a reader ends where the data ends, so a body is to be read once complete); `close()`/`aclose()`/context managers remove the temp file). `close()`/`aclose()` are deliberately NOT part of the `BodyProducer` protocol (duck-typed by `Response.close()`), so third-party producers stay valid. `save_body()`/`asave_body()` copy a body into a path (`append=` for Range-resumed downloads) or file object — a path is opened only after the body's first chunk, so an unreadable body leaves the file untouched, and `_write_all` completes the short writes of a raw target (`None` from an `io.RawIOBase` is non-blocking "nothing written" → `BlockingIOError`; from any other file-like it counts as written); a generator of chunks is closed on the way out, so a failed write does not leave the stream half-read; the async one opens the file and writes the first chunk in one thread call, batches small chunks to 64 KiB per thread hop (the batch is taken over inside the thread, so a flush trio refuses to start loses nothing) and flushes what has arrived when the stream breaks off. Also the `BodyTypes` alias and the private conversion helpers (`_charset`, `_body_bytes`/`_body_str`/`_body_producer`, `_rendered_body`) shared by `Request` and `Response` — the classes keep their own thin, documented accessor methods.
|
|
48
|
+
- `response.py` — `Response`: `status` (any int; `Status` members welcome), `headers`, `body`, `reason` (server-sent phrase; the `phrase` property falls back to the `Status` registry, `""` for unknown codes), `http_version`, an optional `request` back-reference (metadata: shared, not copied, excluded from `__eq__`) and a `meta` dict like `Request`'s. Category properties (`is_success`, …) computed from the numeric range so unregistered codes work. Same body accessors as `Request`, plus the response-only `body_file()` (seekable file view; a streamed body is spooled and the `SpooledBody` REPLACES `body` so the response stays readable and closable; the replaced producer is closed. A producer with only `aclose()` is replaced by the private `_SpooledStream`, which carries that `aclose()` along. A `FileBody` is not copied and not replaced where it can hand out a seekable file itself (see `_file_view()`); otherwise it is spooled. A `SpooledBody` hands out a new read-only view per call), `save_body()`/`asave_body()` and `close()`/`aclose()` + sync/async context manager (release the body's connection or temp file; no-ops for in-memory bodies; `close()` raises `RuntimeError` for a body that only an awaited `aclose()` can release — the body's own `close()` raises it, or it has none; `__exit__`/`__aexit__` with an exception in flight attach any `Exception` from closing to it as a note instead of replacing it). Picklable with an in-memory body (pinned by a test — out-of-process caches rely on it). `copy(**overrides)`, `as_str(include_body, separator)` with status line, redacting-by-omission `repr()` (`Response(404 Not Found)`).
|
|
49
49
|
|
|
50
50
|
Conventions:
|
|
51
51
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: action0-req
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Library for representing, creating and manipulating HTTP requests and responses
|
|
5
5
|
Project-URL: Homepage, https://github.com/LaughInJar/action0-req
|
|
6
6
|
Project-URL: Documentation, https://laughinjar.github.io/action0-req/
|
|
@@ -44,7 +44,15 @@ Full documentation including the API reference:
|
|
|
44
44
|
**Status:** the core API is complete — the header name, status code and
|
|
45
45
|
method constants, the `Headers` mapping, `Request` and `Response`, and
|
|
46
46
|
sync/async body streaming via `BodyProducer` (`BytesBody`, `FileBody`,
|
|
47
|
-
`IterableBody`, `AsyncIterableBody`).
|
|
47
|
+
`IterableBody`, `AsyncIterableBody`, `SpooledBody`). Changes per release
|
|
48
|
+
are listed in the [changelog](https://laughinjar.github.io/action0-req/changelog.html).
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```shell
|
|
54
|
+
pip install action0-req # or uv add action0-req
|
|
55
|
+
```
|
|
48
56
|
|
|
49
57
|
## Usage
|
|
50
58
|
|
|
@@ -115,12 +123,21 @@ print(resp.as_str(separator="\n")) # "\r\n" by default
|
|
|
115
123
|
# Content-Type: text/plain
|
|
116
124
|
```
|
|
117
125
|
|
|
118
|
-
|
|
126
|
+
A response body can also be read as a seekable file object and copied
|
|
127
|
+
into a file, and a response releases what its body holds (a connection,
|
|
128
|
+
a temporary file) when closed:
|
|
119
129
|
|
|
120
|
-
|
|
130
|
+
```python
|
|
131
|
+
import gzip
|
|
121
132
|
|
|
122
|
-
|
|
123
|
-
|
|
133
|
+
from action0.req import IterableBody, Response
|
|
134
|
+
|
|
135
|
+
compressed = gzip.compress(b"a large report")
|
|
136
|
+
with Response(200, body=IterableBody([compressed[:8], compressed[8:]])) as resp:
|
|
137
|
+
# a streamed body is spooled: in memory up to 1 MiB, in a temporary file beyond
|
|
138
|
+
print(gzip.GzipFile(fileobj=resp.body_file()).read()) # b'a large report'
|
|
139
|
+
written = resp.save_body("report.gz") # a path or an open binary file
|
|
140
|
+
print(written == len(compressed)) # True
|
|
124
141
|
```
|
|
125
142
|
|
|
126
143
|
## Development
|
|
@@ -147,8 +164,8 @@ matches `__version__`, builds sdist + wheel and publishes to PyPI via
|
|
|
147
164
|
trusted publishing:
|
|
148
165
|
|
|
149
166
|
```shell
|
|
150
|
-
git tag
|
|
151
|
-
git push origin
|
|
167
|
+
git tag vX.Y.Z
|
|
168
|
+
git push origin vX.Y.Z
|
|
152
169
|
```
|
|
153
170
|
|
|
154
171
|
## AI-assisted development
|
|
@@ -16,7 +16,15 @@ Full documentation including the API reference:
|
|
|
16
16
|
**Status:** the core API is complete — the header name, status code and
|
|
17
17
|
method constants, the `Headers` mapping, `Request` and `Response`, and
|
|
18
18
|
sync/async body streaming via `BodyProducer` (`BytesBody`, `FileBody`,
|
|
19
|
-
`IterableBody`, `AsyncIterableBody`).
|
|
19
|
+
`IterableBody`, `AsyncIterableBody`, `SpooledBody`). Changes per release
|
|
20
|
+
are listed in the [changelog](https://laughinjar.github.io/action0-req/changelog.html).
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
pip install action0-req # or uv add action0-req
|
|
27
|
+
```
|
|
20
28
|
|
|
21
29
|
## Usage
|
|
22
30
|
|
|
@@ -87,12 +95,21 @@ print(resp.as_str(separator="\n")) # "\r\n" by default
|
|
|
87
95
|
# Content-Type: text/plain
|
|
88
96
|
```
|
|
89
97
|
|
|
90
|
-
|
|
98
|
+
A response body can also be read as a seekable file object and copied
|
|
99
|
+
into a file, and a response releases what its body holds (a connection,
|
|
100
|
+
a temporary file) when closed:
|
|
91
101
|
|
|
92
|
-
|
|
102
|
+
```python
|
|
103
|
+
import gzip
|
|
93
104
|
|
|
94
|
-
|
|
95
|
-
|
|
105
|
+
from action0.req import IterableBody, Response
|
|
106
|
+
|
|
107
|
+
compressed = gzip.compress(b"a large report")
|
|
108
|
+
with Response(200, body=IterableBody([compressed[:8], compressed[8:]])) as resp:
|
|
109
|
+
# a streamed body is spooled: in memory up to 1 MiB, in a temporary file beyond
|
|
110
|
+
print(gzip.GzipFile(fileobj=resp.body_file()).read()) # b'a large report'
|
|
111
|
+
written = resp.save_body("report.gz") # a path or an open binary file
|
|
112
|
+
print(written == len(compressed)) # True
|
|
96
113
|
```
|
|
97
114
|
|
|
98
115
|
## Development
|
|
@@ -119,8 +136,8 @@ matches `__version__`, builds sdist + wheel and publishes to PyPI via
|
|
|
119
136
|
trusted publishing:
|
|
120
137
|
|
|
121
138
|
```shell
|
|
122
|
-
git tag
|
|
123
|
-
git push origin
|
|
139
|
+
git tag vX.Y.Z
|
|
140
|
+
git push origin vX.Y.Z
|
|
124
141
|
```
|
|
125
142
|
|
|
126
143
|
## AI-assisted development
|
|
@@ -4,7 +4,8 @@ The public constants and classes are importable from the package root:
|
|
|
4
4
|
|
|
5
5
|
```python
|
|
6
6
|
from action0.req import Header, Headers, Method, Request, Response, Status
|
|
7
|
-
from action0.req import BodyProducer, BytesBody
|
|
7
|
+
from action0.req import BodyProducer, BytesBody, FileBody, IterableBody, AsyncIterableBody
|
|
8
|
+
from action0.req import SpooledBody, save_body, asave_body
|
|
8
9
|
```
|
|
9
10
|
|
|
10
11
|
## Headers and Header
|
|
@@ -31,6 +31,10 @@ uv add action0-req # not on PyPI yet — install from GitHub for now
|
|
|
31
31
|
{py:class}`~action0.req.body.BodyProducer` protocol — sync and async
|
|
32
32
|
(without blocking the event loop), with in-memory, file-backed and
|
|
33
33
|
(async-)iterable-backed producers.
|
|
34
|
+
- Response bodies as files: spooled to a temporary file while they
|
|
35
|
+
arrive ({py:class}`~action0.req.body.SpooledBody`), read through a
|
|
36
|
+
seekable file object, saved to a path — and released
|
|
37
|
+
deterministically with `close()` or a `with` block.
|
|
34
38
|
- Fully typed (checked with mypy strict, pyright and ty), Python 3.11+,
|
|
35
39
|
no runtime dependencies beyond `action0-url`.
|
|
36
40
|
|
|
@@ -42,4 +46,5 @@ personal projects.
|
|
|
42
46
|
|
|
43
47
|
usage
|
|
44
48
|
api
|
|
49
|
+
changelog
|
|
45
50
|
```
|