Skip to main content

fasttransport

Install

pip install fasttransport

Why

Every small API wrapper needs the same plumbing: headers merged into each request, responses decoded by content type, errors that carry the response body, and SSE parsing for streams. Most wrappers also repeat the same mistake. They create one httpx client at startup and keep it, which pins its pooled connections to the event loop that created them. Code that later runs under a different loop, common in tests and background tasks, then fails with confusing connection errors.

fasttransport is that plumbing written once, on httpx2. Each request gets a fresh client and nothing is tied to a loop. Pass client= to manage a persistent client yourself. fastspec builds its spec-driven clients on these transports, ghapi its GitHub client, and solveit its gateway clients.

Get started

SyncTransport.request executes a call and returns the decoded body: JSON arrives as a dict, text as text, and anything else as bytes. HTTP errors raise with the response body included in the message.

from fasttransport.core import *
SyncTransport().request('GET', 'https://jsonplaceholder.typicode.com/todos/1')

AsyncTransport is the same, awaited. It also has stream, an async generator that parses SSE events into JSON dicts. The core page streams a chat completion with it.

await AsyncTransport().request('GET', 'https://jsonplaceholder.typicode.com/users/1')

A small REST client is a base URL plus verbs. HttpCli verbs take a path relative to the base, kwargs become the payload (query params on get and delete, the JSON body otherwise), and decoded bodies come back:

cli = HttpCli('https://jsonplaceholder.typicode.com')
cli.get('todos/1')
cli.post('posts', title='hi')

AsyncHttpCli is the async twin. Its verbs return awaitables:

acli = AsyncHttpCli('https://jsonplaceholder.typicode.com')
await acli.get('todos/1')

Errors

A client fails in three ways: an HTTP error status, a transport failure such as a timeout, and an error event arriving mid-stream. fasttransport.errors turns all three into one APIError, carrying the parsed message, provider code, request id, and whether the failure is worth retrying. fastspec, ghapi, and fastllm all raise that one type, so calling code catches it once whatever the provider. The errors page shows each provider’s error shape parsed into it.

The core page documents the rest with runnable examples: SSE streaming, error enrichment, multipart uploads, and managing your own client.

Metadata

Release files for fasttransport 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fasttransport 0.0.2
File Size Uploaded
fasttransport-0.0.2.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fasttransport 0.0.2
File Interpreter ABI Platform
fasttransport-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 26.2 kB

Release files / fasttransport-0.0.2.tar.gz

Download URL fasttransport-0.0.2.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
686ee5d8a54b3145704ced69aeddbc6329076cdc841df0ffff1161f93d36d579
BLAKE2b-256 checksum
How to use checksums
fb2de332a8fd98717cb4c94214c85c1b38890d9399d1c18fef23ddc2c908bf1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / fasttransport-0.0.2-py3-none-any.whl

Download URL fasttransport-0.0.2-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0173bf2d2785da31b940463713d9e90a5d15dc1c9764ff233e7214b321ae150
BLAKE2b-256 checksum
How to use checksums
aaaf4a5ea7ccd96cc5a4547e3a924eaba9a85cf7d78c31de25e32615f7cffb4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.0.4

2 release files

0.0.3

2 release files

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page