asyncur


Nameasyncur JSON
Version 0.5.4 PyPI version JSON
download
home_pageNone
SummaryAsync functions to compare with anyio and asyncio, and toolkit to read excel with async/await.
upload_time2024-06-17 09:22:26
maintainerNone
docs_urlNone
authorWaket Zheng
requires_python<4.0,>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # asyncur
![Python Versions](https://img.shields.io/pypi/pyversions/asyncur)
[![LatestVersionInPypi](https://img.shields.io/pypi/v/asyncur.svg?style=flat)](https://pypi.python.org/pypi/asyncur)
[![GithubActionResult](https://github.com/waketzheng/asyncur/workflows/ci/badge.svg)](https://github.com/waketzheng/asyncur/actions?query=workflow:ci)
[![Coverage Status](https://coveralls.io/repos/github/waketzheng/asyncur/badge.svg?branch=main)](https://coveralls.io/github/waketzheng/asyncur?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 asyncur
---> 100%
Successfully installed asyncur
```
Or use poetry:
```console
poetry add asyncur
```

## Usage

- bulk_gather/gather/run_async
```py
>>> from asyncur import gather, run_async
>>> async def foo():
...     return 1
...
>>> await bulk_gather([foo(), foo()], limit=200)
(1, 1)
>>> await gather(foo(), foo())
(1, 1)
>>> run_async(gather(foo(), foo()))
(1, 1)
```
- timeit
```py
>>> import time
>>> import anyio
>>> from asyncur 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 asyncur 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()
```


- Read Excel File(need to install with xls extra: `pip install "asyncur[xls]"`)
```py
>>> from asycur.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": "asyncur",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Waket Zheng",
    "author_email": "waketzheng@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b4/41/af616bcc6fd85aedd3786bdb0157f88a8191d828075b993f79f6aa06764f/asyncur-0.5.4.tar.gz",
    "platform": null,
    "description": "# asyncur\n![Python Versions](https://img.shields.io/pypi/pyversions/asyncur)\n[![LatestVersionInPypi](https://img.shields.io/pypi/v/asyncur.svg?style=flat)](https://pypi.python.org/pypi/asyncur)\n[![GithubActionResult](https://github.com/waketzheng/asyncur/workflows/ci/badge.svg)](https://github.com/waketzheng/asyncur/actions?query=workflow:ci)\n[![Coverage Status](https://coveralls.io/repos/github/waketzheng/asyncur/badge.svg?branch=main)](https://coveralls.io/github/waketzheng/asyncur?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 asyncur\n---> 100%\nSuccessfully installed asyncur\n```\nOr use poetry:\n```console\npoetry add asyncur\n```\n\n## Usage\n\n- bulk_gather/gather/run_async\n```py\n>>> from asyncur import gather, run_async\n>>> async def foo():\n...     return 1\n...\n>>> await bulk_gather([foo(), foo()], limit=200)\n(1, 1)\n>>> await gather(foo(), foo())\n(1, 1)\n>>> run_async(gather(foo(), foo()))\n(1, 1)\n```\n- timeit\n```py\n>>> import time\n>>> import anyio\n>>> from asyncur 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 asyncur 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\n\n- Read Excel File(need to install with xls extra: `pip install \"asyncur[xls]\"`)\n```py\n>>> from asycur.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": null,
    "summary": "Async functions to compare with anyio and asyncio, and toolkit to read excel with async/await.",
    "version": "0.5.4",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "43a530d721a9ab12fb9c5e8424c38480c68002dbd0588f88ed704acb73b86699",
                "md5": "41251f8cfed61dc7ee79424134a4f1b6",
                "sha256": "8db4829869e9ca3c88216c1a9341151b2eb75739cfbf272cb3e967a3f3ad030f"
            },
            "downloads": -1,
            "filename": "asyncur-0.5.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "41251f8cfed61dc7ee79424134a4f1b6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 8731,
            "upload_time": "2024-06-17T09:22:24",
            "upload_time_iso_8601": "2024-06-17T09:22:24.884018Z",
            "url": "https://files.pythonhosted.org/packages/43/a5/30d721a9ab12fb9c5e8424c38480c68002dbd0588f88ed704acb73b86699/asyncur-0.5.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b441af616bcc6fd85aedd3786bdb0157f88a8191d828075b993f79f6aa06764f",
                "md5": "1a572c587a1d86daf3a8e906a7c3329f",
                "sha256": "990a290ad5fcc285dd74d3cc4e743b658b80ced32c5b5f06221a8b0d752b9e8c"
            },
            "downloads": -1,
            "filename": "asyncur-0.5.4.tar.gz",
            "has_sig": false,
            "md5_digest": "1a572c587a1d86daf3a8e906a7c3329f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 8002,
            "upload_time": "2024-06-17T09:22:26",
            "upload_time_iso_8601": "2024-06-17T09:22:26.739895Z",
            "url": "https://files.pythonhosted.org/packages/b4/41/af616bcc6fd85aedd3786bdb0157f88a8191d828075b993f79f6aa06764f/asyncur-0.5.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-17 09:22:26",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "asyncur"
}
        
Elapsed time: 3.83583s