Skip to main content

build PyPI - Python Version PyPI - License

remagic logo

remagic

Build regular expressions from composable, typed Python objects. Partly inspired by magic-regexp for Node.

>>> import remagic as rm
>>> year = rm.DIGIT.times(4).group("year")
>>> month = rm.DIGIT.times(2).group("month")
>>> date = rm.START + year + "-" + month + rm.END
>>> date.compile().fullmatch("2027-01")["year"]
'2027'

Patterns are immutable. Strings are matched literally, + concatenates, | alternates, and (?:...) is added only where precedence needs it:

>>> str((rm.exactly("a") | "b").times(2))
'(?:a|b){2}'

Installation

uv add remagic            # or: pip install remagic
uv add "remagic[regex]"   # optional: the `regex` engine

Requires Python 3.11+. Patterns compile with the standard re module. Features that only regex supports, such as unicode_property("L"), switch to it automatically and need the regex extra.

Learn more

See the quickstart, concepts and cookbook in the docs, or the building blocks below.

Building blocks

  • Constants: DIGIT, WORD, WHITESPACE, LETTER, CHAR, NEWLINE, ... and anchors START, END, WORD_BOUNDARY, ...
  • Characters: exactly, char_in, char_not_in, char_range, any_of, unicode_property
  • Quantifiers: optional, zero_or_more, one_or_more, times, between, at_least, each with lazy= and possessive=
  • Groups: group (numbered or named), non_capturing, atomic, ref
  • Assertions: before, not_before, after, not_after, and the methods followed_by, not_followed_by, preceded_by, not_preceded_by
  • Flags: scoped, ignore_case, multiline, dotall
  • Every function has a matching Pattern method.

Development

uv sync
uv run pytest        # 100% line and branch coverage is required
uv run ruff check . && uv run ruff format --check . && uv run mypy
uv run --group docs sphinx-build -W -b html docs docs/_build   # build the docs

Metadata

Release files for remagic 0.2.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 remagic 0.2.0
File Size Uploaded Provenance
remagic-0.2.0.tar.gz 14.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for remagic 0.2.0
File Interpreter ABI Platform
remagic-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.1 kB

Release files / remagic-0.2.0.tar.gz

Download URL remagic-0.2.0.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3312e589fafa35f697c1edbc9c531d1e133a75444d06212bc3cd4ec5c37e054a
BLAKE2b-256 checksum
How to use checksums
fb7e0148cb9008ca504d27251f742b85f9be0568656bcf48e6acc847cd5d663b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / remagic-0.2.0-py3-none-any.whl

Download URL remagic-0.2.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cda63efb9086c6e286797143374ba23d361eab749ff6dfb1a7d1397b1be277d9
BLAKE2b-256 checksum
How to use checksums
76ed329de0bf8c05afbea27ee85d23c9129478d5bf85d97afca48e0795caeb99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for remagic 0.2.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.

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