| Name | asynctor JSON |
| Version |
0.10.3
JSON |
| download |
| home_page | None |
| Summary | Async functions to compare with anyio and asyncio, and toolkit to read excel with async/await. |
| upload_time | 2025-11-09 02:49:20 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.10 |
| license | MIT |
| keywords |
asyncio
anyio
aioredis
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# asynctor

[](https://pypi.python.org/pypi/asynctor)
[](https://github.com/waketzheng/asynctor/actions?query=workflow:ci)
[](https://github.com/pre-commit/pre-commit)
[](https://coveralls.io/github/waketzheng/asynctor?branch=main)

[](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:
```shell
pip install "asynctor[xlsx,redis,fastapi]"
```
Or by pdm:
```bash
pdm add "asynctor[redis]"
```
Or by uv:
```sh
uv add asynctor
```
Or install the latest from *github*
```
uv pip install "asynctor @git+https://github.com/waketzheng/asynctor"
```
Or install by ssh
```
uv pip install "asynctor[redis] @git+ssh://git@github.com/waketzheng/asynctor.git"
```
</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)
```
- `run_async`: start a new thread to run async function and get result of it
```py
>>> from asynctor import run_async
>>> async def foo(a=1):
... return a
...
>>> run_async(foo) == run_async(foo()) == run_async(foo, 1) == 1
True
```
- 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
>>> with timeit('Sleeping'):
... sleep()
...
Sleeping Cost: 3.0 seconds
```
- AioRedis
*pip install "asynctor[redis]"*
```py
from asynctor.contrib.fastapi import AioRedisDep, register_aioredis
from fastapi import FastAPI
app = FastAPI()
register_aioredis(app)
@app.get('/')
async def root(redis: AioRedisDep) -> list[str]:
return await redis.keys()
@app.get('/redis')
async def get_value_from_redis_by_key(redis: AioRedisDep, key: str) -> str:
value = await redis.get(key)
if not value:
return ''
return value.decode()
```
- Async Test Fixtures
*pip install "asynctor[testing]"*
```py
import pytest
from asynctor.testing import anyio_backend_fixture, async_client_fixture
from httpx import AsyncClient
from main import app
anyio_backend = anyio_backend_fixture()
client = async_client_fixture(app)
@pytest.mark.anyio
async def test_api(client: AsyncClient):
response = await client.get("/")
assert response.status_code == 200
```
- Read Excel File
*pandas/openpyxl is required, can be installed with xlsx extra: `pip install "asynctor[xlsx]"`*
```py
>>> from asynctor.xlsx import load_xlsx
>>> await load_xlsx('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.10",
"maintainer_email": null,
"keywords": "asyncio, anyio, aioredis",
"author": null,
"author_email": "Waket Zheng <waketzheng@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/96/14/676558f64728288b2a3037f3b1ff524d116ef4e1d1d767f96dc7e125d30c/asynctor-0.10.3.tar.gz",
"platform": null,
"description": "# asynctor\n\n[](https://pypi.python.org/pypi/asynctor)\n[](https://github.com/waketzheng/asynctor/actions?query=workflow:ci)\n[](https://github.com/pre-commit/pre-commit)\n[](https://coveralls.io/github/waketzheng/asynctor?branch=main)\n\n[](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```shell\npip install \"asynctor[xlsx,redis,fastapi]\"\n```\nOr by pdm:\n```bash\npdm add \"asynctor[redis]\"\n```\nOr by uv:\n```sh\nuv add asynctor\n```\nOr install the latest from *github*\n```\nuv pip install \"asynctor @git+https://github.com/waketzheng/asynctor\"\n```\nOr install by ssh\n```\nuv pip install \"asynctor[redis] @git+ssh://git@github.com/waketzheng/asynctor.git\"\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- `run_async`: start a new thread to run async function and get result of it\n```py\n>>> from asynctor import run_async\n>>> async def foo(a=1):\n... return a\n...\n>>> run_async(foo) == run_async(foo()) == run_async(foo, 1) == 1\nTrue\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>>> with timeit('Sleeping'):\n... sleep()\n...\nSleeping Cost: 3.0 seconds\n```\n- AioRedis\n\n*pip install \"asynctor[redis]\"*\n```py\nfrom asynctor.contrib.fastapi import AioRedisDep, register_aioredis\nfrom fastapi import FastAPI\n\napp = FastAPI()\nregister_aioredis(app)\n\n@app.get('/')\nasync def root(redis: AioRedisDep) -> list[str]:\n return await redis.keys()\n\n@app.get('/redis')\nasync def get_value_from_redis_by_key(redis: AioRedisDep, key: str) -> str:\n value = await redis.get(key)\n if not value:\n return ''\n return value.decode()\n```\n- Async Test Fixtures\n*pip install \"asynctor[testing]\"*\n```py\nimport pytest\nfrom asynctor.testing import anyio_backend_fixture, async_client_fixture\nfrom httpx import AsyncClient\n\nfrom main import app\n\nanyio_backend = anyio_backend_fixture()\nclient = async_client_fixture(app)\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\n*pandas/openpyxl is required, can be installed with xlsx extra: `pip install \"asynctor[xlsx]\"`*\n```py\n>>> from asynctor.xlsx import load_xlsx\n>>> await load_xlsx('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.10.3",
"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": "246971ec3488bfa2f73c8ee1a8bb3b634396e5628e0eb31e1bd846ba72269c6a",
"md5": "16b0a962809287f9a5c8ea2a81281a3a",
"sha256": "7f2077d5bafe789ea4b85d347851389383c55d9b7647112170c875c178286657"
},
"downloads": -1,
"filename": "asynctor-0.10.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "16b0a962809287f9a5c8ea2a81281a3a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 23063,
"upload_time": "2025-11-09T02:49:19",
"upload_time_iso_8601": "2025-11-09T02:49:19.529602Z",
"url": "https://files.pythonhosted.org/packages/24/69/71ec3488bfa2f73c8ee1a8bb3b634396e5628e0eb31e1bd846ba72269c6a/asynctor-0.10.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9614676558f64728288b2a3037f3b1ff524d116ef4e1d1d767f96dc7e125d30c",
"md5": "31370850132174f3055c0955446b2100",
"sha256": "d8d34ac305ab9c2e1740a65cc9ae012aba6c774727e826cfeaac761636c3ddea"
},
"downloads": -1,
"filename": "asynctor-0.10.3.tar.gz",
"has_sig": false,
"md5_digest": "31370850132174f3055c0955446b2100",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 39656,
"upload_time": "2025-11-09T02:49:20",
"upload_time_iso_8601": "2025-11-09T02:49:20.800379Z",
"url": "https://files.pythonhosted.org/packages/96/14/676558f64728288b2a3037f3b1ff524d116ef4e1d1d767f96dc7e125d30c/asynctor-0.10.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-11-09 02:49:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "waketzheng",
"github_project": "asynctor",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "asynctor"
}