option


Nameoption JSON
Version 2.1.0 PyPI version JSON
download
home_pagehttps://mat1g3r.github.io/option/
SummaryRust like Option and Result types in Python
upload_time2022-04-18 15:33:45
maintainer
docs_urlNone
authorPeijun Ma
requires_python>=3.7,<4
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Option
[![CircleCI](https://circleci.com/gh/MaT1g3R/option/tree/master.svg?style=svg)](https://circleci.com/gh/MaT1g3R/option/tree/master)

Rust-like [Option](https://doc.rust-lang.org/std/option/enum.Option.html) and [Result](https://doc.rust-lang.org/std/result/enum.Result.html) types in Python, slotted and fully typed.

An `Option` type represents an optional value, every `Option` is either `Some` and contains Some value, or `NONE`

A `Result` type represents a value that might be an error. Every `Result` is either `Ok` and contains a success value, or `Err` and contains an error value.

Using an `Option` type forces you to deal with `None` values in your code and increase type safety.

Using a `Result` type simplifies error handling and reduces `try` `except` blocks.

## Quick Start
```Python
from option import Result, Option, Ok, Err
from requests import get


def call_api(url, params) -> Result[dict, int]:
    result = get(url, params)
    code = result.status_code
    if code == 200:
        return Ok(result.json())
    return Err(code)


def calculate(url, params) -> Option[int]:
    return call_api(url, params).ok().map(len)


dict_len = calculate('https://example.com', {})
```

## Install
Option can be installed from PyPi:
```bash
pip install option
```

## Documentation
The documentation lives at https://mat1g3r.github.io/option/

## License
MIT

            

Raw data

            {
    "_id": null,
    "home_page": "https://mat1g3r.github.io/option/",
    "name": "option",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4",
    "maintainer_email": "",
    "keywords": "",
    "author": "Peijun Ma",
    "author_email": "peijun.ma@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/15/7a/3622379bd82f70a0b88779566c4847f167ae54103187922b69ad63d3c3b2/option-2.1.0.tar.gz",
    "platform": null,
    "description": "# Option\n[![CircleCI](https://circleci.com/gh/MaT1g3R/option/tree/master.svg?style=svg)](https://circleci.com/gh/MaT1g3R/option/tree/master)\n\nRust-like [Option](https://doc.rust-lang.org/std/option/enum.Option.html) and [Result](https://doc.rust-lang.org/std/result/enum.Result.html) types in Python, slotted and fully typed.\n\nAn `Option` type represents an optional value, every `Option` is either `Some` and contains Some value, or `NONE`\n\nA `Result` type represents a value that might be an error. Every `Result` is either `Ok` and contains a success value, or `Err` and contains an error value.\n\nUsing an `Option` type forces you to deal with `None` values in your code and increase type safety.\n\nUsing a `Result` type simplifies error handling and reduces `try` `except` blocks.\n\n## Quick Start\n```Python\nfrom option import Result, Option, Ok, Err\nfrom requests import get\n\n\ndef call_api(url, params) -> Result[dict, int]:\n    result = get(url, params)\n    code = result.status_code\n    if code == 200:\n        return Ok(result.json())\n    return Err(code)\n\n\ndef calculate(url, params) -> Option[int]:\n    return call_api(url, params).ok().map(len)\n\n\ndict_len = calculate('https://example.com', {})\n```\n\n## Install\nOption can be installed from PyPi:\n```bash\npip install option\n```\n\n## Documentation\nThe documentation lives at https://mat1g3r.github.io/option/\n\n## License\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Rust like Option and Result types in Python",
    "version": "2.1.0",
    "project_urls": {
        "Homepage": "https://mat1g3r.github.io/option/",
        "Repository": "https://github.com/MaT1g3R/option"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0e7a4ece49ebcb33fc43577538f85406598ec93d5675dfb30331ec586351656",
                "md5": "c0d8751de7743a5027989ea596923adf",
                "sha256": "21ccd9a437dbee0341700367efb68e82065fd7a7dba09f8c3263cf2dc1a2b0e0"
            },
            "downloads": -1,
            "filename": "option-2.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c0d8751de7743a5027989ea596923adf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4",
            "size": 11931,
            "upload_time": "2022-04-18T15:33:44",
            "upload_time_iso_8601": "2022-04-18T15:33:44.627097Z",
            "url": "https://files.pythonhosted.org/packages/b0/e7/a4ece49ebcb33fc43577538f85406598ec93d5675dfb30331ec586351656/option-2.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "157a3622379bd82f70a0b88779566c4847f167ae54103187922b69ad63d3c3b2",
                "md5": "32ac8e5eb0e1cf4eacc186e6a916d6a2",
                "sha256": "9fe95a231e54724d2382a5124b55cd84b82339edf1d4e88d6977cedffbfeadf1"
            },
            "downloads": -1,
            "filename": "option-2.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "32ac8e5eb0e1cf4eacc186e6a916d6a2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4",
            "size": 8042,
            "upload_time": "2022-04-18T15:33:45",
            "upload_time_iso_8601": "2022-04-18T15:33:45.856925Z",
            "url": "https://files.pythonhosted.org/packages/15/7a/3622379bd82f70a0b88779566c4847f167ae54103187922b69ad63d3c3b2/option-2.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-04-18 15:33:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MaT1g3R",
    "github_project": "option",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "lcname": "option"
}
        
Elapsed time: 0.15557s