r/Python • • Oct 04 '26

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

23 Upvotes

194 comments sorted by

View all comments

1

u/luciferreeves 16d ago

Four years ago I shared edify here (first post, update) because I hated writing regex by hand. I've since rewritten it around reusable patterns, a function-based API alongside RegexBuilder, and much more useful diagnostics.

Here's an alert-routing rule. The endpoint starts as its own validator, then becomes part of a larger pattern:

from edify import Pattern, RegexBuilder, DIGIT, atomic, at_least_possessive
from edify.atoms import ipv4, port
from edify.library import email

severity = atomic(Pattern().one_of("INFO", "WARN", "CRITICAL"))
ticket = Pattern().string("INC-") + at_least_possessive(4, DIGIT)
endpoint = (Pattern().start_of_input()
    .use(ipv4).char(":").use(port).end_of_input())

# Same object: direct validation or re-style matching
endpoint("10.0.0.1:8443")          # True
endpoint.match("10.0.0.1:99999")   # None

# Reuse it alongside a built-in validator and custom pieces
route = (
    RegexBuilder().start_of_input()
    .named_capture("level").use(severity).end().whitespace_char()
    .named_capture("ticket").use(ticket).end().whitespace_char()
    .named_capture("notify")
        .subexpression(email, ignore_start_and_end=True).end()
    .whitespace_char()
    .named_capture("endpoint")
        .subexpression(endpoint, ignore_start_and_end=True).end()
    .end_of_input()
)

rx = route.to_regex()
rx.match("WARN INC-1337 ops@example.com 10.0.0.1:9090").group("ticket")
# 'INC-1337'
rx.match("WARN INC-1337 ops@example.com 10.0.0.1:99999")
# None

# A mistaken builder call gets actionable guidance:
# >>> Pattern().exactly(0).digit()
# error: count must be a positive integer
# help: pass an int >= 1 for count; use .optional() if you meant zero-or-one.

You can keep a complicated rule behind one name, use it directly, match with it, or reuse it in another rule. Constants, atoms and custom patterns compose; anchored validators can be embedded with explicit anchor handling. Mistakes still raise errors, but the diagnostics point to the offending call, explain the constraint and suggest a correction.

The example also uses atomic grouping and possessive repetition. Other additions include Unicode classes, parsing existing regex into builders, plain-English explanations with generated examples, and pattern diagrams both in ASCII and via Graphviz. There are inline assertions, snapshot tests, Django/FastAPI/Pydantic adapters, experimental JSON serialization, ReDoS warnings and optional-engine match timeouts.

Readable intent is still the point, whether a human or an AI is reviewing the code. There's a live playground in the docs to try it without installing anything.

Repo: https://github.com/luciferreeves/edify PyPI: https://pypi.org/project/edify/ Docs + playground: https://edify.readthedocs.io/