Regex-based inclusion/exclusion filter loaded from JSON config
Project description
py-incl-excl-regex
Regex-based inclusion/exclusion filter for Python.
Install
pip install py-incl-excl-regex
Quick start
from incl_excl_regex import PatternFilter
f = PatternFilter(
include=[r"sg\.gov\.sla"],
exclude=[r"\.to(\.|$)", r"\.dao(\.|$)"],
)
f.matches("sg.gov.sla.stars.service.FooService") # True
f.matches("sg.gov.sla.stars.to.FooTo") # False — excluded
f.matches("com.example.Bar") # False — not included
Filter rules
- Include list: a value must match at least one include pattern to pass. Omitting include patterns accepts everything.
- Exclude list: a value must not match any exclude pattern.
- Exclude wins: if a value matches both an include and an exclude pattern, it is rejected.
- Patterns are matched with
re.search— the pattern can match anywhere in the string.
Loading from a JSON file
f = PatternFilter.from_file("filter.json")
Expected JSON shape (both keys are optional):
{
"include": ["sg\\.gov\\.sla"],
"exclude": ["\\.to(\\.|$)", "\\.dao(\\.|$)"]
}
Anchoring
Patterns use re.search, so they match anywhere in the string by default. Use ^ and $ anchors when you need to match from the start or end:
PatternFilter(include=[r"^sg\.gov\.sla"]) # must start with sg.gov.sla
PatternFilter(exclude=[r"\.to$"]) # only rejects strings ending in .to
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_incl_excl_regex-0.1.0.tar.gz.
File metadata
- Download URL: py_incl_excl_regex-0.1.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1c8f5ff25e475ed23e792461a82efe760e04fa2786e7c532b3d1e9a2ee6bf65
|
|
| MD5 |
1e70bed7ddc9b9b3261706772ffff99b
|
|
| BLAKE2b-256 |
086399500adb95043ba2b7fd3bd048776c43a816fe8e14645962a53948803bf7
|
File details
Details for the file py_incl_excl_regex-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_incl_excl_regex-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86037477cdee4244beeb72813e20f2045c457f5c0edc3f75b0db3d8bf00a9979
|
|
| MD5 |
1fdb8b7e8620703ce954a923bb8203ba
|
|
| BLAKE2b-256 |
9aa77c6986be6a403b57252bb9b5379fcd98bab89604a9b38e64a7991711b05b
|