Clientele is a different way to build Python API Clients
Project description
⚜️ 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 - All the testing tools you need to maintain API integrations.
- Easy to configure - Sensible HTTP defaults and plenty of hooks for customisation.
- Easy data validation - Built in data validation using Pydantic.
- Core built-ins - Caching, Network, and Retry handling built specifically for HTTP.
- Use your own HTTP - Clientele can support any Python HTTP library.
- OpenAPI support - Build your own client, or scaffold one from an OpenAPI schema.
- GraphQL support - Clientele has a GraphQLClient tailored for GraphQL APIs.
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
GraphQL support
from pydantic import BaseModel
from clientele.graphql import GraphQLClient
client = GraphQLClient(base_url="https://api.github.com/graphql")
class Repository(BaseModel):
name: str
stargazerCount: int
class RepositoryQueryData(BaseModel):
repository: Repository
class RepositoryQueryResponse(BaseModel):
data: RepositoryQueryData
@client.query("""
query($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
name
stargazerCount
}
}
""")
def get_repo(owner: str, name: str, result: RepositoryQueryResponse) -> Repository:
return result.data.repository
Works with Python API frameworks
Building an API service in Python? Clientele can build you a client library in seconds.
Clientele is 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file clientele-1.11.0.tar.gz.
File metadata
- Download URL: clientele-1.11.0.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e9130d8a3aae59f82867b215a3eaca43c418c5991574d835ed2a3c497df4f19
|
|
| MD5 |
c758a042bab16dde589a3cdd0b9028d9
|
|
| BLAKE2b-256 |
30d2495e0111aadd2f731f1fedcaebccfca96611452f3b3c649dbfb592916c87
|
File details
Details for the file clientele-1.11.0-py3-none-any.whl.
File metadata
- Download URL: clientele-1.11.0-py3-none-any.whl
- Upload date:
- Size: 89.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be4ef14f2ed3b381b12f20947e6d5969741f9f981b9f7c276b046c7b8e7191de
|
|
| MD5 |
bdac0af2bceb22744c28857672c50af7
|
|
| BLAKE2b-256 |
55e43c4e818ad767d91f8fc762f614be16b335103884af8341eef08dd9e4ee46
|