{"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":"en","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,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}