Registry / devops / pampy
library0.3.0pypypi✓ verified 83d ago

Pampy is a library for pattern matching in Python, inspired by Haskell and OCaml. It provides concise syntax for matching patterns against data structures, including lists, dictionaries, and custom objects. The current stable version is 0.3.0, released in 2019. The library is in maintenance mode with low release cadence.

pip install pampy
INSTALL
IMPORT
SIG · PAMPY
P
pampy
devopspythonv0.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

match
from pampy import match
Standard import for the main pattern matching function.
_
from pampy import _
Wildcard pattern, similar to underscore in Haskell.
ANY
from pampy import _
from pampy import ANY
Pampy uses underscore for wildcard, not ANY.

Basic pattern matching with Pampy using match() function.

from pampy import match, _, REST result = match([1, 2, 3, 4], 1, "one", [1, _, 3, _], lambda a, b: f"1, {a}, 3, {b}", _, "default") print(result) # Output: 1, 2, 3, 4 # Note: Pattern matching is case-sensitive and order matters.
Debug
Known issues
gotchaUse underscore _ for wildcard, not ANY or other names.
fix
Import _ from pampy and use it as wildcard.
affects: all
gotchaPatterns in match are matched in order; the first matching branch is executed. Use default pattern (_) at the end.
fix
Always put the most specific patterns first and a catch-all _ last.
affects: all
gotchaPampy's match does not support Python's structural pattern matching syntax (PEP 634). Use its own DSL.
fix
Refer to Pampy's documentation for correct pattern syntax.
affects: all
deprecatedThe library has not been updated since 2019 and compatibility with newer Python versions may be limited.
fix
Consider using Python 3.10+ built-in match statement or alternative libraries.
affects: 0.3.0
Errors
Common errors & fixes
ImportError: cannot import name 'ANY' from 'pampy'
Attempting to import a non-existent name. The wildcard is '_' not 'ANY'.
fix
Use: from pampy import _
TypeError: match() takes 2 positional arguments but more were given
Incorrect call signature. match accepts (value, *patterns) where patterns are (pattern, result) pairs.
fix
Use: match(data, pattern1, result1, pattern2, result2, ...)
KeyError: '...' when matching dictionaries
Pattern matching with dictionary keys that do not exist in the matched dict.
fix
Ensure dictionary patterns have keys that exist. Use _ for optional keys with a default branch.
Upgrade
Version history
0.3.0latest on PyPI · released Nov 7, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
pampy — pip install pampy · libregistry