Combadge
Combadge generates a service client implementation from a user service interface
declared by a protocol class or an abstract base class.
Documentation
Sneak peek
from httpx import Client
from pydantic import BaseModel, Field
from typing_extensions import Annotated, Protocol
from combadge.support.http.markers import QueryParam, http_method, path
from combadge.support.httpx.backends.sync import HttpxBackend
class CurrentCondition(BaseModel):
humidity: int
temperature: Annotated[float, Field(alias="temp_C")]
class Weather(BaseModel):
current: Annotated[list[CurrentCondition], Field(alias="current_condition")]
class SupportsWttrIn(Protocol):
@http_method("GET")
@path("/{in_}")
def get_weather(
self,
*,
in_: str,
format_: Annotated[str, QueryParam("format")] = "j1",
) -> Weather:
raise NotImplementedError
with HttpxBackend(Client(base_url="https://wttr.in"))[SupportsWttrIn] as service:
response = service.get_weather(in_="amsterdam")
assert response.current[0].humidity == 71
assert response.current[0].temperature == 8.0