Skip to main content

JavaScript-style async programming for Python.

Project description

promisio

Build status codecov

JavaScript-style async programming for Python.

Examples

Create a promise-based async function using the promisify decorator. It works on both sync and async functions!

from promisio import promisify

@promisify
async def f():
    await asyncio.sleep(1)
    return 42

@promisify
def g(x):
    return x * 2

async def main():
    print(await f())  # prints 42
    print(await g(42))  # prints 84

    promise = f()  # runs function in the background without waiting
    # ... do other stuff here in parallel with f running
    await promise  # finally wait for f to complete

The return value of the decorated function is a JavaScript-style promise object that can be awaited. The then(), catch() and finally_() methods to chain promises work as in JavaScript. The Promise.all(), Promise.all_settled(), Promise.any(), Promise.race(), Promise.resolve() and Promise.reject() are also available. Promises in this package are extended to also support cancellation via the cancel() and cancelled() methods.

Resources

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

promisio-0.2.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

promisio-0.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file promisio-0.2.tar.gz.

File metadata

  • Download URL: promisio-0.2.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for promisio-0.2.tar.gz
Algorithm Hash digest
SHA256 80fdb440254c8b4ac390c9bd3aadc784d3a0684163add243c095abbaa98ea098
MD5 e413ae0a65aa5bfb104d97fe99ed9c7d
BLAKE2b-256 b261caeb325f5a5b4cfa0f0538e1cef5de8acae42d099046564729cee8ed5d00

See more details on using hashes here.

File details

Details for the file promisio-0.2-py3-none-any.whl.

File metadata

  • Download URL: promisio-0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for promisio-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 804d9a35ced1aac079a06319bc31a98ef218b5bb65a18e1cf280335bf78c4f9e
MD5 7411a0bc7436cb2ab7edbf826890ce30
BLAKE2b-256 9d27cdff9e9582bf76399585e864f30d6c0594a303f9b7dc32cbd487c4e84cef

See more details on using hashes here.

Supported by

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