asynctor


Nameasynctor JSON
Version 0.8.7 PyPI version JSON
download
home_pageNone
SummaryAsync functions to compare with anyio and asyncio, and toolkit to read excel with async/await.
upload_time2025-08-15 04:03:50
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords asyncio anyio aioredis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # asynctor
![Python Versions](https://img.shields.io/pypi/pyversions/asynctor)
[![LatestVersionInPypi](https://img.shields.io/pypi/v/asynctor.svg?style=flat)](https://pypi.python.org/pypi/asynctor)
[![GithubActionResult](https://github.com/waketzheng/asynctor/workflows/ci/badge.svg)](https://github.com/waketzheng/asynctor/actions?query=workflow:ci)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![Coverage Status](https://coveralls.io/repos/github/waketzheng/asynctor/badge.svg?branch=main)](https://coveralls.io/github/waketzheng/asynctor?branch=main)
![Mypy coverage](https://img.shields.io/badge/mypy-100%25-green.svg)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

Some async functions that using anyio, and toolkit for excel read.

## Installation

<div class="termy">

```console
$ pip install asynctor
---> 100%
Successfully installed asynctor
```
with extras:
```console
pip install "asynctor[xls,redis,fastapi]"
```
Or by pdm:
```bash
pdm add "asynctor[redis]"
```

</div>

## Usage

- Async function that compare asyncio but use anyio: `bulk_gather/gather/run`
```py
>>> import asynctor
>>> async def foo():
...     return 1
...
>>> await asynctor.bulk_gather([foo(), foo()], limit=200)
(1, 1)
>>> await asynctor.gather(foo(), foo())
(1, 1)
>>> asynctor.run(gather(foo(), foo()))
(1, 1)
```
- timeit
```py
>>> import time
>>> import anyio
>>> from asynctor import timeit
>>> @timeit
... async def sleep_test():
...     await anyio.sleep(3)
...
>>> await sleep()
sleep_test Cost: 3.0 seconds

>>> @timeit
... def sleep_test2():
...     time.sleep(3.1)
...
>>> sleep_test2()
sleep_test2 Cost: 3.1 seconds
```
- AioRedis

*pip install "asynctor[redis]"*
```py
from asynctor.contrib.fastapi import AioRedis, register_aioredis
from fastapi import FastAPI

app = FastAPI()
register_aioredis(app)

@app.get('/')
async def root(redis: AioRedis) -> list[str]:
    return await redis.keys()

@app.get('/redis')
async def get_value_from_redis_by_key(redis: AioRedis, key: str) -> str:
    value = await redis.get(key)
    if not value:
        return ''
    return value.decode()
```
- AsyncTestClient
*pip install "asynctor[fastapi]"*
```py
import pytest
from asynctor import AsyncTestClient, AsyncClientGenerator
from httpx import AsyncClient

from main import app

@pytest.fixture(scope='session')
async def client() -> AsyncClientGenerator:
    async with AsyncTestClient(app) as c:
        yield c

@pytest.fixture(scope="session")
def anyio_backend():
    return "asyncio"

@pytest.mark.anyio
async def test_api(client: AsyncClient):
    response = await client.get("/")
    assert response.status_code == 200
```

- Read Excel File(need to install with xls extra: `pip install "asynctor[xls]"`)
```py
>>> from asynctor.xls import load_xls
>>> await load_xls('tests/demo.xlsx')
[{'Column1': 'row1-\\t%c', 'Column2\nMultiLines': 0, 'Column 3': 1, 4: ''}, {'Column1': 'r2c1\n00', 'Column2\nMultiLines': 'r2 c2', 'Column 3': 2, 4: ''}]
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "asynctor",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "asyncio, anyio, aioredis",
    "author": null,
    "author_email": "Waket Zheng <waketzheng@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/97/90/3e679410b2710bbc3da5c9878d06cb46a9d4118a91308254d02b25f54cfc/asynctor-0.8.7.tar.gz",
    "platform": null,
    "description": "# asynctor\n![Python Versions](https://img.shields.io/pypi/pyversions/asynctor)\n[![LatestVersionInPypi](https://img.shields.io/pypi/v/asynctor.svg?style=flat)](https://pypi.python.org/pypi/asynctor)\n[![GithubActionResult](https://github.com/waketzheng/asynctor/workflows/ci/badge.svg)](https://github.com/waketzheng/asynctor/actions?query=workflow:ci)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)\n[![Coverage Status](https://coveralls.io/repos/github/waketzheng/asynctor/badge.svg?branch=main)](https://coveralls.io/github/waketzheng/asynctor?branch=main)\n![Mypy coverage](https://img.shields.io/badge/mypy-100%25-green.svg)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\nSome async functions that using anyio, and toolkit for excel read.\n\n## Installation\n\n<div class=\"termy\">\n\n```console\n$ pip install asynctor\n---> 100%\nSuccessfully installed asynctor\n```\nwith extras:\n```console\npip install \"asynctor[xls,redis,fastapi]\"\n```\nOr by pdm:\n```bash\npdm add \"asynctor[redis]\"\n```\n\n</div>\n\n## Usage\n\n- Async function that compare asyncio but use anyio: `bulk_gather/gather/run`\n```py\n>>> import asynctor\n>>> async def foo():\n...     return 1\n...\n>>> await asynctor.bulk_gather([foo(), foo()], limit=200)\n(1, 1)\n>>> await asynctor.gather(foo(), foo())\n(1, 1)\n>>> asynctor.run(gather(foo(), foo()))\n(1, 1)\n```\n- timeit\n```py\n>>> import time\n>>> import anyio\n>>> from asynctor import timeit\n>>> @timeit\n... async def sleep_test():\n...     await anyio.sleep(3)\n...\n>>> await sleep()\nsleep_test Cost: 3.0 seconds\n\n>>> @timeit\n... def sleep_test2():\n...     time.sleep(3.1)\n...\n>>> sleep_test2()\nsleep_test2 Cost: 3.1 seconds\n```\n- AioRedis\n\n*pip install \"asynctor[redis]\"*\n```py\nfrom asynctor.contrib.fastapi import AioRedis, register_aioredis\nfrom fastapi import FastAPI\n\napp = FastAPI()\nregister_aioredis(app)\n\n@app.get('/')\nasync def root(redis: AioRedis) -> list[str]:\n    return await redis.keys()\n\n@app.get('/redis')\nasync def get_value_from_redis_by_key(redis: AioRedis, key: str) -> str:\n    value = await redis.get(key)\n    if not value:\n        return ''\n    return value.decode()\n```\n- AsyncTestClient\n*pip install \"asynctor[fastapi]\"*\n```py\nimport pytest\nfrom asynctor import AsyncTestClient, AsyncClientGenerator\nfrom httpx import AsyncClient\n\nfrom main import app\n\n@pytest.fixture(scope='session')\nasync def client() -> AsyncClientGenerator:\n    async with AsyncTestClient(app) as c:\n        yield c\n\n@pytest.fixture(scope=\"session\")\ndef anyio_backend():\n    return \"asyncio\"\n\n@pytest.mark.anyio\nasync def test_api(client: AsyncClient):\n    response = await client.get(\"/\")\n    assert response.status_code == 200\n```\n\n- Read Excel File(need to install with xls extra: `pip install \"asynctor[xls]\"`)\n```py\n>>> from asynctor.xls import load_xls\n>>> await load_xls('tests/demo.xlsx')\n[{'Column1': 'row1-\\\\t%c', 'Column2\\nMultiLines': 0, 'Column 3': 1, 4: ''}, {'Column1': 'r2c1\\n00', 'Column2\\nMultiLines': 'r2 c2', 'Column 3': 2, 4: ''}]\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Async functions to compare with anyio and asyncio, and toolkit to read excel with async/await.",
    "version": "0.8.7",
    "project_urls": {
        "Bug Tracker": "https://github.com/waketzheng/asynctor/issues",
        "homepage": "https://github.com/waketzheng/asynctor",
        "repository": "https://github.com/waketzheng/asynctor.git"
    },
    "split_keywords": [
        "asyncio",
        " anyio",
        " aioredis"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a883b55d8466ddc5bb6afc274c2d421b53dcd858fd79bc213de7b472b3303367",
                "md5": "2401f754307120929f8cf495ff40a14b",
                "sha256": "0a29304148465388c2f8e0a1c3afec4f6ab9d1c91f447f6e9174eec9a5add090"
            },
            "downloads": -1,
            "filename": "asynctor-0.8.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2401f754307120929f8cf495ff40a14b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 20075,
            "upload_time": "2025-08-15T04:03:49",
            "upload_time_iso_8601": "2025-08-15T04:03:49.104225Z",
            "url": "https://files.pythonhosted.org/packages/a8/83/b55d8466ddc5bb6afc274c2d421b53dcd858fd79bc213de7b472b3303367/asynctor-0.8.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "97903e679410b2710bbc3da5c9878d06cb46a9d4118a91308254d02b25f54cfc",
                "md5": "c080ba0f66cee9d35d53258b9b1c9389",
                "sha256": "9dac24873942eda483481e893dd77aea0320d3fd5eb1604030d5bc638803950d"
            },
            "downloads": -1,
            "filename": "asynctor-0.8.7.tar.gz",
            "has_sig": false,
            "md5_digest": "c080ba0f66cee9d35d53258b9b1c9389",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 35254,
            "upload_time": "2025-08-15T04:03:50",
            "upload_time_iso_8601": "2025-08-15T04:03:50.387815Z",
            "url": "https://files.pythonhosted.org/packages/97/90/3e679410b2710bbc3da5c9878d06cb46a9d4118a91308254d02b25f54cfc/asynctor-0.8.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-15 04:03:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "waketzheng",
    "github_project": "asynctor",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "asynctor"
}
        
Elapsed time: 0.80885s