rustico


Namerustico JSON
Version 1.0.2 PyPI version JSON
download
home_pageNone
SummaryA Rust-inspired, ergonomic Result type for Python with first-class async support, pattern matching, and a clean API.
upload_time2025-07-18 16:04:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords result rust error-handling async pattern-matching monad decorator type-safety python functional-programming
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # rustico

[![PyPI - Version](https://img.shields.io/pypi/v/rustico.svg?color=purple)](https://pypi.org/project/rustico/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/rustico.svg?color=purple)](https://pypi.org/project/rustico/)
[![License](https://img.shields.io/badge/License-MIT-purple.svg)](https://opensource.org/licenses/MIT)

> **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:

```bash
pip install rustico
```

## Quick Example

Here's a taste of how `rustico` simplifies error handling:

```python
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](docs/index.md).

## License

`rustico` is distributed under the MIT License. See the [LICENSE](LICENSE) file for more information.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "rustico",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "result, rust, error-handling, async, pattern-matching, monad, decorator, type-safety, python, functional-programming",
    "author": null,
    "author_email": "Simon Waiblinger <16225108+simwai@users.noreply.github.com>",
    "download_url": "https://files.pythonhosted.org/packages/d9/60/1fc8d0f01b09b024cf8b82a73761fe744a60660e6393e6327aa75ec8be80/rustico-1.0.2.tar.gz",
    "platform": null,
    "description": "# rustico\n\n[![PyPI - Version](https://img.shields.io/pypi/v/rustico.svg?color=purple)](https://pypi.org/project/rustico/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/rustico.svg?color=purple)](https://pypi.org/project/rustico/)\n[![License](https://img.shields.io/badge/License-MIT-purple.svg)](https://opensource.org/licenses/MIT)\n\n> **A Schr\u00f6dinger's Cat for Python error handling: your result is both alive and dead\u2014until you unwrap it.**\n\n## What is `rustico`?\n\n`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\u2014just beautiful, predictable, and composable error handling.\n\n## Schr\u00f6dinger's Cat: The Metaphor\n\nImagine every function call as a box containing Schr\u00f6dinger'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\u2014when you unwrap the result, you'll know exactly what you got, and you'll handle both cases explicitly.\n\n## Key Features\n\n- \ud83d\udd12 **Can't Forget Error Handling**: The type system forces you to handle both cases\n- \ud83d\udccd **Precise Error Information**: Know exactly what and where things failed\n- \ud83e\udde9 **Composable**: Chain operations without nested try/except blocks\n- \ud83c\udfaf **Early Exit**: Stop processing on first error automatically\n- \ud83d\udd0d **Type Safe**: Your IDE knows about both success and error cases\n- \u26a1 **Async Support**: First-class support for async/await\n- \ud83e\uddea **Test Friendly**: Easily mock and test error conditions\n\n## Installation\n\nPython 3.8+ is required.\n\nYou can install `rustico` using pip:\n\n```bash\npip install rustico\n```\n\n## Quick Example\n\nHere's a taste of how `rustico` simplifies error handling:\n\n```python\nfrom rustico import Ok, Err, Result\n\ndef divide(numerator: float, denominator: float) -> Result[float, str]:\n    \"\"\"Divides two numbers, returning an Ok result or an Err if division by zero occurs.\"\"\"\n    if denominator == 0:\n        return Err(\"Cannot divide by zero!\")\n    return Ok(numerator / denominator)\n\n# --- Usage Examples ---\n\n# Successful division\nresult_success = divide(10, 2)\nif result_success.is_ok():\n    print(f\"Success: {result_success.unwrap()}\") # Output: Success: 5.0\n\n# Failed division\nresult_failure = divide(10, 0)\nif result_failure.is_err():\n    print(f\"Error: {result_failure.unwrap_err()}\") # Output: Error: Cannot divide by zero!\n\n# Chaining operations\ndef multiply_by_two(value: float) -> Result[float, str]:\n    return Ok(value * 2)\n\nchained_result = divide(20, 4).and_then(multiply_by_two)\nif chained_result.is_ok():\n    print(f\"Chained Success: {chained_result.unwrap()}\") # Output: Chained Success: 10.0\n\nfailed_chained_result = divide(20, 0).and_then(multiply_by_two)\nif failed_chained_result.is_err():\n    print(f\"Chained Error: {failed_chained_result.unwrap_err()}\") # Output: Chained Error: Cannot divide by zero!\n```\n\nFor detailed documentation, see the [full documentation](docs/index.md).\n\n## License\n\n`rustico` is distributed under the MIT License. See the [LICENSE](LICENSE) file for more information.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Rust-inspired, ergonomic Result type for Python with first-class async support, pattern matching, and a clean API.",
    "version": "1.0.2",
    "project_urls": {
        "Documentation": "https://github.com/simwai/rustico#readme",
        "Homepage": "https://github.com/simwai/rustico",
        "Source": "https://github.com/simwai/rustico",
        "Tracker": "https://github.com/simwai/rustico/issues"
    },
    "split_keywords": [
        "result",
        " rust",
        " error-handling",
        " async",
        " pattern-matching",
        " monad",
        " decorator",
        " type-safety",
        " python",
        " functional-programming"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cb3bbd0927a35abda342f9afdcee9a538ef7a403d5cf1615cce5e82b867f5cdf",
                "md5": "7a609c94a50f6f7c1dd8570ea2b3b1e9",
                "sha256": "2fe92218fde2637b8a15008fbc285094057a0581de82aa04b124aef01b89abae"
            },
            "downloads": -1,
            "filename": "rustico-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7a609c94a50f6f7c1dd8570ea2b3b1e9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 21166,
            "upload_time": "2025-07-18T16:04:40",
            "upload_time_iso_8601": "2025-07-18T16:04:40.161554Z",
            "url": "https://files.pythonhosted.org/packages/cb/3b/bd0927a35abda342f9afdcee9a538ef7a403d5cf1615cce5e82b867f5cdf/rustico-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d9601fc8d0f01b09b024cf8b82a73761fe744a60660e6393e6327aa75ec8be80",
                "md5": "13c36a7f98b03fcc8130ad4983c38290",
                "sha256": "168e85a378387da1aba5ce943d9f3d077842196a7ced187b9c8a460da260128f"
            },
            "downloads": -1,
            "filename": "rustico-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "13c36a7f98b03fcc8130ad4983c38290",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 23606,
            "upload_time": "2025-07-18T16:04:41",
            "upload_time_iso_8601": "2025-07-18T16:04:41.167085Z",
            "url": "https://files.pythonhosted.org/packages/d9/60/1fc8d0f01b09b024cf8b82a73761fe744a60660e6393e6327aa75ec8be80/rustico-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-18 16:04:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "simwai",
    "github_project": "rustico#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "rustico"
}
        
Elapsed time: 1.80102s