Skip to main content

renorm

PyPI version Python versions License CI

Regex-based data extraction with typed normalization.

renorm lets you embed small, reusable “spec” objects inside regular expressions. Each spec defines both a regex fragment and a normalization function, so matched values are returned as real Python types with zero post-processing.

Normalization depends on the exact structure of the matched text, so extraction and normalization naturally belong together. renorm follows this principle by treating each spec as a single unit of pattern + normalization logic, making typed extraction composable and predictable.

Highlights

  • Drop-in wrapper around Python’s re — mirrors the API and adds no dependencies.
  • Built-in spec objects for common data types.
  • Define your own specs with custom patterns and normalization logic.

Basic Example

Instances of renorm.Num specify the thousand and decimal separators of plain number literals to be captured and, therefore, how they should be normalized.

import renorm as rn

eu = rn.Num(dec=",", ths=" ")
us = rn.Num(dec=".", ths="'")

pat = rn.compile(
    r"price=({@eu}); qty=({@us}); total=({@eu})",
    eu=eu,
    us=us,
)

m = pat.search("price=1 234,50; qty=2'000.0; total=2 469,00")
print(m.groups())  # (1234.5, 2000.0, 2469.0)

Installation

pip install re-norm

Features

  • Extract numeric literals with built-in specs
  • Normalize custom data types via user-defined specs
  • Compose patterns using simple placeholders ({@name})
  • Zero dependencies: drop-in wrapper around Python’s re
  • Minimal developer overhead: mirrors Python’s re API and semantics

Using Specs in Regular Expressions

Specs are embedded in patterns using placeholders:

  • {@name} for keyword specs
  • {@0}, {@1}, … for positional specs

Each placeholder is replaced by the regex fragment defined by the spec. If the placeholder appears inside a capturing group, the matched text is passed through the spec’s normalization function.

This is the same placeholder syntax used in the basic example above, where specs are passed as kwargs.

Custom Specs

You can define your own normalization rules by subclassing rn.NormSpec. A custom spec must implement a pattern property (regex fragment) and a normalize method. This allows renorm to support arbitrary data types and formats.

class Hex(rn.NormSpec):
    @property
    def pattern(self):
        return r"[0-9A-Fa-f]+"

    def normalize(self, value: str):
        return int(value, 16)
addr = Hex()
size = rn.Num()

pat = rn.compile(
    r"addr=0x({@addr}), size=({@size}) bytes",
    addr=addr,
    size=size,
)

m = pat.search("addr=0x1A2B, size=64 bytes")
print(m.groups())   # (6699, 64.0)

API Overview

Mirrors the familiar Python re API.

renorm.compile(pattern, *specs, **named_specs, flags) -> Pattern

renorm.Pattern

  .search(text) -> Match | None

  .match(text) -> Match | None

  .fullmatch(text) -> Match | None

  .pattern -> str   (the compiled regex string)

renorm.Match

  .group(0) -> str   (full match)

  .group(i) -> T   (normalized value)

  .group(i, j) -> tuple[T, str, None, ...]   (normalized values)

  .groups() -> tuple[T, str, None, ...]   (all normalized values)

  .groupdict()   (disabled: reserved for internal use)

renorm.NormSpec

renorm.Num(dec, ths)

Note

Some methods from the re API are not implemented yet. If you need one, just open an issue — happy to add it.

Metadata

Release files for re-norm 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for re-norm 0.1.0
File Size Uploaded Provenance Actions
re_norm-0.1.0.tar.gz 10.0 kB Without provenance Details for re_norm-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for re-norm 0.1.0
File Interpreter ABI Platform Actions
re_norm-0.1.0-py3-none-any.whl Python 3 none any Details for re_norm-0.1.0-py3-none-any.whl

Total release size: 21.8 kB

Release files / re_norm-0.1.0.tar.gz

Download URL re_norm-0.1.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2c122c350e4986bb8e31d49ddf792d85cbd21a775c2ffb303f454c96790641f3
BLAKE2b-256 checksum
How to use checksums
d2406573ff725b129331d0a3184c33af821aaf542dd171f20749c88b0ee283fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / re_norm-0.1.0-py3-none-any.whl

Download URL re_norm-0.1.0-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a61eeadfd9ad9b74db2c4a0f2d8098883da91ba079bae7db4fcfa183d5af7e65
BLAKE2b-256 checksum
How to use checksums
918a065c7aba8138e75b847788ae904e9aaaa95c59eacdb93cb39bb95c25f46c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for re-norm 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page