Key Features
- Result Type: Rust-style
Result[T, E]for explicit error handling without exceptions - Ok/Err Variants: Type-safe success and error cases with pattern matching methods
- Panic Mechanism: Rust-like
panic()for unrecoverable errors with detailed stack traces - Decorator Utilities: Convert existing functions to return Results with
@resultifyand@resultify_catch_only - Chainable Operations: Functional methods like
map,map_err,unwrap_or, and more - Fully Typed: Complete type hints for excellent IDE support and type checking
Installation
# using pip
pip install pa-py-rs
# using uv
uv add pa-py-rs
NOTE: Python 3.7 or higher is required
Examples
Result
Basic Result Usage
from pa_py_rs import Result, Ok, Err
def divide(a: float, b: float) -> Result[float, str]:
if b == 0:
return Err("Division by zero")
return Ok(a / b)
result = divide(10, 2)
print(result) # Ok(5.0)
if result.is_ok():
print(f"Success: {result.unwrap()}") # Success: 5.0
result = divide(10, 0)
print(result) # Err(Division by zero)
if result.is_err():
print(f"Error: {result.unwrap_err()}") # Error: Division by zero
Using decorators
from pa_py_rs import resultify, resultify_catch_only
# Convert any function to return Result
# Automatically catch errors and wrap in Err(...)
@resultify
def parse_int(value: str) -> int:
return int(value)
result = parse_int("123") # Ok(123)
result = parse_int("abc") # Err(...)
# For functions already returning Result
# Automatically catch errors and wrap in Err(...)
@resultify_catch_only
def safe_divide(a: float, b: float) -> Result[float, str]:
return Ok(a / b)
result = safe_divide(10, 2) # Ok(5.0)
result = safe_divide(10, 0) # Err("cannot divide by zero")
Chaining Operations
from pa_py_rs import Ok, Err
result = Err("error").unwrap_or(0)
print(result) # 0
result = (Ok(10)
.map(lambda x: x * 2)
.map(lambda x: x + 5)
.unwrap())
print(result) # 25
Metadata
Release files for pa-py-rs 0.1.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 |
|---|---|---|---|---|
| pa_py_rs-0.1.2.tar.gz | 4.3 kB | Without provenance | Details for pa_py_rs-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pa_py_rs-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for pa_py_rs-0.1.2-py3-none-any.whl |
Total release size: 9.8 kB
Release files / pa_py_rs-0.1.2.tar.gz
| Download URL | pa_py_rs-0.1.2.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67bff2b72c306d7ebee17b027fe245b2cc838bc935baf4d09a36bcd378cf2a26
|
|
BLAKE2b-256 checksum How to use checksums |
e57d10f9942fe303fb1267761efa8348e0a94ab81b13f9575efbbfb0d98b1fee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Release files / pa_py_rs-0.1.2-py3-none-any.whl
| Download URL | pa_py_rs-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d17eea9f551a2d3e4a1bc959856ef9ae3338565fc65367cb5fbc0ae99cfccbc3
|
|
BLAKE2b-256 checksum How to use checksums |
2a85378efd0d9185176e6027a51ddafbe6fc91e16b13ef82946b6923554c2365
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Security for pa-py-rs 0.1.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.