Skip to main content

simple-result

Supported Python versions Package version Publish License

A very simple, fully typed Rust-like Result type for Python 3.

If you need a Result type only for checking if an operation succeeded or failed, and don't need to perform special actions like chaining operations, mapping, etc., then this library is for you.

If you are looking for a more feature-rich Result type, check out rustedpy/result.

Installation

# Using pip
pip install simple-result

# Using Poetry
poetry add simple-result

# Using uv
uv add simple-result

Usage

import random

from simple_result import Err, Ok, Result

def fetch_data() -> Result[str, ConnectionError]:
    fetched = random.choice([True, False])
    if fetched:
        return Ok('Data fetched!')
    return Err(ConnectionError('Error fetching data!'))

Check if the result is Ok or Err using type narrowing:

if res := fetch_data():
    print(res.value) # "Data fetched!"
    print(res.error) # None
else:
    print(res.error) # "Error fetching data!"
    print(res.value) # None

Or using match:

match fetch_data():
    case Ok(data):
        print(data) # "Data fetched!"
    case Err(error):
        print(error) # "Error fetching data!"

match fetch_data():
    case Ok(data):
        print(data) # "Data fetched!"
    case Err(error, code):
        print(error, code) # "Error fetching data! 1"

Call .unwrap_value() to get the value or raise an UnwrapError if the result is Err:

from simple_result import UnwrapError

try:
    res = Err(ConnectionError('Error fetching data!'))
    print(res.unwrap_value())
except UnwrapError as exc:
    print(str(exc)) # called `Result.unwrap_value()` on an `Err` value
    print(exc.result.error) # "Error fetching data!"

Call .unwrap_error() to get the error or raise an UnwrapError if the result is Ok:

try:
    res = Ok('Data fetched!')
    print(res.unwrap_error())
except UnwrapError as exc:
    print(str(exc)) # called `Result.unwrap_error()` on an `Ok` value
    print(exc.result.value) # "Data fetched!"

Compare results:

assert Ok(1) == Ok(1)
assert Ok(1) != Ok(2)

exc = ValueError('error')
assert Err(exc) == Err(exc)

other_exc = ValueError('other error')
assert Err(exc) != Err(other_exc)

Check if the result is Ok or Err using isinstance:

from simple_result import ResultOption

res = fetch_data()
assert isinstance(res, ResultOption)
assert isinstance(res, (Ok, Err))

Contributing

See the contribution guidelines.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Support

If you find this project useful, give it a ⭐ on GitHub!

Metadata

Release files for simple-result 0.2.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 simple-result 0.2.0
File Size Uploaded
simple_result-0.2.0.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple-result 0.2.0
File Interpreter ABI Platform
simple_result-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 kB

Release files / simple_result-0.2.0.tar.gz

Download URL simple_result-0.2.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3468547e36f8079c3b0e5325b3b2018e3c32fd61de9d0f2cd8d36f852d761d71
BLAKE2b-256 checksum
How to use checksums
b3f7e1ea503bfd0b456f2c1df5369d4070700e9e2ca1451f6ccd2998f4d6b70c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 16, 2025.

Transparency log

Release files / simple_result-0.2.0-py3-none-any.whl

Download URL simple_result-0.2.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d15e7a64f0c6bcb4ea83f6cd055cbfb29786649994428c7c64c4e0ddc96d28ea
BLAKE2b-256 checksum
How to use checksums
1bffff55a6e2ad190558fe25c933103c565914eb780f767a315613844a16561b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 16, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

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