{"id":24534382,"url":"https://github.com/winand/python-option","last_synced_at":"2026-05-19T11:06:13.931Z","repository":{"id":272660147,"uuid":"917093786","full_name":"Winand/python-option","owner":"Winand","description":"Implementation of Scala Option in Python","archived":false,"fork":false,"pushed_at":"2025-01-15T20:36:08.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-15T22:42:01.669Z","etag":null,"topics":["maybe","option","python","scala"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Winand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-01-15T10:45:03.000Z","updated_at":"2025-01-15T20:36:09.000Z","dependencies_parsed_at":"2025-01-15T22:42:06.157Z","dependency_job_id":"d74e0526-4077-4d0d-83d8-cebfbf2625d0","html_url":"https://github.com/Winand/python-option","commit_stats":null,"previous_names":["winand/python-option"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Winand%2Fpython-option","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Winand%2Fpython-option/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Winand%2Fpython-option/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Winand%2Fpython-option/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Winand","download_url":"https://codeload.github.com/Winand/python-option/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243797610,"owners_count":20349432,"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":["maybe","option","python","scala"],"created_at":"2025-01-22T11:17:03.006Z","updated_at":"2026-05-19T11:06:08.903Z","avatar_url":"https://github.com/Winand.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Option\nImplementation of Scala Option in Python.\n\n```python\n    from option import Option, none, _\n\n    # return option value if it's not empty\n    val1 = 1\n    opt1 = Option(val1)\n    print(\"value is\", opt1.get_or_else(\"hello\"))\n\n    # if Option1 is empty return Option2\n    opt2 = Option(1.2)\n    opt3 = none.or_else(opt2)\n    print(opt3)\n\n    # fold == map + get_or_else\n    opt4 = opt3.fold(8, lambda v: v*2)\n    opt4_alt = opt3.map(lambda v: v*2).get_or_else(8)\n    print(opt4, \"==\", opt4_alt)\n\n    # map and flat_map\n    opt5 = Option(\"hello\")\n    print(opt5.flat_map(lambda v: Option(v * 2)))  # Some('hellohello')\n    print(opt5.map(lambda v: v * 2))  # Some('hellohello')\n\n    # zip options, convert to list\n    opt6 = Option(\"hi\").zip(Option('xx'))\n    print(list(opt6))\n\n    # Using underscore object:\n    class MyObj:\n        hello = \"hi\"\n\n        def bye(self):\n            return \"see you\"\n    opt7 = Option(MyObj())\n    print(opt7.fold(\"\", _.hello))  # hi\n    print(opt7.fold(\"\", _.bye))  # see you\n    print(Option(9).fold(0, 2 * _))  # 18\n\n    # filter option value\n    print(Option(9).filter(_ \u003e 50).get_or_else(0))  # 0\n```\n\n# See also\n- [Is there a Python equivalent for Scala's Option or Either?](https://stackoverflow.com/q/22992433)\n- _returns_ [Maybe container](https://github.com/dry-python/returns?tab=readme-ov-file#maybe-container)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinand%2Fpython-option","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinand%2Fpython-option","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinand%2Fpython-option/lists"}