Skip to main content

Rust like Option type in Python

Project description

Option

Build Status codecov

A rust-like Option type in Python, slotted and fully typed.

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

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

Quick Start

from option import Some, NONE, Option
from requests import get

def call_api(url, params) -> Option[dict]:
    result = get(url, params)
    if result.status_code == 200:
        return Some(result.json())
    return NONE

# Instead of checking for None, the NONE case is always dealt with.
dict_len = call_api(url, params).map(len)

Install

Option can be installed from PyPi:

pip install option

Documentation

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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

option-0.2.0.tar.gz (6.8 kB view hashes)

Uploaded Source

Built Distribution

option-0.2.0-py3-none-any.whl (30.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page