Skip to main content

⚜️ Clientele

https://raw.githubusercontent.com/phalt/clientele/refs/heads/main/docs/clientele_header.png

Package version Python versions PyPI - License codecov PyPI Downloads

Pydantic Badge Http Badge

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

See more examples

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.

generate_gif

API Client explorer

Clientele has an explore mode for quickly testing and debugging APIs through an interactive REPL:

# Explore an existing clientele-compatible client
uvx clientele explore -c my_clientele_client/

# Or generate a temporary client from any OpenAPI service on the web
uvx clientele explore -u https://raw.githubusercontent.com/PokeAPI/pokeapi/master/openapi.yml
# 🤫 Pssst! Copy and paste this right now to try it!

repl demo

  • Autocomplete for operations and schemas.
  • Execute API operations to test the API.
  • Inspect schemas to see what the objects look like.
  • Modify configuration within the REPL as you're testing.

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.7.0.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clientele-1.7.0-py3-none-any.whl (119.2 kB view details)

Uploaded Python 3

File details

Details for the file clientele-1.7.0.tar.gz.

File metadata

  • Download URL: clientele-1.7.0.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for clientele-1.7.0.tar.gz
Algorithm Hash digest
SHA256 7b889ff2a5e896a46abe5e853c9dc6c2b0acb17cf1ba001dfa6f1b5a4d10f0eb
MD5 edbc779685c138c7f53db65a14ee73fb
BLAKE2b-256 6b8de07da514b9ec7ad62f3ec98df1c958ef06c96480a24c1472faf27016b12f

See more details on using hashes here.

File details

Details for the file clientele-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: clientele-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 119.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for clientele-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 738c9e1b589f62e1b1022dff92b8f3028474f8aa51f5a392a5529c007da37296
MD5 e2fd7e429353fbc0048a0f30288c5c78
BLAKE2b-256 2d355eaacee005d7ece3ae329b0924b0245cb90fc4d7ae0456b5c62100c3835c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page