Repository navigation
v0.2.0 - Shields for Popular Libraries
What's New
Pyrethrin 0.2.0 introduces Shields - pre-built exception declarations for popular Python libraries. Shields are drop-in replacements that bring exhaustive error handling to third-party code.
Available Shields
| Shield | Coverage |
|---|---|
pyrethrin.shields.pandas |
File I/O, parsing, data manipulation (read_csv, read_excel, read_json, concat, merge, pivot, etc.) |
pyrethrin.shields.numpy |
95%+ of numpy API (array creation, math, linalg, FFT, random, I/O) |
pyrethrin.shields.fastapi |
Core FastAPI (FastAPI, APIRouter, Request, Response, dependencies) |
Usage
# Before - exceptions are implicit
import pandas as pd
df = pd.read_csv("data.csv") # Can raise OSError, ParserError, ValueError...
# After - exceptions are explicit and must be handled
from pyrethrin.shields import pandas as pd
from pyrethrin import match, Ok
result = match(pd.read_csv, "data.csv")({
Ok: lambda df: process(df),
OSError: lambda e: log_error("File not found", e),
pd.ParserError: lambda e: log_error("Invalid CSV", e),
ValueError: lambda e: log_error("Bad data", e),
})How Shields Are Built
Exception declarations are generated using Arbor, a static analysis tool that traverses Python call graphs to discover all possible exceptions. This ensures shields declare the actual exceptions that can occur, not just guesses.
Install
pip install pyrethrin==0.2.0