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.
Metadata
Release files for regex-pypeline 0.0.21
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| regex_pypeline-0.0.21.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| regex_pypeline-0.0.21-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.4 kB
Release files / regex_pypeline-0.0.21.tar.gz
| Download URL | regex_pypeline-0.0.21.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
039e960f14a12a59ed9c6cddfbf4d511463c8f95ca1ff71747c6e74520ff09eb
|
|
BLAKE2b-256 checksum How to use checksums |
439aabee8e10bb81d68e8fae0c6054fb3ba58ee1ca072fb31faed404dbc2654f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Release files / regex_pypeline-0.0.21-py3-none-any.whl
| Download URL | regex_pypeline-0.0.21-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48389c0de015170366748da3da767063f898c15a3d80e7364d1e7c2058d5fabd
|
|
BLAKE2b-256 checksum How to use checksums |
d9f49ec8e9c982b252d182dc48c03034fddfac443c83100189686e79630e9bf4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|