omoide-client
Python-клиент для сервера Omoide.
Генерация клиента
Для создания новой версии требуется запущенный экземпляр Omoide.
openapi-python-client generate --url http://127.0.0.1:8080/api/openapi.json --output-path ./omoide_tmp --overwrite
Мне не удалось добиться от утилиты генерации чистого результата, так что я просто предпочитаю
копировать каталог omoide_api_client из того, что было сгенерировано.
Как пользоваться клиентом
Создание экземпляра простого клиента:
from omoide_client import Client
client = Client(base_url='https://api.example.com')
Создание экземпляра клиента с аутентификацией:
from omoide_client import AuthenticatedClient
client = AuthenticatedClient(base_url='https://api.example.com', token='SuperSecretToken')
Использование:
from omoide_client.models import MyDataModel
from omoide_client.api.my_tag import get_my_data_model
from omoide_client.types import Response
with client as client:
my_data: MyDataModel = get_my_data_model.sync(client=client)
response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
То же самое, но асинхронно:
from omoide_client.models import MyDataModel
from omoide_client.api.my_tag import get_my_data_model
from omoide_client.types import Response
async with client as client:
my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
При необходимости использовать отдельный сертификат для SSL.
from omoide_client import AuthenticatedClient
client = AuthenticatedClient(
base_url='https://internal_api.example.com',
token='SuperSecretToken',
verify_ssl='/path/to/certificate_bundle.pem',
)
Можно также отключить проверку сертификата (это небезопасно):
from omoide_client import AuthenticatedClient
client = AuthenticatedClient(
base_url='https://internal_api.example.com',
token='SuperSecretToken',
verify_ssl=False
)
Стоит иметь в виду:
-
Все сочетания путь-метод станут модулями с четырьмя функциями:
sync: Блокирующий запрос, возвращающий ответ илиNone.sync_detailed: Блокирующий запрос, всегда возвращающийRequest(с полемparsedесли он был успешен).asyncio: То же самое, что иsyncтолько неблокирующий.asyncio_detailed: То же самое, что иsync_detailedтолько неблокирующий.
-
Все аргументы пути/тела запроса/строки запроса становятся аргументами метода клиента.
-
Если у ручки были теги, первый тег становится именем модуля для функции клиента.
-
Все ручки без тегов окажутся в модуле
omoide_client.api.default
Расширенная настройка
Объект Client обладает рядом расширенных настроек, которые можно посмотреть в его коде.
Также есть возможность дополнительной настройки нижележащих httpx.Client или httpx.AsyncClient:
from omoide_client import Client
def log_request(request):
print(f'Request event hook: {request.method} {request.url} - Waiting for response')
def log_response(response):
request = response.request
print(f'Response event hook: {request.method} {request.url} - Status {response.status_code}')
client = Client(
base_url='https://api.example.com',
httpx_args={'event_hooks': {'request': [log_request], 'response': [log_response]}},
)
# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
Существует также возможность замены клиента httpx, но это собьёт все настройки:
import httpx
from omoide_client import Client
client = Client(
base_url='https://api.example.com',
)
# Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
client.set_httpx_client(httpx.Client(base_url='https://api.example.com', proxies='http://localhost:8030'))
Публикация клиента
uv build
uv publish --token <token>
Metadata
Release files for omoide-client 0.3.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| omoide_client-0.3.12.tar.gz | 35.3 kB | Without provenance | Details for omoide_client-0.3.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| omoide_client-0.3.12-py3-none-any.whl | Python 3 | none | any | Details for omoide_client-0.3.12-py3-none-any.whl |
Total release size: 143.3 kB
Release files / omoide_client-0.3.12.tar.gz
| Download URL | omoide_client-0.3.12.tar.gz |
|---|---|
| Size | 35.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e16607766bfff8216b4846b76139e25a955cdae3f7e73214510202d646307c19
|
|
BLAKE2b-256 checksum How to use checksums |
09e9e6667bd93c195fa63452fbc5f04ade8c138e24e92d43f7c8ca514ba9217e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.9
|
Release files / omoide_client-0.3.12-py3-none-any.whl
| Download URL | omoide_client-0.3.12-py3-none-any.whl |
|---|---|
| Size | 108.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
179acdaffd1e01d3ad875a785f2c8788bb907d6ef539969593cba6066c5d6a58
|
|
BLAKE2b-256 checksum How to use checksums |
d1c72a5da9fa2ca890a9e305259840f5d2698a2e64b41a94577177a8ed868394
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.9
|
Security for omoide-client 0.3.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.