aiotraq


Nameaiotraq JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/toshi-pono/aiotraq
SummaryAsync ready traQ API Client
upload_time2024-06-02 10:07:51
maintainerNone
docs_urlNone
authortoshi00
requires_python<4.0,>=3.8
licenseMIT
keywords traq api async httpx
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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/d8/cb/e69afe87ecde9e96523ba10b06aa85603c68438d333550cbfa52220f8a9e/aiotraq-0.1.2.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.1.2",
    "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": "5416fadb878a9eb8dc06adbceadc1049e5def7fd925690730b4105c866a9d697",
                "md5": "46e1fac1e2ad614c3278ab0c2f3a6561",
                "sha256": "bf4cc30bd9642f206dcac5369d3a487b102b5cd323036a75ec3e11f7bcac2af9"
            },
            "downloads": -1,
            "filename": "aiotraq-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "46e1fac1e2ad614c3278ab0c2f3a6561",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 317577,
            "upload_time": "2024-06-02T10:07:50",
            "upload_time_iso_8601": "2024-06-02T10:07:50.212813Z",
            "url": "https://files.pythonhosted.org/packages/54/16/fadb878a9eb8dc06adbceadc1049e5def7fd925690730b4105c866a9d697/aiotraq-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d8cbe69afe87ecde9e96523ba10b06aa85603c68438d333550cbfa52220f8a9e",
                "md5": "8e657d24b0a22719aa67b565474d0595",
                "sha256": "32cfbbb5aeee9f6bfff7f8dd81c5249760d14dcc5e56b54e17e963e28c0d6aa2"
            },
            "downloads": -1,
            "filename": "aiotraq-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "8e657d24b0a22719aa67b565474d0595",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 88671,
            "upload_time": "2024-06-02T10:07:51",
            "upload_time_iso_8601": "2024-06-02T10:07:51.936557Z",
            "url": "https://files.pythonhosted.org/packages/d8/cb/e69afe87ecde9e96523ba10b06aa85603c68438d333550cbfa52220f8a9e/aiotraq-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-02 10:07:51",
    "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"
}
        
Elapsed time: 0.25179s