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

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.2.tar.gz (4.7 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.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file regex_pypeline-0.0.2.tar.gz.

File metadata

  • Download URL: regex_pypeline-0.0.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for regex_pypeline-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a20ecb24871b5f9307483e361b86c06093dcdcc675f6d629a25fa85011c66199
MD5 aa966354c238ad5197d844ecf8135a1d
BLAKE2b-256 ab946b7b6564a521a783d1ddf9b504449d413556e0482baa2a19a99d5fbe145b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: regex_pypeline-0.0.2-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.12.3

File hashes

Hashes for regex_pypeline-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b9c16277405ed9574c7976fd1fed4a15c18cb984e6a6c1dc05d955d5568bb1df
MD5 1c3933a91ec3ea754e3613cdd246dd2e
BLAKE2b-256 e4694a35f8794ca70ce8b4f95738e2ab51690d4ff32d27a13e97cb1e03cb8c1f

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