skillfed

pampy

The Pattern Matching for Python you always dreamed of

pampy v0.3.0 85.3K downloads/30d#13,937 on PyPI3,526
Permissive license DORMANT released

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 pampy

uv

uv add pampy

poetry

poetry add pampy

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

pattern matching pythonmatch expression destructuringfunctional pattern matchingswitch case alternativetype-based dispatchstructural pattern matchingmatch statement library
pattern-matchingfunctional-programmingcontrol-flow

More Software Development packages