{"id":2669,"library":"promise","title":"Python Promises/A+ implementation","description":"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.","status":"active","version":"2.3.0","language":"python","source_language":"en","source_url":"https://github.com/syrusakbary/promise","tags":["async","promises","async/await","dataloader","concurrency"],"install":[{"cmd":"pip install promise","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for Python 2 and 3 compatibility, though the library primarily targets Python 3.5+.","package":"six","optional":false}],"imports":[{"symbol":"Promise","correct":"from promise import Promise"},{"note":"DataLoader is located in a submodule.","wrong":"from promise import DataLoader","symbol":"DataLoader","correct":"from promise.dataloader import DataLoader"}],"quickstart":{"code":"from promise import Promise\n\ndef my_async_operation(resolve, reject):\n    # Simulate an async task\n    import time\n    time.sleep(0.1)\n    success = True # or False for rejection\n    if success:\n        resolve('Data fetched successfully!')\n    else:\n        reject('Failed to fetch data.')\n\n# Create a promise\npromise_instance = Promise(my_async_operation)\n\n# Chain operations with .then() and handle errors with .catch()\npromise_instance.then(\n    lambda result: print(f'Resolved: {result}')\n).catch(\n    lambda error: print(f'Rejected: {error}')\n)\n\n# To make the example runnable without an explicit event loop for simple cases:\n# In a real async application (e.g., with asyncio), you would integrate it with the event loop.\n# This example is synchronous after the sleep, demonstrating the promise structure.","lang":"python","description":"Demonstrates creating a basic Promise and chaining `.then()` and `.catch()` callbacks for handling resolution and rejection."},"warnings":[{"fix":"Review the official documentation for Promise 2.x API changes, specifically for `resolve` and `reject` methods. Update method calls and their signatures accordingly.","message":"Version 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.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Upgrade to version 2.3.0 or newer to benefit from built-in thread-safety for `Promise` and `DataLoader`.","message":"`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.","severity":"gotcha","affected_versions":"<2.3.0"},{"fix":"Upgrade to version 2.3.0 or newer to resolve the memory leak issue.","message":"Versions prior to 2.3.0 contained a memory leak, particularly impacting dynamically created types within the library.","severity":"gotcha","affected_versions":"<2.3.0"},{"fix":"Upgrade to version 2.0.1 or newer, where this issue was fixed.","message":"In version 2.0.0, `Promise.resolve` when called with a coroutine incorrectly returned an `asyncio.Task` instead of a `Promise`, breaking expected chaining behavior.","severity":"gotcha","affected_versions":"2.0.0"},{"fix":"Upgrade to version 2.3.0 or newer to fix Python 3.7 deprecation warnings.","message":"Older versions of the library (prior to 2.3.0) might emit deprecation warnings when run on Python 3.7 and newer environments.","severity":"gotcha","affected_versions":"<2.3.0"}],"env_vars":null,"search_vec":"'2.3.0':47 'akin':22 'api':21 'async':60 'async/await':62 'asynchron':16 'code':30 'compat':59 'concurr':64 'current':44 'dataload':39,63 'design':13 'develop':36 'essenti':32 'extens':33 'familiar':20 'focus':52 'handl':15 'implement':3,10,40 'includ':37 'javascript':24 'librari':6,42 'occasion':50 'offer':27 'oper':17 'perform':29,54 'promis':5,25,61 'promises/a':2,9 'provid':7 'python':1,12,35 'readabl':28 'safeti':57 'see':49 'thread':56 'thread-safeti':55 'updat':51 'version':46","created_at":"2026-04-11T01:37:49.513859+00:00","updated_at":"2026-04-16T18:11:36.210972+00:00","problems":[{"fix":"Install the library using pip: `pip install promise`","cause":"The 'promise' library is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'promise'"},{"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`","cause":"This specific import error often arises from an incomplete or corrupted installation of the 'promise' library, or a conflict with other package dependencies.","error":"ModuleNotFoundError: No module named 'promise.pyutils'"},{"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)`","cause":"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.","error":"Unhandled promise rejection"},{"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: ...)`","cause":"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()`.","error":"TypeError: object is not callable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.3","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/syrusakbary/promise","docs":null,"changelog":null,"pypi":"https://pypi.org/project/promise/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}