Text (potentially byte) parsing utilities wrapping python stdlib regex features
Project description
Python Parsable Lib
utilities for quickly structuring text parsing
intended for situations where full-blown ast parsing is unnecessary
EXAMPLE_TEXT = """
{
"border": "{{int(1, 5)}}px {{random(solid, dotted, dashed)}} {{color()}}",
"coordinates": {
"type": "array",
"count": 2,
"items": "{{float(0, 120, 5)}}"
},
"password": "xX{{animal()}}-{{string(6, 10, *)}}"
}
{
"border": "2px dashed gray",
"coordinates": [
14.95685,
69.91848
],
"password": "xXearthworm-*******"
}
"""
@dataclass
class Coordinates(Parsable):
x: float
y: float
@staticmethod
def pattern() -> "re.Pattern[str]":
return re.compile(
r"\"coordinates\":\s*\[\s*(?P<x>\d+(?:\.\d+)?)\,\s*(?P<y>\d+(?:\.\d+)?)\,?\s*\]"
)
coordinates = Coordinates.from_str(EXAMPLE_TEXT)
print(coordinates)
which outputs:
>>> [Coordinates(x=14.95685, y=69.91848)]
This particular functionality exploits the named capture groups feature in the version of regex used by python (available in many other typical implementations) to structure the desired data into a dataclass output that can be worked with easily for other tasks.
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 regex_pypeline-0.0.21.tar.gz.
File metadata
- Download URL: regex_pypeline-0.0.21.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
039e960f14a12a59ed9c6cddfbf4d511463c8f95ca1ff71747c6e74520ff09eb
|
|
| MD5 |
489428dd30838007730ee07e458f23af
|
|
| BLAKE2b-256 |
439aabee8e10bb81d68e8fae0c6054fb3ba58ee1ca072fb31faed404dbc2654f
|
File details
Details for the file regex_pypeline-0.0.21-py3-none-any.whl.
File metadata
- Download URL: regex_pypeline-0.0.21-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48389c0de015170366748da3da767063f898c15a3d80e7364d1e7c2058d5fabd
|
|
| MD5 |
5a9df493c0eedf106c3a0a1c71c20201
|
|
| BLAKE2b-256 |
d9f49ec8e9c982b252d182dc48c03034fddfac443c83100189686e79630e9bf4
|