Name | asynctor JSON |
Version |
0.6.9
JSON |
| download |
home_page | https://github.com/waketzheng/asynctor |
Summary | Async functions to compare with anyio and asyncio, and toolkit to read excel with async/await. |
upload_time | 2025-01-17 07:12:02 |
maintainer | None |
docs_url | None |
author | Waket Zheng |
requires_python | >=3.9 |
license | MIT |
keywords |
|
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://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
```
Or use poetry:
```console
poetry add asynctor
```
## 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
```
- AsyncRedis
```py
from contextlib import asynccontextmanager
from asynctor import AsyncRedis
from fastapi import FastAPI, Request
@asynccontextmanager
async def lifespan(app):
async with AsyncRedis(app):
yield
app = FastAPI(lifespan=lifespan)
@app.get('/')
async def root(request: Request) -> list[str]:
return await AsyncRedis(request).keys()
@app.get('/redis')
async def get_value_from_redis_by_key(request: Request, key: str) -> str:
value = await AsyncRedis(request).get(key)
if not value:
return ''
return value.decode()
```
- AsyncTestClient
```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": "https://github.com/waketzheng/asynctor",
"name": "asynctor",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Waket Zheng",
"author_email": "waketzheng@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/69/7c/79fcf4ed769a099e12d7464438a7ba0f37c2e42644f612ffd1c4198103fb/asynctor-0.6.9.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://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```\nOr use poetry:\n```console\npoetry add asynctor\n```\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- AsyncRedis\n```py\nfrom contextlib import asynccontextmanager\n\nfrom asynctor import AsyncRedis\nfrom fastapi import FastAPI, Request\n\n@asynccontextmanager\nasync def lifespan(app):\n async with AsyncRedis(app):\n yield\n\napp = FastAPI(lifespan=lifespan)\n\n@app.get('/')\nasync def root(request: Request) -> list[str]:\n return await AsyncRedis(request).keys()\n\n@app.get('/redis')\nasync def get_value_from_redis_by_key(request: Request, key: str) -> str:\n value = await AsyncRedis(request).get(key)\n if not value:\n return ''\n return value.decode()\n```\n- AsyncTestClient\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.6.9",
"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": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ccf5cd99338e90b291cde6b5a3582025fb8fbc037e7ed9fb4498525b8cbe9e73",
"md5": "8ca3ca16fb5fc4cd2f277e92ba4a9be5",
"sha256": "3add7df7a15bb747c1b758ca6e25d83a37bea7ceeb566c3c6bf2e93808c5e40f"
},
"downloads": -1,
"filename": "asynctor-0.6.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8ca3ca16fb5fc4cd2f277e92ba4a9be5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 13911,
"upload_time": "2025-01-17T07:12:00",
"upload_time_iso_8601": "2025-01-17T07:12:00.153293Z",
"url": "https://files.pythonhosted.org/packages/cc/f5/cd99338e90b291cde6b5a3582025fb8fbc037e7ed9fb4498525b8cbe9e73/asynctor-0.6.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "697c79fcf4ed769a099e12d7464438a7ba0f37c2e42644f612ffd1c4198103fb",
"md5": "56fbeb78c58b1c84060eb0a70b19aa94",
"sha256": "65c149b16310bba080b40f63f919e2265a00a885c01ac8f6929b6792db737cd9"
},
"downloads": -1,
"filename": "asynctor-0.6.9.tar.gz",
"has_sig": false,
"md5_digest": "56fbeb78c58b1c84060eb0a70b19aa94",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 11798,
"upload_time": "2025-01-17T07:12:02",
"upload_time_iso_8601": "2025-01-17T07:12:02.415973Z",
"url": "https://files.pythonhosted.org/packages/69/7c/79fcf4ed769a099e12d7464438a7ba0f37c2e42644f612ffd1c4198103fb/asynctor-0.6.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-17 07:12:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "waketzheng",
"github_project": "asynctor",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "asynctor"
}