pampy
The Pattern Matching for Python you always dreamed of
What it is and what it does
Pampy is a lightweight pattern-matching library that lets you write declarative match expressions instead of nested conditionals. It supports matching literals, types, tuples, lists, dicts, dataclasses, and typing annotations, with the special operator `_` capturing values to pass into handler functions. Patterns are evaluated in order, and you can nest structures arbitrarily—matching a tuple of integers, a dict with specific keys, or a dataclass field all work the same way.
The library is pure Python with no dependencies, making it trivial to install and use. It's useful for simplifying control flow in recursive algorithms, AST walkers, or any code that needs to branch on the shape of data. However, since the last release was in 2019 and the repository shows no active maintenance, you should verify compatibility with your target Python version before adopting it in new projects.
Use it for:
- Simplify recursive algorithms like Fibonacci or tree traversal by matching on input structure instead of writing nested conditionals.
- Parse and evaluate Lisp-like expressions or simple DSLs by matching on callable, tuple, and type patterns.
- Destructure nested dicts and lists to extract values without repeated indexing or get() calls.
- Dispatch on class hierarchies (e.g., different Pet subclasses) without isinstance chains.
- Validate and extract fields from dataclasses or typed tuples in a single match expression.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pampy provides pattern matching for Python, letting you write match expressions that destructure and dispatch on values, types, and nested structures without nested if-else chains.
Yes, if you need pattern matching and are comfortable with a dormant library. The package is tiny, has no dependencies, carries no known vulnerabilities, and works well for the specific task it solves. Install it for algorithmic code, DSL parsing, or data destructuring where it genuinely improves readability. Avoid it if you require active maintenance or have not tested it with your target Python version.
Install
pampy on PyPI
pip
pip install pampyuv
uv add pampypoetry
poetry add pampyInstalling pampy
Before you install
Installation is frictionless—a pure-Python wheel with no runtime dependencies. The package is dormant (last release November 2019, last commit January 2025), so it receives no active maintenance, but the small codebase (150 lines) and lack of external dependencies mean there is little surface for breakage.
License in practice
Licensed under MIT (permissive), so you can use, modify, and distribute this package freely in commercial and open-source projects with minimal restrictions.
Quickstart
from pampy import match, _
def fibonacci(n):
return match(n,
1, 1,
2, 1,
_, lambda x: fibonacci(x-1) + fibonacci(x-2)
)
fibonacci(5) # => 5
Requires Python >3.6; dict-based patterns with `_` as keys rely on insertion-order guarantees.
Verify before relying
- Whether the dormant status and 2019 release date pose compatibility risks with recent Python versions.
- Performance characteristics compared to native match statements or other pattern-matching libraries.
- Actual minimum Python version needed for all features to work correctly.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 2,472 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 85,253/month — #13,937 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pampy-0.3.0-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
pygrokParses strings and extracts structured data…
permissive · top 15,000 on PyPI
snuggsSnuggs evaluates s-expressions (Lisp-like…
permissive · top 15,000 on PyPI
ExpressionExpression provides functional programming…
permissive · top 5,000 on PyPI
anysProvides matcher objects that compare equal to…
permissive · top 5,000 on PyPI
rebulkReBulk provides a fluent API for building…
permissive · top 15,000 on PyPI
schemaValidates Python data structures (dicts, lists,…
permissive · top 1,000 on PyPI
consImplements Lisp/Scheme-style cons operations…
unclear · top 5,000 on PyPI
overloadingProvides function and method overloading based…
permissive · top 15,000 on PyPI
methoddispatchAdds single-dispatch method support to Python…
permissive · top 15,000 on PyPI
typing-inspectProvides runtime inspection utilities for…
permissive · top 1,000 on PyPI