# Combadge
Combadge generates a service client implementation from a user service interface
declared by a [protocol](https://peps.python.org/pep-0544/) class or an abstract base class.
[![Checks](https://img.shields.io/github/checks-status/kpn/combadge/main?logo=github)](https://github.com/kpn/combadge/actions/workflows/check.yaml)
[![Coverage](https://codecov.io/gh/kpn/combadge/branch/main/graph/badge.svg?token=ZAqYAaTXwE)](https://codecov.io/gh/kpn/combadge)
![Code style](https://img.shields.io/badge/code%20style-black-000000.svg)
[![Python Version](https://img.shields.io/pypi/pyversions/combadge?logo=python&logoColor=yellow)](https://pypi.org/project/combadge/)
[![License](https://img.shields.io/github/license/kpn/combadge)](LICENSE)
## Documentation
<a href="https://kpn.github.io/combadge/">
<img alt="Documentation" height="30em" src="https://img.shields.io/github/actions/workflow/status/kpn/combadge/docs.yml?label=documentation&logo=github">
</a>
## Sneak peek
```python title="quickstart_httpx.py"
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
# 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):
@http_method("GET")
@path("/{in_}")
def get_weather(
self,
*,
in_: str,
format_: Annotated[str, QueryParam("format")] = "j1",
) -> Weather:
raise NotImplementedError
# 3️⃣ Bind the service:
with HttpxBackend(Client(base_url="https://wttr.in"))[SupportsWttrIn] as service:
# 🚀 Call the service:
response = service.get_weather(in_="amsterdam")
assert response.current[0].humidity == 71
assert response.current[0].temperature == 8.0
```
Raw data
{
"_id": null,
"home_page": "https://github.com/kpn/combadge",
"name": "combadge",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0.0,>=3.9.0",
"maintainer_email": null,
"keywords": "api, api-client, pydantic",
"author": "Pavel Perestoronin",
"author_email": "pavel.perestoronin@kpn.com",
"download_url": "https://files.pythonhosted.org/packages/cc/01/10d5911f0fb04f8f410fabe8b79fb0858ad2a3e2a1fc0c9066be8eed8202/combadge-4.8.1.tar.gz",
"platform": null,
"description": "# Combadge\n\nCombadge generates a service client implementation from a user service interface\ndeclared by a [protocol](https://peps.python.org/pep-0544/) class or an abstract base class.\n\n[![Checks](https://img.shields.io/github/checks-status/kpn/combadge/main?logo=github)](https://github.com/kpn/combadge/actions/workflows/check.yaml)\n[![Coverage](https://codecov.io/gh/kpn/combadge/branch/main/graph/badge.svg?token=ZAqYAaTXwE)](https://codecov.io/gh/kpn/combadge)\n![Code style](https://img.shields.io/badge/code%20style-black-000000.svg)\n[![Python Version](https://img.shields.io/pypi/pyversions/combadge?logo=python&logoColor=yellow)](https://pypi.org/project/combadge/)\n[![License](https://img.shields.io/github/license/kpn/combadge)](LICENSE)\n\n## Documentation\n\n<a href=\"https://kpn.github.io/combadge/\">\n <img alt=\"Documentation\" height=\"30em\" src=\"https://img.shields.io/github/actions/workflow/status/kpn/combadge/docs.yml?label=documentation&logo=github\">\n</a>\n\n## Sneak peek\n\n```python title=\"quickstart_httpx.py\"\nfrom httpx import Client\nfrom pydantic import BaseModel, Field\nfrom typing_extensions import Annotated, Protocol\n\nfrom combadge.support.http.markers import QueryParam, http_method, path\nfrom combadge.support.httpx.backends.sync import HttpxBackend\n\n\n# 1\ufe0f\u20e3 Declare the response models:\nclass CurrentCondition(BaseModel):\n humidity: int\n temperature: Annotated[float, Field(alias=\"temp_C\")]\n\n\nclass Weather(BaseModel):\n current: Annotated[list[CurrentCondition], Field(alias=\"current_condition\")]\n\n\n# 2\ufe0f\u20e3 Declare the protocol:\nclass SupportsWttrIn(Protocol):\n @http_method(\"GET\")\n @path(\"/{in_}\")\n def get_weather(\n self,\n *,\n in_: str,\n format_: Annotated[str, QueryParam(\"format\")] = \"j1\",\n ) -> Weather:\n raise NotImplementedError\n\n\n# 3\ufe0f\u20e3 Bind the service:\nwith HttpxBackend(Client(base_url=\"https://wttr.in\"))[SupportsWttrIn] as service:\n # \ud83d\ude80 Call the service:\n response = service.get_weather(in_=\"amsterdam\")\n\nassert response.current[0].humidity == 71\nassert response.current[0].temperature == 8.0\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Generic API client based on Pydantic",
"version": "4.8.1",
"project_urls": {
"Homepage": "https://github.com/kpn/combadge",
"Repository": "https://github.com/kpn/combadge"
},
"split_keywords": [
"api",
" api-client",
" pydantic"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f0d02cd1bb5f6850a776c756a0953a21b8e4407d2da8fb12c6b7d322c09a7aca",
"md5": "343752d9c8a7e03b1648416595b849ed",
"sha256": "4f398e5b8d5aee2c1963155acff1eeb62066dfa6118f03a1fc97729a916d0282"
},
"downloads": -1,
"filename": "combadge-4.8.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "343752d9c8a7e03b1648416595b849ed",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.9.0",
"size": 39020,
"upload_time": "2024-12-03T12:36:29",
"upload_time_iso_8601": "2024-12-03T12:36:29.618572Z",
"url": "https://files.pythonhosted.org/packages/f0/d0/2cd1bb5f6850a776c756a0953a21b8e4407d2da8fb12c6b7d322c09a7aca/combadge-4.8.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cc0110d5911f0fb04f8f410fabe8b79fb0858ad2a3e2a1fc0c9066be8eed8202",
"md5": "6b5f73f03c46cf2f881ffd83ad14ede4",
"sha256": "ee354b872afbaa3e047b8bb9126bf4a26883cf1275878df20e49e195e3617559"
},
"downloads": -1,
"filename": "combadge-4.8.1.tar.gz",
"has_sig": false,
"md5_digest": "6b5f73f03c46cf2f881ffd83ad14ede4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.9.0",
"size": 25332,
"upload_time": "2024-12-03T12:36:30",
"upload_time_iso_8601": "2024-12-03T12:36:30.603816Z",
"url": "https://files.pythonhosted.org/packages/cc/01/10d5911f0fb04f8f410fabe8b79fb0858ad2a3e2a1fc0c9066be8eed8202/combadge-4.8.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-03 12:36:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kpn",
"github_project": "combadge",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "combadge"
}