Registry / http-networking / promise

promise

JSON →
library2.3pypypi✓ verified 26d ago

The `promise` library provides a Promises/A+ implementation for Python, designed to handle asynchronous operations with a familiar API akin to JavaScript Promises. It offers readable, performant code with essential extensions for Python development, including a `DataLoader` implementation. The library is currently at version 2.3.0 and sees occasional updates, focusing on performance, thread-safety, and compatibility.

pip install promise
INSTALL
IMPORT
SIG · PROMISE
P
promise
http-networkingpythonv2.3
Install
2.5s avg
Import
217ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.234s · 19.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.200s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Promise
from promise import Promise
DataLoader
from promise.dataloader import DataLoader
from promise import DataLoader
DataLoader is located in a submodule.

Demonstrates creating a basic Promise and chaining `.then()` and `.catch()` callbacks for handling resolution and rejection.

from promise import Promise def my_async_operation(resolve, reject): # Simulate an async task import time time.sleep(0.1) success = True # or False for rejection if success: resolve('Data fetched successfully!') else: reject('Failed to fetch data.') # Create a promise promise_instance = Promise(my_async_operation) # Chain operations with .then() and handle errors with .catch() promise_instance.then( lambda result: print(f'Resolved: {result}') ).catch( lambda error: print(f'Rejected: {error}') ) # To make the example runnable without an explicit event loop for simple cases: # In a real async application (e.g., with asyncio), you would integrate it with the event loop. # This example is synchronous after the sleep, demonstrating the promise structure.
Debug
Known issues
breakingVersion 2.0.0 introduced a complete rewrite. Key changes include `Promise.resolve` now behaving like `Promise.cast` and `Promise.reject` becoming a static method. Code written for 1.x versions will likely require significant updates.
fix
Review the official documentation for Promise 2.x API changes, specifically for `resolve` and `reject` methods. Update method calls and their signatures accordingly.
affects: <2.0.0
gotcha`Promise` and `DataLoader` were not thread-safe in versions prior to 2.3.0. Concurrent access from multiple threads could lead to unexpected behavior or data corruption.
fix
Upgrade to version 2.3.0 or newer to benefit from built-in thread-safety for `Promise` and `DataLoader`.
affects: <2.3.0
gotchaVersions prior to 2.3.0 contained a memory leak, particularly impacting dynamically created types within the library.
fix
Upgrade to version 2.3.0 or newer to resolve the memory leak issue.
affects: <2.3.0
gotchaIn version 2.0.0, `Promise.resolve` when called with a coroutine incorrectly returned an `asyncio.Task` instead of a `Promise`, breaking expected chaining behavior.
fix
Upgrade to version 2.0.1 or newer, where this issue was fixed.
affects: 2.0.0
gotchaOlder versions of the library (prior to 2.3.0) might emit deprecation warnings when run on Python 3.7 and newer environments.
fix
Upgrade to version 2.3.0 or newer to fix Python 3.7 deprecation warnings.
affects: <2.3.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'promise'
The 'promise' library is not installed in your Python environment.
fix
Install the library using pip: `pip install promise`
ModuleNotFoundError: No module named 'promise.pyutils'
This specific import error often arises from an incomplete or corrupted installation of the 'promise' library, or a conflict with other package dependencies.
fix
Reinstall the library, ideally in a clean virtual environment, to ensure all its internal components are correctly installed: `pip uninstall promise && pip install promise`
Unhandled promise rejection
A Promise was rejected (either explicitly via `reject` or due to an error in its execution or a `.then()` callback) but no `.catch()` handler was attached to process the rejection, leading to an uncaught exception in your application.
fix
Always attach a `.catch()` handler to your promise chains to gracefully handle any rejections and prevent unhandled exceptions. Example: `my_promise.then(on_success).catch(on_error)`
TypeError: object is not callable
This error occurs when you try to call a non-callable object, such as passing a non-function as the resolver to `Promise()`, or providing a non-callable argument to `.then()` or `.catch()`.
fix
Ensure that the first argument to `Promise()` is a function that accepts `resolve` and `reject` as parameters, and that all arguments passed to `.then()` and `.catch()` are also callable functions. For example: `Promise(lambda resolve, reject: ...)`
Upgrade
Version history
2.3latest on PyPI · released Dec 18, 2019
Audit
Dependencies
sixrequiredUsed for Python 2 and 3 compatibility, though the library primarily targets Python 3.5+.
Agent activity
9 hits · last 30 days
node
8
Resources
promise — pip install promise · libregistry