Open source
Updated Nov 2026 by Mangesh Kashid
A Rust core behind one Python API
I built rusty-agent-sdk so Python callers could get a complete response or read text as it arrives through the same provider interface. I put HTTP and stream handling in Rust and published v0.1.0 to PyPI in February 2026.
Role
SDK design, implementation, and packaging
Duration
First PyPI release: February 2026
What shipped
- 7 Prebuilt wheels in v0.1.0
One provider, two ways to read
The first release exposed two methods on the same Python Provider. I made generate_text return the complete response as a string and stream_text return an iterator over text chunks. The model and endpoint belong to the provider, so changing how a caller reads the reply doesn't require a different client.
I'd use the blocking call when the next step needs the whole answer. I'd use the iterator when the caller can do something with partial text, like writing it to a terminal.
A synchronous call over async HTTP
I used PyO3 to expose the Rust core as a Python extension. For blocking generation, each call creates a Tokio runtime and uses block_on to run the asynchronous HTTP request. A Python script can wait for the string without setting up its own event loop.
That puts runtime setup inside each call. The tradeoff I made was to avoid keeping a long-lived runtime across the Python and Rust boundary. The package declares no Python runtime dependencies, even though the extension uses Rust crates.
A queue with a fixed limit
For streaming, I gave a Rust worker thread its own Tokio runtime. The first release parsed the response line by line. In the repository version, the worker assembles those lines into server-sent events before parsing them. In both versions, the worker hands parsed text chunks to the Python iterator through a channel.
I bounded the channel between the worker and Python. If the caller falls behind and the queue fills, the worker waits before handing off another chunk. That limit applies to the channel, not the entire response or every buffer involved in reading it.
The caller owns the conversation
In the repository version, I let a caller pass a prompt or supply the messages for a conversation. The application decides which turns to send on each request. I exposed JSON mode through response_format as a request to the endpoint, rather than treating the SDK as a validator for the returned text.
I also made usage opt-in. For blocking calls, include_usage gives the caller an object with the text and available response metadata. For streaming calls, the caller can read available token counts after consuming the iterator.
Presets for the connection details
I added three presets in the repository version. OpenAI uses https://api.openai.com/v1 and OPENAI_API_KEY. Anthropic uses https://api.anthropic.com/v1 and ANTHROPIC_API_KEY. OpenRouter uses https://openrouter.ai/api/v1 and OPENROUTER_API_KEY. An explicit key takes precedence. Provider requires a model, defaults to the OpenRouter URL, and accepts a custom OpenAI-compatible base URL.
The presets change how the client connects. They leave the choice between a string and a stream where I put it in the first release, on the method the caller uses.
Retries with a stopping point
I gave request failures a bounded retry policy in the repository version. A rate limit response or some server errors can trigger another attempt. The wait grows between attempts, and there's a stopping point instead of an endless loop.
I exposed the retry settings and timeouts through environment variables so callers can change the defaults without editing their calls. For streaming, the retry loop covers opening the response. It doesn't resume text after a stream has already started.
What I shipped to PyPI
The v0.1.0 wheels cover macOS, Linux and Windows. I used the CPython stable ABI so I could split the builds by platform without shipping a separate wheel for each Python minor version.
I also shipped a source distribution for installs that need to build the extension from source. The repository documents API additions made after this release.
GitHub README · Rust architecture · PyPI v0.1.0 release files