rustico
A Schrödinger's Cat for Python error handling: your result is both alive and dead—until you unwrap it.
What is rustico?
rustico brings the power and elegance of Rust's Result type to Python. Every operation is either a success (Ok) or a failure (Err), and you must explicitly handle both. No more try/except hell—just beautiful, predictable, and composable error handling.
Schrödinger's Cat: The Metaphor
Imagine every function call as a box containing Schrödinger's cat. Until you open (unwrap) the box, the cat is both alive (Ok) and dead (Err). With rustico, you don't have to guess or hope—when you unwrap the result, you'll know exactly what you got, and you'll handle both cases explicitly.
Key Features
- 🔒 Can't Forget Error Handling: The type system forces you to handle both cases
- 📍 Precise Error Information: Know exactly what and where things failed
- 🧩 Composable: Chain operations without nested try/except blocks
- 🎯 Early Exit: Stop processing on first error automatically
- 🔍 Type Safe: Your IDE knows about both success and error cases
- ⚡ Async Support: First-class support for async/await
- 🧪 Test Friendly: Easily mock and test error conditions
Installation
Python 3.8+ is required.
You can install rustico using pip:
pip install rustico
Quick Example
Here's a taste of how rustico simplifies error handling:
from rustico import Ok, Err, Result
def divide(numerator: float, denominator: float) -> Result[float, str]:
"""Divides two numbers, returning an Ok result or an Err if division by zero occurs."""
if denominator == 0:
return Err("Cannot divide by zero!")
return Ok(numerator / denominator)
# --- Usage Examples ---
# Successful division
result_success = divide(10, 2)
if result_success.is_ok():
print(f"Success: {result_success.unwrap()}") # Output: Success: 5.0
# Failed division
result_failure = divide(10, 0)
if result_failure.is_err():
print(f"Error: {result_failure.unwrap_err()}") # Output: Error: Cannot divide by zero!
# Chaining operations
def multiply_by_two(value: float) -> Result[float, str]:
return Ok(value * 2)
chained_result = divide(20, 4).and_then(multiply_by_two)
if chained_result.is_ok():
print(f"Chained Success: {chained_result.unwrap()}") # Output: Chained Success: 10.0
failed_chained_result = divide(20, 0).and_then(multiply_by_two)
if failed_chained_result.is_err():
print(f"Chained Error: {failed_chained_result.unwrap_err()}") # Output: Chained Error: Cannot divide by zero!
For detailed documentation, see the full documentation.
License
rustico is distributed under the MIT License. See the LICENSE file for more information.
Metadata
Release files for rustico 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rustico-1.0.2.tar.gz | 23.6 kB | Without provenance | Details for rustico-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rustico-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for rustico-1.0.2-py3-none-any.whl |
Total release size: 44.8 kB
Release files / rustico-1.0.2.tar.gz
| Download URL | rustico-1.0.2.tar.gz |
|---|---|
| Size | 23.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
168e85a378387da1aba5ce943d9f3d077842196a7ced187b9c8a460da260128f
|
|
BLAKE2b-256 checksum How to use checksums |
d9601fc8d0f01b09b024cf8b82a73761fe744a60660e6393e6327aa75ec8be80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.20
|
Release files / rustico-1.0.2-py3-none-any.whl
| Download URL | rustico-1.0.2-py3-none-any.whl |
|---|---|
| Size | 21.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2fe92218fde2637b8a15008fbc285094057a0581de82aa04b124aef01b89abae
|
|
BLAKE2b-256 checksum How to use checksums |
cb3bbd0927a35abda342f9afdcee9a538ef7a403d5cf1615cce5e82b867f5cdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.20
|
Security for rustico 1.0.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.