Skip to main content

Text (potentially byte) parsing utilities wrapping python stdlib regex features

Project description

Python Parsable Lib

utilities for quickly structuring text parsing

test_suite

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

regex_pypeline-0.0.21.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

regex_pypeline-0.0.21-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

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

Hashes for regex_pypeline-0.0.21.tar.gz
Algorithm Hash digest
SHA256 039e960f14a12a59ed9c6cddfbf4d511463c8f95ca1ff71747c6e74520ff09eb
MD5 489428dd30838007730ee07e458f23af
BLAKE2b-256 439aabee8e10bb81d68e8fae0c6054fb3ba58ee1ca072fb31faed404dbc2654f

See more details on using hashes here.

File details

Details for the file regex_pypeline-0.0.21-py3-none-any.whl.

File metadata

File hashes

Hashes for regex_pypeline-0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 48389c0de015170366748da3da767063f898c15a3d80e7364d1e7c2058d5fabd
MD5 5a9df493c0eedf106c3a0a1c71c20201
BLAKE2b-256 d9f49ec8e9c982b252d182dc48c03034fddfac443c83100189686e79630e9bf4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page