Reflow (Python)
Ported line-for-line from the TypeScript implementation. See the root README for the pitch, the prior-art table, and the scope decisions — this file only covers what's specific to running the Python code.
Install
pip install -e ".[dev]"
Quickstart
PYTHONPATH=src python3 examples/quickstart.py
from reflow import Reflow
async def on_prompt_too_long(messages):
return (await context_clip.recover(messages)).messages
reflow = Reflow(
on_prompt_too_long=on_prompt_too_long,
on_media_too_large=lambda messages: strip_large_images(messages),
on_truncated=lambda messages, attempt: [*messages, continue_message],
max_truncation_retries=2,
)
result = await reflow.call(
lambda messages: anthropic.messages.create(model=model, messages=messages, max_tokens=4096),
initial_messages,
)
# result.value — the response
# result.recoveries — ordered log of what happened, e.g. ["prompt_too_long"]
# result.truncated — True if still truncated after exhausting retries
Test
pytest
Status
Prompt-too-long recovery, media-too-large recovery, and bounded
truncation recovery are real and tested, with default classifiers for
common Anthropic/OpenAI-shaped errors. Not yet published to PyPI — the
bare reflow name is taken by an unrelated abandoned package, so this
publishes as reflowkit instead, same as the TypeScript package.
Release files for reflowkit 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| reflowkit-0.0.2.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| reflowkit-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / reflowkit-0.0.2.tar.gz
| Download URL | reflowkit-0.0.2.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
164ed626af4500a7c5b790affb808924b71f82450c38d5f792ce35a1b8ddb086
|
|
BLAKE2b-256 checksum How to use checksums |
60b4054150c5d61053f65572fa9e9b3fdf6c502f5b1495a75121ade4e8cabbc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|
Release files / reflowkit-0.0.2-py3-none-any.whl
| Download URL | reflowkit-0.0.2-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95f2c5de72b169280aeba5ee8d8db2787d0ea78bd6c981c6c65a6433db42ecf6
|
|
BLAKE2b-256 checksum How to use checksums |
b6e93550e514edd7f9f63e2226332c07a5cf8f883b19e3a75e1551ffc7244b46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|