Skip to main content

Option

Build Status codecov

Rust-like Option and Result 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

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:

pip install option

Documentation

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

License

MIT

Metadata

Release files for option 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for option 0.5.0
File Size Uploaded Provenance Actions
option-0.5.0.tar.gz 7.7 kB Without provenance Details for option-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for option 0.5.0
File Interpreter ABI Platform Actions
option-0.5.0-py3-none-any.whl Python 3 none any Details for option-0.5.0-py3-none-any.whl

Total release size: 19.4 kB

Release files / option-0.5.0.tar.gz

Download URL option-0.5.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ffb784953918553dfd45de712cde562b12eb451244b32c54dae7356d24fb6425
BLAKE2b-256 checksum
How to use checksums
2b7a4bf7c523e575803e4906cf9a7fd729e985dc053cb0826c3dbb8adbb3383f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.17 CPython/3.7.1 Linux/4.15.0-1028-gcp

Release files / option-0.5.0-py3-none-any.whl

Download URL option-0.5.0-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
941a19bde0691706885be8494668c7085f93faa753823ce1c7a49e2b7d25a229
BLAKE2b-256 checksum
How to use checksums
d2366b2432b20902525bd10f678eee94a88f7b72fb8146ba7ce0a51200063366
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.17 CPython/3.7.1 Linux/4.15.0-1028-gcp

Security for option 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page