Skip to main content

Python Pattern Matching

Inspired by pampy and core.match, this is a pattern matching library for dynamic list of patterns.

Right now it only supports matching lists of same sizes.

Usage

Import the lib

import PatternMatchStore from py_matching_pattern

First you will add initialize a PatternMatchStore with a fixed size of keys to match (size of the list).

pmdb = PatternMatchStore(keysize=3)

After that you can add the patterns. Every value is valid match, including None.

The "catch all" value is default attribute of the instance.

_ = pmdb.default
pmdb.put(keys=["a","b","c"],value=1)
pmdb.put(keys=["a","b","b"],value=2)
pmdb.put(keys=["a","b",_],value=3)
pmdb.put(keys=["a",_,_],value=4)
pmdb.put(keys=["a",None,"c"],value=5)
pmdb.put(keys=["a",_,"d"],value=6)

These patterns are staged for the DB. This is useful if you reload the patterns from another thread.

To make the pattern live, you commit it.

pmdb.commit()

Now you can finally start matching values:

pmdb.get(keys=["a","b","c"])==1
pmdb.get(keys=["a","b","b"])==2
pmdb.get(keys=["a","b","d"])==3
pmdb.get(keys=["a","c","d"])==4
pmdb.get(keys=["a",None,"c"])==5
pmdb.get(keys=["a","e","d"])==6
pmdb.get(keys=["e","e","e"])==None

The staged patterns are kept between commits, so you can add or override to it later.

But in case you want to clean it:

pmdb.clean()

It can also raise an exception if not found, but by default it will return None:

pmdb = core.PatternMatchStore(keysize=3,raise_on_notfound=True)
pmdb.get(keys=["e","e","e"]) # raise KeyNotFound

License

MIT

Metadata

Release files for py-matching-pattern 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-matching-pattern 0.0.3
File Size Uploaded Provenance Actions
py_matching_pattern-0.0.3.tar.gz 2.8 kB Without provenance Details for py_matching_pattern-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-matching-pattern 0.0.3
File Interpreter ABI Platform Actions
py_matching_pattern-0.0.3-py3-none-any.whl Python 3 none any Details for py_matching_pattern-0.0.3-py3-none-any.whl

Total release size: 5.8 kB

Release files / py_matching_pattern-0.0.3.tar.gz

Download URL py_matching_pattern-0.0.3.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
943b3fb49bbc29535a3746b1237626fb4c3f64b35ef1840988ee7c269b901de0
BLAKE2b-256 checksum
How to use checksums
f437777ee10a7424ed71222934f34b7b57a321722e17a20a63b47b06bd8e8bfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.5

Release files / py_matching_pattern-0.0.3-py3-none-any.whl

Download URL py_matching_pattern-0.0.3-py3-none-any.whl
Size 3.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfd91641f8ad6eaa0121075806d2f3ddf139c1c708e7a3a36c6ae935808bf3c7
BLAKE2b-256 checksum
How to use checksums
e3fd528c992377fa48a5f48fe7ea0d3e56205b0d2db0c84b843a8e9e8b9cd5b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.5

Security for py-matching-pattern 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page