Skip to main content

Utility types for Python, such as `Result`, `Option`, etc.

Project description

📦 typeric

typeric is a practical type utility toolkit for Python, focused on clarity, safety, and ergonomics. It was originally built to make my own development experience smoother, but I hope it proves useful to others as well.
It currently provides lightweight, pattern-matchable types like Result and Option — inspired by Rust — with plans to include more common type patterns and error-handling abstractions.

pip install typeric

🚀 Features

  • ✅ Functional-style Result type: Ok(value) and Err(error)
  • 🌀 Lightweight Option type: Some(value) and NONE
  • 🧩 Pattern matching support (__match_args__)
  • 🔒 Immutable with .map() / .map_err() / .unwrap() / .unwrap_or() helpers
  • 🔧 Clean type signatures: Result[T, E] and Option[T]
  • 🛠️ Built for extensibility — more type tools coming

🔍 Quick Example

Result

from typeric.result import Result, Ok, Err

def parse_number(text: str) -> Result[int, str]:
    try:
        return Ok(int(text))
    except ValueError:
        return Err("Not a number")

match parse_number("42"):
    case Ok(value):
        print("Parsed:", value)
    case Err(error):
        print("Failed:", error)


def func_a(x: int) -> Result[int, str]:
    if x < 0:
        return Err("negative input")
    return Ok(x * 2)


@spreadable
def func_b(y: int) -> Result[int, str]:
    a = func_a(y).spread()
    return Ok(a + 1)


def test_func_b_success():
    assert func_b(5) == Ok(11)  # 5*2=10 +1=11


def test_func_b_propagate_error():
    assert func_b(-2) == Err("negative input")

Option

from typeric.option import Option, Some, NONE

def maybe_get(index: int, items: list[str]) -> Option[str]:
    if 0 <= index < len(items):
        return Some(items[index])
    return NONE

match maybe_get(1, ["a", "b", "c"]):
    case Some(value):
        print("Got:", value)
    case NONE:
        print("Nothing found")

✅ Test

Run tests with:

uv run pytest -v

📦 Roadmap

  • Validated type for batch error collection
  • Async Result
  • OptionResult combinators
  • Try, Either, NonEmptyList, etc.

📄 License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typeric-0.1.4.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typeric-0.1.4-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file typeric-0.1.4.tar.gz.

File metadata

  • Download URL: typeric-0.1.4.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for typeric-0.1.4.tar.gz
Algorithm Hash digest
SHA256 09bac98dd79719cfff75b9502220d58d9661faf71d9962ec0ab9c1466a1e5fe0
MD5 72e9fe2cf8040752c5e8ab2fe244928f
BLAKE2b-256 efd084386d1767dc0c94847bcf18a6412ea524000956182b58740ba60d11655a

See more details on using hashes here.

File details

Details for the file typeric-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: typeric-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for typeric-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d3e236db16d13818b2866f9b7eb1b1421c4aedab95c5a4ca3e1484c3d70bfbd6
MD5 3dd5c88cf1437c3e628c5e6d6e3e6c57
BLAKE2b-256 4d8afeb558a000fd3c5431fc5a03a3164b8180c3faf6f74e5fad7b527317c9c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page