phalt · GitHub

Introducing Clientele API - a different way to think about Python API Clients

  • Clientele API is a decorator-driven http client that can create elegant API integrations.
# api.py
from clientele import api as clientele_api
from .my_models import Book, CreateBookReponse, CreateBookRequest
client = clientele_api.APIClient(base_url="http://localhost:8000")
# Mix sync and async functions in the same client
@client.get("/book/{book_id}")
async def get_book(book_id: int, result: Book) -> Book:
    return result
# Return only what you need from the API
@client.get("/book/{book_id}")
def get_book_title(book_id: int, result: Book) -> str:
    return result.title
# POST, PUT, PATCH, DELETE all supported
@client.post("/books")
def create_user(
    data: CreateBookRequest,
    result: CreateBookReponse,
) -> CreateBookReponse:
    return result
  • Clientele API is considered a beta project for this release. It is an evolving idea that has been tested thoroughly and it works well in ideal conditions. Small changes to the API and usage may occur over time as we encounter unexpected scenarios.

Get started with Clientele API

Generate scaffolding for OpenAPI projects with clientele API

  • The scaffold-api command will produce scaffolding from an OpenAPI schema and uses the new clientele api.
uvx run clientele scaffold-api -u https://raw.githubusercontent.com/PokeAPI/pokeapi/master/openapi.yml -o my_pokeapi_client/

Learn how to scaffold an API integration here

generate_gif

Explore APIs with Clientele API clients

  • The explore command has been updated to support clients that use the clientele api pattern.
# 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!

Explore an API without installing anything

repl demo

Improved documentation

  • New documentation added to cover Clientele API.
  • Documentation sections have been reorganised to reflect the key features of Clientele.

See the new documentation here

2.0.0 deprecation notice

  • When clientele API reaches maturity, support for the current "barebones" style of OpenAPI scaffolders will be deprecated.
  • This will be marked as the 2.0.0 release.

Read the original on github.com ↗