Skip to main content

async wrapper

Project description

async-wrapper

License: MIT github action PyPI version python version

how to install

$ pip install async_wrapper
# or
$ pip install "async_wrapper[all]"
# or
$ pip install "async_wrapper[anyio]"
# or
$ pip install "async_wrapper[loky]"

how to use

from __future__ import annotations

import asyncio

# or(>=py311)
# from asyncio.taskgroups import TaskGroup
from async_wrapper import async_to_sync, get_task_group_factory, get_task_group_wrapper


@async_to_sync("thread")
async def sample_func() -> int:
    await asyncio.sleep(1)
    return 1


result = sample_func()
assert isinstance(result, int)
assert result == 1


async def sample_func_2(x: int) -> int:
    await asyncio.sleep(1)
    return x


async def main():
    wrapper = get_task_group_wrapper("asyncio")
    factory = get_task_group_factory("asyncio")
    async with factory() as task_group:
        value_1 = wrapper(sample_func_2, task_group)(1)
        value_2 = wrapper(sample_func_2, task_group)(2)

    assert isinstance(value_1.value, int)
    assert isinstance(value_2.value, int)
    assert value_1.value == 1
    assert value_2.value == 2

License

MIT, see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_wrapper-0.1.3.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

async_wrapper-0.1.3-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file async_wrapper-0.1.3.tar.gz.

File metadata

  • Download URL: async_wrapper-0.1.3.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1040-azure

File hashes

Hashes for async_wrapper-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d817650d4cd3d63fe9159fcef6cf2dfd1294ac99541307f3676377e09eacf450
MD5 97dad5adfb3732fab119c645339e0e7c
BLAKE2b-256 f3b83f6e928b60f0748b8d948a3e54e9a4981d1e69e45399d0bdb01369d97f0b

See more details on using hashes here.

File details

Details for the file async_wrapper-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: async_wrapper-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1040-azure

File hashes

Hashes for async_wrapper-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9441750b7b2b14941244db4827aab5783011a223ef7603d8c8b290cb29d2a19e
MD5 d997d2121f1261a759ee66fda4a5c59c
BLAKE2b-256 2cc3968a58bfb562a46ae2e70018e9b5f74a42b1a6cd738794037cf4f180baaf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page