# AiotraQ
Async ready traQ API Client for Python
[![PyPI - Version](https://img.shields.io/pypi/v/aiotraq)](https://pypi.org/project/aiotraq/)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/toshi-pono/aiotraq/blob/main/LICENSE)
[![CI](https://github.com/toshi-pono/aiotraq/actions/workflows/ci.yml/badge.svg)](https://github.com/toshi-pono/aiotraq/actions/workflows/ci.yml)
## Installation
```bash
pip install aiotraq
```
## Usage
`AuthenticatedClient`を用いて API クライアントを作成し API を叩くことができます。
```python
import os
from aiotraq import AuthenticatedClient
from aiotraq.api.channel import get_channels
BOT_ACCESS_TOKEN = os.getenv("BOT_ACCESS_TOKEN")
assert BOT_ACCESS_TOKEN is not None
client = AuthenticatedClient(base_url="https://q.trap.jp/api/v3", token=BOT_ACCESS_TOKEN)
with client as client:
channels = get_channels.sync_detailed(client=client)
print(channels.status_code)
```
API の利用例: チャンネル一覧の取得
```python
with client as client:
channels: ChannelList = get_channels.sync(client=client)
# status_code などの情報も利用したい場合
response: Response[ChannelList] = get_channels.sync_detailed(client=client)
```
非同期版も利用可能です:
```python
with client as client:
channels: ChannelList = await get_channels.asyncio(client=client)
response: Response[ChannelList] = await get_channels.asyncio_detailed(client=client)
```
## Advanced customizations
By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
```python
client = AuthenticatedClient(
base_url="https://internal_api.example.com",
token="SuperSecretToken",
verify_ssl="/path/to/certificate_bundle.pem",
)
```
You can also disable certificate validation altogether, but beware that **this is a security risk**.
```python
client = AuthenticatedClient(
base_url="https://internal_api.example.com",
token="SuperSecretToken",
verify_ssl=False
)
```
Things to know:
1. Every path/method combo becomes a Python module with four functions:
1. `sync`: Blocking request that returns parsed data (if successful) or `None`
1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
1. `asyncio`: Like `sync` but async instead of blocking
1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking
1. All path/query params, and bodies become method arguments.
1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
1. Any endpoint which did not have a tag will be in `aiotraq.api.default`
### Customizing the client
There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case):
```python
from aiotraq 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()
```
You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
```python
import httpx
from aiotraq 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"))
```
## Acknowledgements
This project is generated using [openapi-python-client](https://github.com/openapi-generators/openapi-python-client).
Raw data
{
"_id": null,
"home_page": "https://github.com/toshi-pono/aiotraq",
"name": "aiotraq",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "traQ, API, async, httpx",
"author": "toshi00",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/93/d0/0fb44cc468f154aa1d8c58792de3528f5c0618dd86045cd94a7fca7cf1ef/aiotraq-0.2.4.tar.gz",
"platform": null,
"description": "# AiotraQ\n\nAsync ready traQ API Client for Python\n\n[![PyPI - Version](https://img.shields.io/pypi/v/aiotraq)](https://pypi.org/project/aiotraq/)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/toshi-pono/aiotraq/blob/main/LICENSE)\n[![CI](https://github.com/toshi-pono/aiotraq/actions/workflows/ci.yml/badge.svg)](https://github.com/toshi-pono/aiotraq/actions/workflows/ci.yml)\n\n## Installation\n\n```bash\npip install aiotraq\n```\n\n## Usage\n\n`AuthenticatedClient`\u3092\u7528\u3044\u3066 API \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u4f5c\u6210\u3057 API \u3092\u53e9\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\n\n```python\nimport os\nfrom aiotraq import AuthenticatedClient\nfrom aiotraq.api.channel import get_channels\n\nBOT_ACCESS_TOKEN = os.getenv(\"BOT_ACCESS_TOKEN\")\nassert BOT_ACCESS_TOKEN is not None\n\nclient = AuthenticatedClient(base_url=\"https://q.trap.jp/api/v3\", token=BOT_ACCESS_TOKEN)\n\nwith client as client:\n channels = get_channels.sync_detailed(client=client)\n print(channels.status_code)\n```\n\nAPI \u306e\u5229\u7528\u4f8b: \u30c1\u30e3\u30f3\u30cd\u30eb\u4e00\u89a7\u306e\u53d6\u5f97\n\n```python\nwith client as client:\n channels: ChannelList = get_channels.sync(client=client)\n # status_code \u306a\u3069\u306e\u60c5\u5831\u3082\u5229\u7528\u3057\u305f\u3044\u5834\u5408\n response: Response[ChannelList] = get_channels.sync_detailed(client=client)\n```\n\n\u975e\u540c\u671f\u7248\u3082\u5229\u7528\u53ef\u80fd\u3067\u3059:\n\n```python\nwith client as client:\n channels: ChannelList = await get_channels.asyncio(client=client)\n response: Response[ChannelList] = await get_channels.asyncio_detailed(client=client)\n```\n\n## Advanced customizations\n\nBy default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.\n\n```python\nclient = AuthenticatedClient(\n base_url=\"https://internal_api.example.com\",\n token=\"SuperSecretToken\",\n verify_ssl=\"/path/to/certificate_bundle.pem\",\n)\n```\n\nYou can also disable certificate validation altogether, but beware that **this is a security risk**.\n\n```python\nclient = AuthenticatedClient(\n base_url=\"https://internal_api.example.com\",\n token=\"SuperSecretToken\",\n verify_ssl=False\n)\n```\n\nThings to know:\n\n1. Every path/method combo becomes a Python module with four functions:\n\n 1. `sync`: Blocking request that returns parsed data (if successful) or `None`\n 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.\n 1. `asyncio`: Like `sync` but async instead of blocking\n 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking\n\n1. All path/query params, and bodies become method arguments.\n1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)\n1. Any endpoint which did not have a tag will be in `aiotraq.api.default`\n\n### Customizing the client\n\nThere are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case):\n\n```python\nfrom aiotraq import Client\n\ndef log_request(request):\n print(f\"Request event hook: {request.method} {request.url} - Waiting for response\")\n\ndef log_response(response):\n request = response.request\n print(f\"Response event hook: {request.method} {request.url} - Status {response.status_code}\")\n\nclient = Client(\n base_url=\"https://api.example.com\",\n httpx_args={\"event_hooks\": {\"request\": [log_request], \"response\": [log_response]}},\n)\n\n# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()\n```\n\nYou can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):\n\n```python\nimport httpx\nfrom aiotraq import Client\n\nclient = Client(\n base_url=\"https://api.example.com\",\n)\n# Note that base_url needs to be re-set, as would any shared cookies, headers, etc.\nclient.set_httpx_client(httpx.Client(base_url=\"https://api.example.com\", proxies=\"http://localhost:8030\"))\n```\n\n## Acknowledgements\n\nThis project is generated using [openapi-python-client](https://github.com/openapi-generators/openapi-python-client).\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Async ready traQ API Client",
"version": "0.2.4",
"project_urls": {
"Homepage": "https://github.com/toshi-pono/aiotraq",
"Repository": "https://github.com/toshi-pono/aiotraq",
"Source Code": "https://github.com/toshi-pono/aiotraq/tree/main/libs/aiotraq"
},
"split_keywords": [
"traq",
" api",
" async",
" httpx"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1268c38fd65aefc4b1ec33f7c7eab45c9634911f08b3d2132a5d248bf755305d",
"md5": "6d9a262f6009cb385468ca4da08481a3",
"sha256": "8bc2923eb7f19ca5ddc15e5945718047fdaa50126bbde57c7ab0465a2fbce41c"
},
"downloads": -1,
"filename": "aiotraq-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6d9a262f6009cb385468ca4da08481a3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 319052,
"upload_time": "2024-07-21T17:19:45",
"upload_time_iso_8601": "2024-07-21T17:19:45.484056Z",
"url": "https://files.pythonhosted.org/packages/12/68/c38fd65aefc4b1ec33f7c7eab45c9634911f08b3d2132a5d248bf755305d/aiotraq-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "93d00fb44cc468f154aa1d8c58792de3528f5c0618dd86045cd94a7fca7cf1ef",
"md5": "4ac41fcb539370a1c5841048b03c3a0f",
"sha256": "796d408373710d440a261ec2af1de04bff22b40e9df20183e397b389be526252"
},
"downloads": -1,
"filename": "aiotraq-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "4ac41fcb539370a1c5841048b03c3a0f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 89251,
"upload_time": "2024-07-21T17:19:47",
"upload_time_iso_8601": "2024-07-21T17:19:47.877710Z",
"url": "https://files.pythonhosted.org/packages/93/d0/0fb44cc468f154aa1d8c58792de3528f5c0618dd86045cd94a7fca7cf1ef/aiotraq-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-21 17:19:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "toshi-pono",
"github_project": "aiotraq",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "aiotraq"
}