Metadata-Version: 2.4
Name: pithio-sdk
Version: 0.1.0
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: 3
Requires-Dist: langchain-core>=0.3 ; extra == 'langchain'
Requires-Dist: litellm>=1.50 ; extra == 'litellm'
Requires-Dist: llama-index-core>=0.12 ; extra == 'llamaindex'
Provides-Extra: langchain
Provides-Extra: litellm
Provides-Extra: llamaindex
License-File: LICENSE.md
Summary: Shorter context for AI applications, without losing the answer: local, recoverable, measured.
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# pithio for Python

Shorter context for AI applications, without losing the answer. Runs on your machine; whatever is removed can be
fetched back.

```python
import pithio

r = pithio.compress(document, "Which law governs the agreement?", mode="text", keep=0.5)
print(r.ratio, r.tokens_in, r.tokens_out)   # achieved compression and o200k token counts
print(r.text)                               # the most relevant paragraphs, verbatim; removed parts marked
pithio.more(r.handle)                       # the original, page by page
```

- `mode="text"`: documents and retrieved passages; keeps the paragraphs most relevant to the query.
- `mode="auto"`: detects JSON, CSV, logs, test runs, web pages and prose, and uses the method made for each.
- `compress_messages(messages)`: shortens the tool results inside an OpenAI or Anthropic chat request.

## Agents on the Anthropic or OpenAI SDK: one line

```python
import anthropic, pithio

client = pithio.wrap(anthropic.Anthropic())      # also openai.OpenAI() and the async clients

# in your tool loop, before your own tools:
result = pithio.handle_tool_call(block.name, block.input)
if result is not None:
    ...                                           # send it back as that tool call's result
```

Every `messages.create`, `chat.completions.create` and `responses.create` request has its tool results shortened (the tool call that
produced each is its query); nothing else in the request changes, and the same input always gives the same bytes, so
the provider's prompt cache keeps working. Requests with tools get a `pithio_more` tool through which the model fetches
anything that was removed. Each call's usage and the request's make-up (token counts, never text) go to
`~/.pithio/calls.jsonl`: `pithio diagnose --source api` and the dashboard's Bill tab show where the money goes.
Replies, streamed or not, are returned unchanged. Not covered yet: the SDKs' `messages.stream()` / `responses.stream()` helpers.

Integrations: `pithio.integrations.langchain.PithioCompressor` (a document compressor for retrievers),
`pithio.integrations.llamaindex.PithioNodePostprocessor`, `pithio.integrations.litellm.PithioGuardrail` (a LiteLLM
proxy hook that shortens tool results before each model call).

