FastClient
A lightweight, dynamic Python client for FastAPI applications that automatically maps API routes into native pythonic methods with seamless Pydantic model deserialization and custom exception propagation.
Features
- Dynamic Route Binding: Converts FastAPI
APIRoutemetadata directly into native client instance methods. - Pydantic Model Deserialization: Parses input request payloads and automatically validates response models.
- Custom Exception Auto-Raising: Captures structured server error payloads (
ErrorDetail) and raises matching custom Python exception classes.
Installation
Install fastclient alongside your FastAPI dependencies:
pip install fastclient
Quickstart
Define Server Models & Custom Exceptions
from fastapi import FastAPI
from pydantic import BaseModel
from fastclient import BaseAPIException, register_exceptions
app = FastAPI()
# Register exception handlers on your FastAPI app
register_exceptions(app)
class User(BaseModel):
id: str
name: str
class UserNotFoundError(BaseAPIException):
status_code = 404
message = "User not found"
@app.get("/users/{user_id}", response_model=User)
def get_user(user_id: str):
if user_id != "1":
raise UserNotFoundError(details={"user_id": user_id})
return User(id="1", name="Alice")
Instantiate and Call FastClient
from fastclient import FastClient
# Connect to a running server or pass the ASGI app directly
client = FastClient(base_url="http://localhost:8000", app=app)
# 1. Successful request returning Pydantic User instance
user = client.get_user(user_id="1")
print(user.name) # Output: "Alice"
# 2. Failed request automatically raising your custom exception
try:
client.get_user(user_id="999")
except UserNotFoundError as err:
print(err.status_code) # Output: 404
print(err.message) # Output: "User not found"
print(err.details) # Output: {'user_id': '999'}
Development & Testing
fastclient uses uv and standard pytest for development and testing.
Install Development Dependencies
uv sync --dev
Run Tests
Execute unit and end-to-end integration tests:
uv run pytest
Author
- Ron Weisenstern - @ronviz
Metadata
Release files for ronviz-fastclient 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ronviz_fastclient-0.1.0.tar.gz | 4.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ronviz_fastclient-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.2 kB
Release files / ronviz_fastclient-0.1.0.tar.gz
| Download URL | ronviz_fastclient-0.1.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1cdf31dd2bfe44b657f6791d1afc2777b3bd6986570f9be2d047931dbf28fec
|
|
BLAKE2b-256 checksum How to use checksums |
f00d6c72a605e46053ae65a7abbe0cc6e82fa66a500ed0c67e689bf7a4f6d80e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / ronviz_fastclient-0.1.0-py3-none-any.whl
| Download URL | ronviz_fastclient-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d03c79061e6b7d431d9cb43a5ce9c0356568f27c62401e1949ad2c95a744aea0
|
|
BLAKE2b-256 checksum How to use checksums |
8f9491cdde15886ceac9a021f857f15d6fa8060010bff98d66465d4988933b60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for ronviz-fastclient 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.