
Research
/Security News
npm Author Qix Compromised via Phishing Email in Major Supply Chain Attack
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
A Rust-inspired, ergonomic Result type for Python with first-class async support, pattern matching, and a clean API.
A Schrödinger's Cat for Python error handling: your result is both alive and dead—until you unwrap it.
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.
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.
Python 3.8+ is required.
You can install rustico
using pip:
pip install rustico
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.
rustico
is distributed under the MIT License. See the LICENSE file for more information.
FAQs
A Rust-inspired, ergonomic Result type for Python with first-class async support, pattern matching, and a clean API.
We found that rustico demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.