Show HN: Resilient-result – Rust-style errors in Python
1 iteebz 0 7/25/2025, 12:01:12 PM github.com ↗
I built `resilient-result` after getting tired of try/catch blocks scattered everywhere in production Python code. It's a zero-dependency library that brings Rust-style Result types to Python with a clean decorator API and seamless async support.
Key features:
- @resilient decorator converts any sync or async function to return Result[T, E] instead of raising exceptions
- Rust-style Ok() and Err() constructors for familiarity
- Guard clause patterns for clean early returns
- Full generic typing support for IDEs and type-checkers
- Zero dependencies, Python 3.8+
Example:
from resilient_result import Result, resilient
@resilient
def divide(a: int, b: int) -> int:
return a // b
result = divide(10, 0) # Returns Result.fail("division by zero")
if result.success:
print(f"Result: {result.data}")
else:
print(f"Error: {result.error}")
The guard clause pattern shines in multi-step processes: def multi_step_process(data: str) -> Result[str, str]:
step1_result = process_step1(data)
if not step1_result.success:
return step1_result # Early return on failure
step2_result = process_step2(step1_result.data)
if not step2_result.success:
return step2_result
return Result.ok(step2_result.data + "_complete")
PyPI: https://pypi.org/project/resilient-result/GitHub: https://github.com/iteebz/resilient-result
Would love feedback from the community! Is this a pattern you'd use in production Python?
No comments yet