Skip to main content

Dispatch blocking IO calls to threads wrapped in coroutines.

Project description

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.

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

piodispatch-1.0.3.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

piodispatch-1.0.3-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file piodispatch-1.0.3.tar.gz.

File metadata

  • Download URL: piodispatch-1.0.3.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for piodispatch-1.0.3.tar.gz
Algorithm Hash digest
SHA256 5e97702dfab0fb49c2652ca7e19031b6f79201d05dfce0b3291e0cb47c5d21a2
MD5 c8c9991d2ec5b455e2e928ddeab04158
BLAKE2b-256 41ae5d60fff629832dc96670d861eaf55bdde452050e4abc078833113265bea6

See more details on using hashes here.

Provenance

File details

Details for the file piodispatch-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: piodispatch-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for piodispatch-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8b1de1a456e5ef7651fd1d4a237898177dc872ddc7c257cb63ade9aa1708a0f1
MD5 7da1a5b8a0542435d5a6a12b45bb7e7f
BLAKE2b-256 a67201ffabfeaf328da6be192edf6d1d99f27e26c60fc8db0545ede709ee3aa3

See more details on using hashes here.

Provenance

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