# 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 typing import List
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": "",
"docs_url": null,
"requires_python": ">=3.8.1,<4.0.0",
"maintainer_email": "",
"keywords": "api,api-client,pydantic",
"author": "Pavel Perestoronin",
"author_email": "pavel.perestoronin@kpn.com",
"download_url": "https://files.pythonhosted.org/packages/51/c1/2aca100ed5d00bbd56a1553623cd0ce7300c4bbace8919dc283914c7bbc0/combadge-4.2.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 typing import List\n\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.2.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": "9f59591a9ce124c572510ad1e4ab49b4badeda1bd3f5b9e5fc12b226f4168359",
"md5": "069cbbbb9e42035c2181ac9de9c87e80",
"sha256": "6e44466136694662e0875de6a8bee8677ab25dec2d3c38b7557a2da07cc23781"
},
"downloads": -1,
"filename": "combadge-4.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "069cbbbb9e42035c2181ac9de9c87e80",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.1,<4.0.0",
"size": 37438,
"upload_time": "2024-01-23T15:56:22",
"upload_time_iso_8601": "2024-01-23T15:56:22.499932Z",
"url": "https://files.pythonhosted.org/packages/9f/59/591a9ce124c572510ad1e4ab49b4badeda1bd3f5b9e5fc12b226f4168359/combadge-4.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "51c12aca100ed5d00bbd56a1553623cd0ce7300c4bbace8919dc283914c7bbc0",
"md5": "d7c4d0fefdeda9d994b2d44885e03fd5",
"sha256": "140a4c1fdd2e2ac6ed1cc09a96d891496acd128cac04da0d946ede8e34eec60d"
},
"downloads": -1,
"filename": "combadge-4.2.1.tar.gz",
"has_sig": false,
"md5_digest": "d7c4d0fefdeda9d994b2d44885e03fd5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.1,<4.0.0",
"size": 23981,
"upload_time": "2024-01-23T15:56:24",
"upload_time_iso_8601": "2024-01-23T15:56:24.133805Z",
"url": "https://files.pythonhosted.org/packages/51/c1/2aca100ed5d00bbd56a1553623cd0ce7300c4bbace8919dc283914c7bbc0/combadge-4.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-23 15:56:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kpn",
"github_project": "combadge",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "combadge"
}