{
"info": {
"author": "Danilo Bargen",
"author_email": "mail@dbrgn.ch",
"bugtrack_url": null,
"classifiers": [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3 :: Only"
],
"description": "Result\n======\n\n.. image:: https://img.shields.io/travis/dbrgn/result/master.svg\n :alt: Build status\n :target: https://travis-ci.org/dbrgn/result\n\n.. image:: https://img.shields.io/coveralls/dbrgn/result/master.svg\n :alt: Coverage\n :target: https://coveralls.io/github/dbrgn/result\n\nA simple Result type for Python 3 `inspired by Rust `__.\n\nThe idea is that a ``Result`` value can be either ``Ok(value)`` or ``Err(error)``,\nwith a way to differentiate between the two. It will change code like this:\n\n.. sourcecode:: python\n\n def get_user_by_email(email):\n \"\"\"\n Return the user instance or an error message.\n \"\"\"\n if not user_exists(email):\n return None, 'User does not exist'\n if not user_active(email):\n return None, 'User is inactive'\n user = get_user(email)\n return user, None\n\n user, reason = get_user_by_email('ueli@example.com')\n if user is None:\n raise RuntimeError('Could not fetch user: %s' % reason)\n else:\n do_something(user)\n\nTo something like this:\n\n.. sourcecode:: python\n\n from result import Ok, Err\n\n def get_user_by_email(email):\n \"\"\"\n Return the user instance or an error message.\n \"\"\"\n if not user_exists(email):\n return Err('User does not exist')\n if not user_active(email):\n return Err('User is inactive')\n user = get_user(email)\n return Ok(user)\n\n user_result = get_user_by_email(email)\n if user_result.is_ok():\n do_something(user_result.value)\n else: \n raise RuntimeError('Could not fetch user: %s' user_result.value)\n\nAs this is Python and not Rust, you will lose some of the advantages that it\nbrings, like elegant combinations with the ``match`` statement. On the other\nside, you don't have to return semantically unclear tuples anymore.\n\nNot all methods (https://doc.rust-lang.org/std/result/enum.Result.html) have\nbeen implemented, only the ones that make sense in the Python context. You still\ndon't get any type safety, but some easier handling of types that can be OK or\nnot, without resorting to custom exceptions.\n\n\nAPI\n---\n\nCreating an instance::\n\n >>> from result import Ok, Err\n >>> res1 = Ok('yay')\n >>> res2 = Err('nay')\n\nOr through the class methods::\n\n >>> from result import Result\n >>> res1 = Result.Ok('yay')\n >>> res2 = Result.Err('nay')\n\nChecking whether a result is ok or not::\n\n >>> res = Ok('yay')\n >>> res.is_ok()\n True\n >>> res.is_err()\n False\n\nConvert a Result to the value or ``None``::\n\n >>> res1 = Ok('yay')\n >>> res2 = Err('nay')\n >>> res1.ok()\n 'yay'\n >>> res2.ok()\n None\n\nConvert a Result to the error or ``None``::\n\n >>> res1 = Ok('yay')\n >>> res2 = Err('nay')\n >>> res1.err()\n None\n >>> res2.err()\n 'nay'\n\nAccess the value directly, without any other checks::\n\n >>> res1 = Ok('yay')\n >>> res2 = Err('nay')\n >>> res1.value\n 'yay'\n >>> res2.value\n 'nay'\n\nNote that this is a property, you cannot assign to it. Results are immutable.\n\nFor your convenience, simply creating an `Ok` result without value is the same as using `True`::\n\n >>> res1 = Result.Ok()\n >>> res1.value\n True\n >>> res2 = Ok()\n >>> res2.value\n True\n\nThe `unwrap` method returns the value if `Ok`, otherwise it raises an `UnwrapError`::\n\n >>> res1 = Ok('yay')\n >>> res2 = Err('nay')\n >>> res1.unwrap()\n 'yay'\n >>> res2.unwrap()\n Traceback (most recent call last):\n File \"\", line 1, in \n File \"C:\\project\\result\\result.py\", line 107, in unwrap\n return self.expect(\"Called `Result.unwrap()` on an `Err` value\")\n File \"C:\\project\\result\\result.py\", line 101, in expect\n raise UnwrapError(message)\n result.result.UnwrapError: Called `Result.unwrap()` on an `Err` value\n\nA custom error message can be displayed instead by using `expect`::\n\n >>> res1 = Ok('yay')\n >>> res2 = Err('nay')\n >>> res1.expect('not ok')\n 'yay'\n >>> res2.expect('not ok')\n Traceback (most recent call last):\n File \"\", line 1, in \n File \"C:\\project\\result\\result.py\", line 101, in expect\n raise UnwrapError(message)\n result.result.UnwrapError: not ok\n\nA default value can be returned instead by using `unwrap_or`::\n\n >>> res1 = Ok('yay')\n >>> res2 = Err('nay')\n >>> res1.unwrap_or('default')\n 'yay'\n >>> res2.unwrap_or('default')\n 'default'\n\n\nLicense\n-------\n\nMIT License\n\n\n",
"description_content_type": "",
"docs_url": null,
"download_url": "",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/dbrgn/result",
"keywords": "rust result enum",
"license": "MIT",
"maintainer": "",
"maintainer_email": "",
"name": "result",
"package_url": "https://pypi.org/project/result/",
"platform": "",
"project_url": "https://pypi.org/project/result/",
"project_urls": {
"Homepage": "https://github.com/dbrgn/result"
},
"release_url": "https://pypi.org/project/result/0.4.0/",
"requires_dist": [
"typing ; python_version < \"3.5\""
],
"requires_python": "",
"summary": "A rust-like result type for Python",
"version": "0.4.0"
},
"last_serial": 5153612,
"releases": {
"0.1.0": [
{
"comment_text": "",
"digests": {
"md5": "b89e3a228356e5ab2e82ff9ae82f8287",
"sha256": "b9658d70af4449d1112131984c437f96331c1212696a6fe15bce32a6cc47ac2a"
},
"downloads": -1,
"filename": "result-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b89e3a228356e5ab2e82ff9ae82f8287",
"packagetype": "bdist_wheel",
"python_version": "3.5",
"requires_python": null,
"size": 6063,
"upload_time": "2015-12-14T14:07:21",
"url": "https://files.pythonhosted.org/packages/9b/a9/0e6bcff2a78cd34041ced965a923b306d4e5850f95743bd8af8b9efbc5ba/result-0.1.0-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "d74a52cdefb444dfc688e34aea8d494a",
"sha256": "7753bf3da1927a56f51b7471e248dbcf9adf5dc9c4d12556e48cfefcc31d32f7"
},
"downloads": -1,
"filename": "result-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "d74a52cdefb444dfc688e34aea8d494a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3541,
"upload_time": "2015-12-14T14:07:09",
"url": "https://files.pythonhosted.org/packages/1d/27/48abc77c8d10e54f095f2ed41ab02f6030f3d75474369a1073bee813478f/result-0.1.0.tar.gz"
}
],
"0.1.1": [
{
"comment_text": "",
"digests": {
"md5": "7d5a3e2009b420055b25ed9732130a1b",
"sha256": "566aa192f96631f407cef595d942d512b4e19239f29a486620560735914c6b57"
},
"downloads": -1,
"filename": "result-0.1.1-py2-none-any.whl",
"has_sig": false,
"md5_digest": "7d5a3e2009b420055b25ed9732130a1b",
"packagetype": "bdist_wheel",
"python_version": "2.7",
"requires_python": null,
"size": 6124,
"upload_time": "2015-12-14T14:12:10",
"url": "https://files.pythonhosted.org/packages/af/4e/6b7b1388cbd3dd93d2b7e79621753725ae30059595c9e0383ab971dde2f1/result-0.1.1-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "3ab7cf09cc4449d1288f640628b0c03a",
"sha256": "65d8479929189be6533d6dfb4ac6c60220f3587dc13debde6a7678ce098b3565"
},
"downloads": -1,
"filename": "result-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3ab7cf09cc4449d1288f640628b0c03a",
"packagetype": "bdist_wheel",
"python_version": "3.5",
"requires_python": null,
"size": 6123,
"upload_time": "2015-12-14T14:11:49",
"url": "https://files.pythonhosted.org/packages/32/2c/f82ab8d4163473d181885187d23b4e567cbb3c97fd9fa758f795abd80fea/result-0.1.1-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "36dfdc828502cb385a0c6071f6c027e7",
"sha256": "2b104296a1b326167f262a33f177ddebae0f8c91d9d8ecea5e16dc115feb62ee"
},
"downloads": -1,
"filename": "result-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "36dfdc828502cb385a0c6071f6c027e7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3570,
"upload_time": "2015-12-14T14:11:27",
"url": "https://files.pythonhosted.org/packages/b5/23/128679988640f51436a13043e9684adb0640bb9f9f591be19c07a248d97e/result-0.1.1.tar.gz"
}
],
"0.2.0": [
{
"comment_text": "",
"digests": {
"md5": "c8827aff962b616ee48a62b5c4695147",
"sha256": "56d347a8cfcff699b58d8888da8ca33a219853466fdfd83f4429619a351b261c"
},
"downloads": -1,
"filename": "result-0.2.0-py2.py3-none-any.whl",
"has_sig": true,
"md5_digest": "c8827aff962b616ee48a62b5c4695147",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 6258,
"upload_time": "2016-05-05T07:10:02",
"url": "https://files.pythonhosted.org/packages/f5/5b/aa17fd0853fe7c7aa8490ca46a18d87eef5b256b6b08ee72abdc2b377362/result-0.2.0-py2.py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "566b7aa89fda871cc44824a1864b7ac9",
"sha256": "78a0bed8c6afae74fa58f43390dc7f50ee6ec601a2e6a3e0168d89451b516996"
},
"downloads": -1,
"filename": "result-0.2.0.tar.gz",
"has_sig": true,
"md5_digest": "566b7aa89fda871cc44824a1864b7ac9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3752,
"upload_time": "2016-05-05T07:10:23",
"url": "https://files.pythonhosted.org/packages/46/d8/0286512923024c30daeb3644b3269cacc99ac6bf80b12e630f0342ccccbc/result-0.2.0.tar.gz"
}
],
"0.2.2": [
{
"comment_text": "",
"digests": {
"md5": "be4d21adc48df36b18a0a9ec709c9688",
"sha256": "d0210c5e79798ab7e9fdc22d6c0561d406cd5d569e227d0985c8cba4fbb4d284"
},
"downloads": -1,
"filename": "result-0.2.2-py2.py3-none-any.whl",
"has_sig": true,
"md5_digest": "be4d21adc48df36b18a0a9ec709c9688",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 6317,
"upload_time": "2016-09-21T06:47:23",
"url": "https://files.pythonhosted.org/packages/c6/8b/ae6bdc68b41126de61b3825ead968a0f6302c3752a7ff1722910b0abddc8/result-0.2.2-py2.py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "11abe30f1c9568573c63867c38b012b0",
"sha256": "ec2d1404b20d9a8fc8c14ffdc7f9ebcf34b614208267997dcb5d917c9f78612b"
},
"downloads": -1,
"filename": "result-0.2.2.tar.gz",
"has_sig": true,
"md5_digest": "11abe30f1c9568573c63867c38b012b0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3732,
"upload_time": "2016-09-21T06:47:26",
"url": "https://files.pythonhosted.org/packages/18/b9/049bb2a6cee1d0dd95bf35579735b6074a51703f955d8b02ccd491b39d61/result-0.2.2.tar.gz"
}
],
"0.3.0": [
{
"comment_text": "",
"digests": {
"md5": "fbf2f7e1a3493bc4ab05b698895bfd79",
"sha256": "e947cf0e768913ef66d135139f0bed5b48ebec4d87ce3c76c29ff794e0a7d54f"
},
"downloads": -1,
"filename": "result-0.3.0-py2.py3-none-any.whl",
"has_sig": true,
"md5_digest": "fbf2f7e1a3493bc4ab05b698895bfd79",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 6993,
"upload_time": "2017-07-12T20:57:20",
"url": "https://files.pythonhosted.org/packages/86/99/b1ec36110856f740d8304437816bd88f9aa2b3e506697881bb2b7c9ca936/result-0.3.0-py2.py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "d7853082fcfb416597199aef34bc907f",
"sha256": "ffa75336a4c269211e52192725db268d2ad95c6dd900846a0d08aaa3b3046321"
},
"downloads": -1,
"filename": "result-0.3.0.tar.gz",
"has_sig": true,
"md5_digest": "d7853082fcfb416597199aef34bc907f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4462,
"upload_time": "2017-07-12T20:57:21",
"url": "https://files.pythonhosted.org/packages/61/58/a5567e284eb25f11a2e412e4f5686a8548b57b1f718c54b3fc2ad1d65767/result-0.3.0.tar.gz"
}
],
"0.4.0": [
{
"comment_text": "",
"digests": {
"md5": "9217ad5b9198cba7f5758985fad47d72",
"sha256": "582c6c464b188ad9f13bc1cacc67d02502ed77b92acbcda9bc541c6cb049a2f9"
},
"downloads": -1,
"filename": "result-0.4.0-py3-none-any.whl",
"has_sig": true,
"md5_digest": "9217ad5b9198cba7f5758985fad47d72",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5215,
"upload_time": "2019-04-17T07:10:58",
"url": "https://files.pythonhosted.org/packages/cb/1c/2046b5cf6640d20b7d1b2d1307a02ecd565a2ecd83c274db9da7f0ccc872/result-0.4.0-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "cf2614a18a6ba60cdb467bd879e004a8",
"sha256": "2e3d086e0dad69b8bd3f34939822872a6b5ea4e7f7ba437182cbc0417d1d4379"
},
"downloads": -1,
"filename": "result-0.4.0.tar.gz",
"has_sig": true,
"md5_digest": "cf2614a18a6ba60cdb467bd879e004a8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4697,
"upload_time": "2019-04-17T07:11:00",
"url": "https://files.pythonhosted.org/packages/d8/b0/6e709c3692e22c1ba3d3697434b05a8d5887519646aff394d4a2b08c533e/result-0.4.0.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "9217ad5b9198cba7f5758985fad47d72",
"sha256": "582c6c464b188ad9f13bc1cacc67d02502ed77b92acbcda9bc541c6cb049a2f9"
},
"downloads": -1,
"filename": "result-0.4.0-py3-none-any.whl",
"has_sig": true,
"md5_digest": "9217ad5b9198cba7f5758985fad47d72",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5215,
"upload_time": "2019-04-17T07:10:58",
"url": "https://files.pythonhosted.org/packages/cb/1c/2046b5cf6640d20b7d1b2d1307a02ecd565a2ecd83c274db9da7f0ccc872/result-0.4.0-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "cf2614a18a6ba60cdb467bd879e004a8",
"sha256": "2e3d086e0dad69b8bd3f34939822872a6b5ea4e7f7ba437182cbc0417d1d4379"
},
"downloads": -1,
"filename": "result-0.4.0.tar.gz",
"has_sig": true,
"md5_digest": "cf2614a18a6ba60cdb467bd879e004a8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4697,
"upload_time": "2019-04-17T07:11:00",
"url": "https://files.pythonhosted.org/packages/d8/b0/6e709c3692e22c1ba3d3697434b05a8d5887519646aff394d4a2b08c533e/result-0.4.0.tar.gz"
}
]
}