result
A Rust-like result type for Python
What it is and what it does
Result is a type-safe container for representing success or failure outcomes without relying on exceptions. It provides Ok and Err classes that wrap values, letting you encode success or error states directly in function return types. The package is inspired by Rust's Result enum and fully type-annotated, making it compatible with MyPy and other type checkers for compile-time safety.
You use it by returning Ok(value) for success or Err(error) for failure, then checking the result with isinstance, is_ok/is_err functions, or Python 3.10+ match statements. It includes utility methods like map, unwrap, expect, and unwrap_or to transform and extract values. The design encourages explicit error handling at call sites rather than implicit exception propagation, making error paths visible in code.
Use it for:
- Building APIs or functions where error cases are part of the normal control flow and should be handled explicitly rather than caught.
- Type-checking error handling with MyPy by narrowing result types through isinstance checks to ensure all branches are covered.
- Replacing tuple-based error returns (like returning (value, error_msg)) with a clearer, type-safe Result[T, E] signature.
- Chaining operations on results using map and map_err to transform values or errors without nested conditionals.
- Porting Rust code to Python while preserving the Result pattern for consistency and familiar error semantics.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a Rust-inspired Result type for Python that represents either a success value (Ok) or an error (Err), enabling explicit error handling without exceptions.
Yes, if you prefer explicit error handling and type safety over exceptions. The package is stable, has low install friction, and is widely used (top 5000 PyPI). However, note that the repository is archived and abandoned—while the code is mature and unlikely to need updates, you will not receive maintenance or security patches. Use it for new projects only if your team is comfortable with that trade-off.
Install
result on PyPI
pip
pip install resultuv
uv add resultpoetry
poetry add resultInstalling result
Before you install
Low install friction with a single lightweight dependency (typing-extensions). Repository is archived and maintenance is abandoned as of 803 days since last release, though the package remains stable and widely used.
License in practice
MIT license permits unrestricted use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
pip install result
from result import Ok, Err, Result
def divide(a: int, b: int) -> Result[int, str]:
if b == 0:
return Err("Cannot divide by zero")
return Ok(a // b)
result = divide(10, 2)
if isinstance(result, Ok):
print(result.ok_value) # 5
else:
print(result.err_value)
Verify before relying
- Whether the archived repository status affects long-term security patch availability or community support for edge cases.
- Performance characteristics when used in high-throughput or latency-sensitive code paths compared to exception-based patterns.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — typing-extensions |
| Maintenance | abandoned — 803 days since the last release |
| Last repo commit | (repository archived) |
| First released | |
| Downloads | 2,520,319/month — #3,024 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: result-0.17.0-py3-none-any.whl
Keywords: rust, result, enum
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
setuptools-rustsetuptools-rust is a setuptools plugin that…
permissive · top 5,000 on PyPI
regressProvides Python bindings to the Rust regress…
permissive · top 5,000 on PyPI
msgfyConverts Python Exception instances into…
permissive · top 15,000 on PyPI
python-statusProvides named constants for HTTP status codes…
permissive · top 15,000 on PyPI
pyre-extensionsProvides typing extensions for the Pyre type…
permissive · top 5,000 on PyPI
better-exceptionsFormats Python exceptions with syntax…
unclear · top 15,000 on PyPI
cargo-lambdacargo-lambda is a Cargo subcommand that…
permissive · top 15,000 on PyPI
numeraryProvides runtime-checkable protocols and type…
permissive · top 15,000 on PyPI
infinityProvides an Infinity class that can be compared…
permissive · top 15,000 on PyPI
tree-sitter-rustProvides a Rust language grammar for…
permissive · top 5,000 on PyPI