combadge-0.1.0rc6
توضیحات
Generic API client based on Pydantic
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | combadge-0.1.0rc6 |
| نام | combadge |
| نسخه کتابخانه | 0.1.0rc6 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Pavel Perestoronin |
| ایمیل نویسنده | pavel.perestoronin@kpn.com |
| آدرس صفحه اصلی | https://github.com/kpn/combadge |
| آدرس اینترنتی | https://pypi.org/project/combadge/ |
| مجوز | Apache-2.0 |
# 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.
[](https://github.com/kpn/combadge/actions/workflows/check.yaml)
[](https://codecov.io/gh/kpn/combadge)

[](https://pypi.org/project/combadge/)
[](LICENSE)
## Features
- Request and response models based on [**pydantic**](https://docs.pydantic.dev/)
- Declarative services using [`Protocol`](https://peps.python.org/pep-0544/)
- Exception classes automatically derived from error models
- Built-in backends:
- [HTTPX](https://www.python-httpx.org/) – sync and async
- [Zeep](https://docs.python-zeep.org/en/master/) – sync and async
## 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 http import HTTPStatus
from typing import List
from httpx import Client
from pydantic import BaseModel, Field
from typing_extensions import Annotated, Protocol
from combadge.support.http.aliases import StatusCode
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):
status: StatusCode[HTTPStatus]
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.status == HTTPStatus.OK
assert response.current[0].humidity == 71
assert response.current[0].temperature == 8.0
```
نیازمندی
| مقدار | نام |
|---|---|
| >=4.4.0,<5.0.0 | typing-extensions |
| >=1.10.4,<2.0.0 | pydantic |
| >=0.1.2,<0.2.0 | get-annotations |
| >=4.2.1,<5.0.0 | zeep |
| >=0.23.3,<0.24.0 | httpx |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.8.1,<4.0.0 | Python |
نحوه نصب
نصب پکیج whl combadge-0.1.0rc6:
pip install combadge-0.1.0rc6.whl
نصب پکیج tar.gz combadge-0.1.0rc6:
pip install combadge-0.1.0rc6.tar.gz