**typeric** is a practical type utility toolkit for Python, focused on clarity, safety, and ergonomics
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 a lightweight, pattern-matchable Result type — similar to Rust's Result — with plans to include more common type patterns and error-handling abstractions.
pip install typeric
🚀 Features
- ✅ Functional-style
Resulttype:Ok(value)andErr(error) - 🧩 Pattern matching support (
__match_args__) - 🔒 Immutable with
.map()/.map_err()/.unwrap()/.unwrap_or()helpers - 🔧 Clean type signatures:
Result[T, E](with defaultE = Exception) - 🛠️ Built for extensibility — more type tools coming
🔍 Quick Example
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)
📂 Real-World Example
from functools import partial
import hashlib
from pathlib import Path
from typing import BinaryIO
from typeric.result import Result, Ok, Err
def get_md5(file_obj: BinaryIO) -> Result[str, Exception]:
try:
md5 = hashlib.md5()
while chunk := file_obj.read(8096):
md5.update(chunk)
file_obj.seek(0)
return Ok(md5.hexdigest())
except Exception as e:
return Err(e)
def is_exist(element: str, file_sets: set[str], auto_add: bool = True) -> bool:
exist = element in file_sets
if not exist and auto_add:
file_sets.add(element)
return exist
def file_exist(file_obj: BinaryIO, file_sets: set[str], auto_add: bool = True) -> Result[bool, Exception]:
match get_md5(file_obj):
case Ok(md5):
print("md5:", md5)
case Err(e):
print("error occurred:", e)
func = partial(is_exist, file_sets=file_sets, auto_add=auto_add)
return get_md5(file_obj).map(func=func)
✅ Test
def test_file() -> None:
file_set: set[str] = set()
files = [Path("test1.pdf"), Path("test1.pdf"), Path("test2.pdf")]
for file in files:
with open(file, "rb") as f:
result = file_exist(f, file_set)
assert result.is_ok()
Run tests with:
uv pytest -v
📦 Roadmap
Validatedtype for batch error collection- Async
Result
📄 License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file typeric-0.1.1.tar.gz.
File metadata
- Download URL: typeric-0.1.1.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6e8673548f8a455ca572e4904e1a5aabd337d8d007c8933c7563127a300090d
|
|
| MD5 |
841d70059dc28fde11a2ca1ffd030e76
|
|
| BLAKE2b-256 |
f2b9fc8d60f5f33bb5fc8de848934a4030de2be80c3b585f3817c878a5c107bc
|
File details
Details for the file typeric-0.1.1-py3-none-any.whl.
File metadata
- Download URL: typeric-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1c854374c9ea3236645058a845e6be84cd39bd7bac6df103322488caf2ff32d
|
|
| MD5 |
df16de6894b54271f72455eac33a6125
|
|
| BLAKE2b-256 |
cf67eb8fa8d54aa186426748429a4c97514b42291578de1beedadee042233a02
|