Option
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)
| File | Size | Uploaded | |
|---|---|---|---|
| option-0.5.0.tar.gz | 7.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| option-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
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
|