{"id":15569696,"url":"https://github.com/syrusakbary/promise","last_synced_at":"2025-04-11T11:47:06.781Z","repository":{"id":8311568,"uuid":"57949796","full_name":"syrusakbary/promise","owner":"syrusakbary","description":"Ultra-performant Promise implementation in Python","archived":false,"fork":false,"pushed_at":"2024-07-09T05:36:30.000Z","size":243,"stargazers_count":363,"open_issues_count":38,"forks_count":76,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-03T12:06:55.696Z","etag":null,"topics":["promise","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syrusakbary.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-03T07:25:34.000Z","updated_at":"2025-01-26T02:15:35.000Z","dependencies_parsed_at":"2024-10-30T12:02:09.601Z","dependency_job_id":"7912103a-ec0f-4968-b393-8bfbf29fc189","html_url":"https://github.com/syrusakbary/promise","commit_stats":{"total_commits":221,"total_committers":18,"mean_commits":"12.277777777777779","dds":"0.23981900452488691","last_synced_commit":"4627315476f6b9fc82818327ae09b04f89f9bda7"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syrusakbary%2Fpromise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syrusakbary%2Fpromise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syrusakbary%2Fpromise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syrusakbary%2Fpromise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syrusakbary","download_url":"https://codeload.github.com/syrusakbary/promise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248388267,"owners_count":21095359,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["promise","python"],"created_at":"2024-10-02T17:36:25.902Z","updated_at":"2025-04-11T11:47:06.748Z","avatar_url":"https://github.com/syrusakbary.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Promise\n\nThis is a implementation of Promises in Python.\nIt is a super set of Promises/A+ designed to have readable, performant code and to provide just the extensions that are absolutely necessary for using promises in Python.\n\nIts fully compatible with the [Promises/A+ spec](http://promises-aplus.github.io/promises-spec/)\n\n[![travis][travis-image]][travis-url]\n[![pypi][pypi-image]][pypi-url]\n[![coveralls][coveralls-image]][coveralls-url]\n\n[travis-image]: https://img.shields.io/travis/syrusakbary/promise.svg?style=flat\n[travis-url]: https://travis-ci.org/syrusakbary/promise\n[pypi-image]: https://img.shields.io/pypi/v/promise.svg?style=flat\n[pypi-url]: https://pypi.python.org/pypi/promise\n[coveralls-image]: https://coveralls.io/repos/syrusakbary/promise/badge.svg?branch=master\u0026service=github\n[coveralls-url]: https://coveralls.io/github/syrusakbary/promise?branch=master\n\n## Installation\n\n    $ pip install promise\n\n## Usage\n\nThe example below shows how you can load the promise library. It then demonstrates creating a promise from scratch. You simply call `Promise(fn)`. There is a complete specification for what is returned by this method in [Promises/A+](http://promises-aplus.github.com/promises-spec/).\n\n```python\nfrom promise import Promise\n\npromise = Promise(\n    lambda resolve, reject: resolve('RESOLVED!')\n)\n```\n\n## API\n\nBefore all examples, you will need:\n\n```python\nfrom promise import Promise\n```\n\n### Promise(resolver)\n\nThis creates and returns a new promise. `resolver` must be a function. The `resolver` function is passed two arguments:\n\n1.  `resolve` should be called with a single argument. If it is called with a non-promise value then the promise is fulfilled with that value. If it is called with a promise (A) then the returned promise takes on the state of that new promise (A).\n2.  `reject` should be called with a single argument. The returned promise will be rejected with that argument.\n\n### Class Methods\n\nThese methods are invoked by calling `Promise.methodName`.\n\n#### Promise.resolve(value)\n\nConverts values and foreign promises into Promises/A+ promises. If you pass it a value then it returns a Promise for that value. If you pass it something that is close to a promise (such as a jQuery attempt at a promise) it returns a Promise that takes on the state of `value` (rejected or fulfilled).\n\n#### Promise.reject(value)\n\nReturns a rejected promise with the given value.\n\n#### Promise.all(list)\n\nReturns a promise for a list. If it is called with a single argument then this returns a promise for a copy of that list with any promises replaced by their fulfilled values. e.g.\n\n```python\np = Promise.all([Promise.resolve('a'), 'b', Promise.resolve('c')]) \\\n       .then(lambda res: res == ['a', 'b', 'c'])\n\nassert p.get() is True\n```\n\n#### Promise.cast(obj)\n\nThis function wraps the `obj` ect as a `Promise` if possible.\nPython `Future`s are supported, with a callback to `promise.done` when resolved.\nHas the same effects as `Promise.resolve(obj)`.\n\n#### Promise.for_dict(d)\n\nA special function that takes a dictionary of promises and turns them\ninto a promise for a dictionary of values. In other words, this turns\na dictionary of promises for values into a promise for a dictionary\nof values.\n\n#### Promise.is_thenable(obj)\n\nThis function checks if the `obj` is a `Promise`, or could be `cast`ed.\n\n#### Promise.promisify(func)\n\nThis function wraps the result of calling `func` in a `Promise` instance.\n\n### Instance Methods\n\nThese methods are invoked on a promise instance by calling `myPromise.methodName`\n\n### promise.then(did_fulfill, did_reject)\n\nThis method follows the [Promises/A+ spec](http://promises-aplus.github.io/promises-spec/). It explains things very clearly so I recommend you read it.\n\nEither `did_fulfill` or `did_reject` will be called and they will not be called more than once. They will be passed a single argument and will always be called asynchronously (in the next turn of the event loop).\n\nIf the promise is fulfilled then `did_fulfill` is called. If the promise is rejected then `did_reject` is called.\n\nThe call to `.then` also returns a promise. If the handler that is called returns a promise, the promise returned by `.then` takes on the state of that returned promise. If the handler that is called returns a value that is not a promise, the promise returned by `.then` will be fulfilled with that value. If the handler that is called throws an exception then the promise returned by `.then` is rejected with that exception.\n\n#### promise.catch(did_reject)\n\nSugar for `promise.then(None, did_reject)`, to mirror `catch` in synchronous code.\n\n#### promise.done(did_fulfill, did_reject)\n\nThe same semantics as `.then` except that it does not return a promise and any exceptions are re-thrown so that they can be logged (crashing the application in non-browser environments)\n\n# Contributing\n\nAfter cloning this repo, ensure dependencies are installed by running:\n\n```sh\npip install -e \".[test]\"\n```\n\nAfter developing, the full test suite can be evaluated by running:\n\n```sh\npy.test tests --cov=promise --benchmark-skip # Use -v -s for verbose mode\n```\n\nYou can also run the benchmarks with:\n\n```sh\npy.test tests --benchmark-only\n```\n\n## Static type checking\n\nPython type annotations are very useful for making sure we use the libary the way is intended.\n\nYou can run `mypy` static type checker:\n\n```sh\npip install mypy\nmypy promise  --ignore-missing-imports\n```\n\nOr `pyre`:\n\n```sh\npip install pyre-check\npyre --source-directory promise check\n```\n\n# Notes\n\nThis package is heavily insipired in [aplus](https://github.com/xogeny/aplus).\n\n## License\n\n[MIT License](https://github.com/syrusakbary/promise/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyrusakbary%2Fpromise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyrusakbary%2Fpromise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyrusakbary%2Fpromise/lists"}