pattex
A Python library for extracting common patterns from text using regex — emails, URLs, phone numbers, IP addresses, and more.
Installation
pip install pattex
Changelog
[0.4.0] - 2026-05-16
Added
url_extractor.py
extract_urls_by_scheme(text, scheme)— filter URLs by a specific schemeextract_urls_by_domain(text, domain, include_subdomains)— filter URLs by domain, with optional subdomain matchingextract_urls_by_tld(text, tld)— filter URLs by TLD, leading dot optionalextract_secure_urls(text)— returns only https, ftps, sftp, wss URLsextract_insecure_urls(text)— returns only http, ftp, ws URLsextract_urls_with_auth(text)— returns only URLs containing userinfo (user:pass@host)extract_urls_with_port(text, port)— returns URLs with any port, or a specific portextract_unique_domains(text, root_only)— unique hostnames or root domains across all URLsis_url(text, strict)— validates whether a string is a valid URLallow_ipv4,allow_ipv6,allow_port,allow_tail,schemesparameters added toextract_urls_build_strict_regex()— dynamic regex builder withlru_cache(maxsize=16)_build_permissive_regex()— single combined permissive regex with named groups,lru_cache(maxsize=1)
ip_extractor.py ← new file
extract_ip_urls(text, ipv4, ipv6)— extract URLs whose host is an IP addressextract_localhost_urls(text, allow_port, allow_tail)— extract localhost URLs only
regexes.py
_SCHEMES— raw scheme alternation string_BARE_DOMAIN— raw bare domain pattern without port/tail
_utils.py
_get_root_domain(host)— extracts root domain from hostnamehas_auth(url)— checks whether a URL contains userinfo_is_ip_host(url)— checks whether a URL host is an IP address
extractor_constants.py
URL_SCHEMES—Literaltype for all supported schemes
Changed
include_localhostrenamed toallow_localhost— breaking change- Permissive mode now runs a single
finditerscan instead of 3–4 separate loops — protocol-relative, bare domain, bare IP, and localhost combined into one regex via named groups ((?P<name>...)) match.lastgroupused to dispatch per-branch guard logic in permissive loop- Localhost always included in permissive mode implicitly —
allow_localhostonly controls strict mode _build_permissive_regextakes no arguments — localhost always included in permissive- Schemed
http://localhostalways extracted in strict mode regardless ofallow_localhost extract_secure_urlsandextract_insecure_urlshave nomodeparameter — scheme implies strictness
Internal
- All raw pattern constants kept as plain strings in
regexes.py— compiled only at assembly time lru_cacheon both builders avoids recompilation on repeated calls with same flagsurlparseimport consolidated at top ofurl_extractor.py- Walrus operator used in
extract_urls_with_portto avoid doubleurlparsecall
v0.3.1 - 2026-05-13
Fixed
- Zoho extractor: removed hyphen (
-) and plus (+) from allowed local part characters — Zoho usernames only permit letters, numbers, dots, and underscores per official documentation - Zoho extractor:
+is a subaddressing tag separator, not a valid account creation character; removed from base regex and validation logic - Proton extractor: tightened leading/trailing character rule — local part must
begin and end with an alphanumeric character (was checking against
._-set, now explicitly usesisalnum()to match Proton's documented rule)
Changed
- Renamed
email_extraction.py→email_extractor.py - Renamed
urls_extraction.py→url_extractor.py - Updated docstrings for
extract_zoho_emailsandextract_proton_emailsto reflect corrected provider rules - Added inline comments on each validation rule inside
email_extractor.pyfor all six provider extractors - Added documentation comments for all email regex patterns in
constants/regexes.pyand corresponding.pyistubs
Internal
- General code cleanups across extractor modules
Status
Currently under active development. Full documentation and usage examples coming soon.
License
MIT
Metadata
Release files for pattex 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pattex-0.4.0.tar.gz | 19.2 kB | Without provenance | Details for pattex-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pattex-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for pattex-0.4.0-py3-none-any.whl |
Total release size: 43.1 kB
Release files / pattex-0.4.0.tar.gz
| Download URL | pattex-0.4.0.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac4daee99a67494bdb6dc75f3fd9e167adb3c95bda54ed113acdc9e9d67e55a4
|
|
BLAKE2b-256 checksum How to use checksums |
1bb59cb61b612f38782b869d17da8e0492bf81d741c1630e7c388f2d9824a149
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Release files / pattex-0.4.0-py3-none-any.whl
| Download URL | pattex-0.4.0-py3-none-any.whl |
|---|---|
| Size | 23.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca40c139b5fdc436aadc791f7df584e9c587d47b60d0196b454c8470babd6c30
|
|
BLAKE2b-256 checksum How to use checksums |
0f36d892b8ca0407bec5b46ce45f2006bf56533732884db548476f04de69010e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Security for pattex 0.4.0
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.