JavaScript-style async programming for Python.
Find a file
Miguel Grinberg d14880632c
All checks were successful
build / tests-3.11 (push) Successful in 57s
build / tests-3.10 (push) Successful in 1m1s
build / lint (push) Successful in 1m32s
build / tests-3.12 (push) Successful in 1m7s
build / tests-3.13 (push) Successful in 1m11s
build / zizmor (push) Successful in 11s
build / tests-3.14 (push) Successful in 1m6s
build / tests-pypy-3.11 (push) Successful in 2m6s
Forgejo migration
2026-08-29 20:24:38 +01:00
.forgejo/workflows Forgejo migration 2026-08-29 20:24:38 +01:00
docs Add Python 3.11 to builds 2023-03-13 10:25:06 +00:00
src/promisio Promise cancellation improvements 2021-11-21 19:58:43 +00:00
tests Python 3.14 support 2026-05-15 00:11:44 +01:00
.gitignore Forgejo migration 2026-08-29 20:24:38 +01:00
.readthedocs.yaml Forgejo migration 2026-08-29 20:24:38 +01:00
CHANGES.md Release 0.2 2026-05-15 00:20:40 +01:00
CODE_OF_CONDUCT.md Forgejo migration 2026-08-29 20:24:38 +01:00
CONTRIBUTING.md Forgejo migration 2026-08-29 20:24:38 +01:00
LICENSE Added missing LICENSE file 2022-02-24 18:47:34 +00:00
MANIFEST.in Migrate Python package metadata to pyproject.toml 2023-10-15 14:20:52 +01:00
pyproject.toml Version 0.3.dev0 2026-05-15 00:20:47 +01:00
README.md Forgejo migration 2026-08-29 20:24:38 +01:00
SECURITY.md Forgejo migration 2026-08-29 20:24:38 +01:00
tox.ini ci updates 2026-05-15 00:05:27 +01:00

promisio

tests

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

Sponsor this project

This project relies on contributions from its users. If you benefit from it please consider making a single or ongoing monetary contribution in one of the following platforms:

Thank you!