Skip to main content

PioDispatch

Dispatch blocking IO calls to threads wrapped in coroutines (technically, asyncio.Futures). It allows easily integrating older blocking APIs with async/await syntax.

Installation

Install via pip:

pip install piodispatch

Usage

The piodispatch module defines two epicentral functions: dispatch and ascoroutine.

Using dispatch works as follows:

from piodispatch import dispatch
import requests

async def myfun():
    res = await dispatch(requests.get, 'https://google.com/')
    # type(res) is requests.Response

dispatch passes any *args and **kwargs on to its first parameter, which is assumed to be a Callable.

Using ascoroutine works slightly differently:

from piodispatch import ascoroutine
import requests

rget = ascoroutine(requests.get)

async def myfun():
    res = await rget('https://google.com/')
    # type(res) is requests.Response

Unlike dispatch, which immediately executes the method, ascoroutine wraps the method in a coroutine which internally simply calls dispatch. While it could technically also be used as a decorator, this is effectively the same as simply writing an async def.

License

MIT License

Copyright (c) 2020 Kiruse

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for piodispatch 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for piodispatch 1.0.3
File Size Uploaded
piodispatch-1.0.3.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for piodispatch 1.0.3
File Interpreter ABI Platform
piodispatch-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 7.7 kB

Release files / piodispatch-1.0.3.tar.gz

Download URL piodispatch-1.0.3.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5e97702dfab0fb49c2652ca7e19031b6f79201d05dfce0b3291e0cb47c5d21a2
BLAKE2b-256 checksum
How to use checksums
41ae5d60fff629832dc96670d861eaf55bdde452050e4abc078833113265bea6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

Release files / piodispatch-1.0.3-py3-none-any.whl

Download URL piodispatch-1.0.3-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b1de1a456e5ef7651fd1d4a237898177dc872ddc7c257cb63ade9aa1708a0f1
BLAKE2b-256 checksum
How to use checksums
a67201ffabfeaf328da6be192edf6d1d99f27e26c60fc8db0545ede709ee3aa3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page