Skip to main content

Generic API client based on Pydantic

Project description

combadge

Checks Coverage Code style Python Version License

📻 Application to the service, please respond!

Features

  • Pydantic-based request and response models
  • Automatically derived exception classes
  • Using Protocols to define service classes
  • Built-in backends:
  • Pluggable backends

Documentation

Documentation

🚀 Quick example

from typing import List

from httpx import Client
from pydantic import BaseModel, Field
from typing_extensions import Annotated, Protocol

from combadge.core.binder import bind
from combadge.support.httpx.backends.sync import HttpxBackend
from combadge.support.rest.marks import QueryParam, method, path


# 1️⃣ Declare the response models:
class CurrentCondition(BaseModel):
    humidity: int
    temperature: Annotated[float, Field(alias="temp_C")]


class Weather(BaseModel):
    current: Annotated[List[CurrentCondition], Field(alias="current_condition")]


# 2️⃣ Declare the protocol:
class SupportsWttrIn(Protocol):
    @method("GET")
    @path("/{in_}")
    def get_weather(
        self,
        *,
        in_: str,
        format_: Annotated[str, QueryParam("format")] = "j1",
    ) -> Weather:
        raise NotImplementedError


# 3️⃣ Bind the service:
backend = HttpxBackend(Client(base_url="https://wttr.in"))
service = bind(SupportsWttrIn, backend)

# 🚀 Call the service:
response = service.get_weather(in_="amsterdam")
assert response.current[0].humidity == 71
assert response.current[0].temperature == 8.0

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

combadge-0.1.0.dev3.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

combadge-0.1.0.dev3-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file combadge-0.1.0.dev3.tar.gz.

File metadata

  • Download URL: combadge-0.1.0.dev3.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-1033-azure

File hashes

Hashes for combadge-0.1.0.dev3.tar.gz
Algorithm Hash digest
SHA256 1afb6a26b9cc10449bc06323aacfac3b89b34f63646873ca7b9ebd6b73779edf
MD5 90fa9140da69b0eefcee787c099f00e2
BLAKE2b-256 9156f0f0c3eeec4007ca34d90ed5baaaa1b056d899b09682b1e808e52580d5d0

See more details on using hashes here.

File details

Details for the file combadge-0.1.0.dev3-py3-none-any.whl.

File metadata

  • Download URL: combadge-0.1.0.dev3-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-1033-azure

File hashes

Hashes for combadge-0.1.0.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 68b3496870a2887aae0e20e3e1161f9fa090e222207fd9b24897ced08f786bc7
MD5 60a7023670b225423cd0d6addc81f872
BLAKE2b-256 35eb1c9b17031142b88796dd72e1804fbfad93ba115cbdc55038f19027d07a5c

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 Pingdom Monitoring Sentry Error logging StatusPage Status page