⚜️ Clientele
Example code
from clientele import api
from pydantic import BaseModel
client = api.APIClient(base_url="https://pokeapi.co/api/v2/")
class Pokemon(BaseModel):
name: str
@client.get("/pokemon/{id}")
def get_pokemon_name(id: int, result: Pokemon) -> str:
return result.name
Why use Clientele?
- A comfortable abstraction - Encourages consistency and focus on the functionality.
- Easy to learn - Clientele is visually similar to popular python API server frameworks.
- Easy to test - Comes with built-in testing tools, and works with existing libraries like respx and pytest-httpx.
- Easy to configure - Clientele has sensible defaults and plenty of hooks for customisation.
- Easy data validation - Built in data validation using Pydantic.
- Use your own HTTP - Clientele can support all HTTP libraries.
- OpenAPI support - Build your own client, or scaffold one from an OpenAPI schema.
Async support
@client.get("/pokemon/{id}")
async def get_pokemon_name(id: int, result: Pokemon) -> str:
return result.name
Automatic data validation
from clientele import api as clientele_api
from .my_pydantic_models import CreateBookRequest, CreateBookResponse
client = clientele_api.APIClient(base_url="http://localhost:8000")
@client.post("/books")
def create_book(data: CreateBookRequest, result: CreateBookResponse) -> CreateBookResponse:
return result
Streaming responses
from typing import AsyncIterator
from clientele import api
from pydantic import BaseModel
client = api.APIClient(base_url="https://httpbin.org")
class Event(BaseModel):
id: int
url: str
@client.get("/stream/{n}", streaming_response=True)
async def stream_events(n: int, result: AsyncIterator[Event]) -> AsyncIterator[Event]:
return result
Direct requests
result = client.request(
"GET",
"pokemon/{pokemon_id}",
response_map={200: Pokemon},
pokemon_id=1
)
Works with Python API frameworks
Built and tested to be 100% compatible with the OpenAPI schemas generated from:
- FastAPI
- Django REST Framework via drf-spectacular
- Django Ninja
See the working demos in our server_examples/ directory.
OpenAPI support
Clientele can create scaffolding for an API client from an OpenAPI schema with:
- Pydantic models generated from the schema objects.
- Decorated function signatures generated from schema operations.
- Async support if you want a client with concurrency.
- A tiny output that is only 3 files big.
- Regeneration-friendly - update your API, regenerate, review the git diff, then ship it!
- Formatted code thanks to Ruff.
Getting Started
👉 Read the full documentation for all documentation.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
clientele-1.8.0.tar.gz
(1.9 MB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
clientele-1.8.0-py3-none-any.whl
(102.6 kB
view details)
File details
Details for the file clientele-1.8.0.tar.gz.
File metadata
- Download URL: clientele-1.8.0.tar.gz
- Upload date:
- Size: 1.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7be641112d9e527fd9092c1ae947fd5f307d7598951c443b4ca3a07b86bcdbab
|
|
| MD5 |
f738a1ffc11476116e7b6852928d70e6
|
|
| BLAKE2b-256 |
f09c02ae37b8a299de5be519f20d398253508745079669e103e2571953ac20e8
|
File details
Details for the file clientele-1.8.0-py3-none-any.whl.
File metadata
- Download URL: clientele-1.8.0-py3-none-any.whl
- Upload date:
- Size: 102.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9c8a28543b0889644e7ff0d433721ceb6d3869e9676568d692c68fa1d6ec83c
|
|
| MD5 |
0c5f2c5ea422e34ad11e2bf8b74af756
|
|
| BLAKE2b-256 |
a873a4bdede1c855d035cb338063a5f4eb1a2f32edb4f67a207942638d7c7b5a
|