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.1
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.1.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| reflowkit-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / reflowkit-0.0.1.tar.gz
| Download URL | reflowkit-0.0.1.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8dfceff1a2cb25d80b92a55b7c892385bda075defa5de441733eaf1569f1dbc8
|
|
BLAKE2b-256 checksum How to use checksums |
68a0bd6342c8d9c77d1e51f7d7eb375b4d796134eb2b2c61f890474ac24c3192
|
| 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.1-py3-none-any.whl
| Download URL | reflowkit-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
554884c4579864e6df78643ebad9cc006270a70427fc771d21a3d54b3fc48161
|
|
BLAKE2b-256 checksum How to use checksums |
35aa618128a307b6cf514fd723d37c34a3c1b67da21bcd8a61598f8365fced8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|