Metadata-Version: 2.3
Name: pa-py-rs
Version: 0.1.2
Summary: A Python module that brings ergonomic, Rust-inspired utilities like Result, and panics to Python
Author: lalitm1004
Author-email: lalitm1004 <lalitm1004@gmail.com>
License: MIT
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: >=3.7
Project-URL: Issues, https://github.com/lalitm1004/pa-py-rs/issues
Project-URL: Repository, https://github.com/lalitm1004/pa-py-rs
Description-Content-Type: text/markdown

[![PyPI version info](https://img.shields.io/pypi/v/pa-py-rs.svg?style=for-the-badge&logo=pypi&color=yellowgreen&logoColor=white)](https://pypi.python.org/pypi/pa-py-rs)
[![PyPI supported Python versions](https://img.shields.io/pypi/pyversions/pa-py-rs.svg?style=for-the-badge&logo=python&logoColor=white)](https://pypi.python.org/pypi/pa-py-rs)

# 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 `@resultify` and `@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
```bash
# 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
```python
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
```python
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
```python
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
```