{"id":18832203,"url":"https://github.com/crxwns/results","last_synced_at":"2025-07-18T06:37:05.441Z","repository":{"id":247399625,"uuid":"823249847","full_name":"crxwns/results","owner":"crxwns","description":"Partial implementation of Rust's Result- and Option-Type in Python","archived":false,"fork":false,"pushed_at":"2024-07-15T10:18:37.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-14T02:02:03.277Z","etag":null,"topics":["option-type","python","result-type"],"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/crxwns.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,"zenodo":null}},"created_at":"2024-07-02T17:04:24.000Z","updated_at":"2024-07-15T10:18:40.000Z","dependencies_parsed_at":"2025-05-22T16:15:28.872Z","dependency_job_id":"18635275-6ac5-4462-a078-a9284e0ba1b7","html_url":"https://github.com/crxwns/results","commit_stats":null,"previous_names":["crxwns/results"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/crxwns/results","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crxwns%2Fresults","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crxwns%2Fresults/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crxwns%2Fresults/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crxwns%2Fresults/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crxwns","download_url":"https://codeload.github.com/crxwns/results/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crxwns%2Fresults/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265711330,"owners_count":23815513,"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":["option-type","python","result-type"],"created_at":"2024-11-08T01:57:11.174Z","updated_at":"2025-07-18T06:37:05.400Z","avatar_url":"https://github.com/crxwns.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Results\n\nImplementation of Rust's Result- and Option-Type in Python.\n\nCan be used to mimic similar behaviour as Rust to propagate Exceptions to the caller instead of handling them in the method itself and use default values if there is an `Error` or the `Option` is `None`.\n\n```python\nfrom dataclasses import dataclass\n\nimport tomllib\n\nfrom results import Err, Ok, Result\n\n\n@dataclass\nclass Config:\n    debug: bool\n    value: int\n\n\ndef parse_config_from_toml_string(config_str: str) -\u003e Result[Config, Exception]:\n    \"\"\"Takes in a TOML string and returns a Result[Config, Exception]\"\"\"\n    try:\n        data = tomllib.loads(config_str)\n    except tomllib.TOMLDecodeError as e:\n        return Err(e)\n\n    tool = data.get(\"tool\")\n\n    if not tool:\n        return Err(ValueError(\"No configuration for tool in config.\"))\n\n    try:\n        config = Config(**tool)\n    except TypeError as e:\n        return Err(e)\n\n    return Ok(config)\n\n\nif __name__ == \"__main__\":\n    valid_config_str = \"\"\"[tool]\n    debug = true\n    value = 10\"\"\"\n\n    invalid_config_str = \"\"\"[wrong]\n    debug = true\n    value = 10\"\"\"\n\n    valid_config_result = parse_config_from_toml_string(config_str=valid_config_str)\n    invalid_config_result = parse_config_from_toml_string(config_str=invalid_config_str)\n\n    # You can match on the result\n\n    match valid_config_result:\n        case Err(err):\n            print(err)\n        case Ok(config):\n            print(config)\n\n    # Use a default for the config if Err\n\n    print(invalid_config_result.unwrap_or(Config(debug=False, value=2)))\n\n```\n\n# Examples\n\n- [Option[T]](examples/option_example.py)\n- [Result[T, E]](examples/result_example.py)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrxwns%2Fresults","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrxwns%2Fresults","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrxwns%2Fresults/lists"}