regexml 🚀
A lightweight, fault-tolerant, text-first XML extraction library for Python. Available on PyPI: pypi.org/project/regexml.
Unlike traditional XML parsers (xml.etree.ElementTree, lxml) that enforce strict document validation and crash with ParseError on incomplete or malformed markup, regexml treats XML purely as plain text. It extracts values directly using regular expressions and resilient pattern matching.
🌟 Why regexml?
- Fault-Tolerant & Resilient: Doesn't crash on unescaped
&,<,>, missing closing tags, or broken XML headers. - Perfect for LLM Outputs: Cleanly extract tags like
<thought>,<answer>, or<code>from AI responses. - Fluent Dot-Syntax Chaining: Call
data.tagvalue("div").tagvalue("name")seamlessly. - Balanced Outermost Tag Extraction: Accurately captures outer tags with nested tags of the same name without premature cut-offs.
- Truncated Stream Recovery: If an XML stream cuts off prematurely (e.g. at line 1000 of 1200), it safely captures data up to EOF without failing.
- Tag Inspector & Hierarchy: Built-in
check_tags()discovers all tags, reports unclosed/truncated tags, and renders visual ASCII trees. - Zero Heavy Dependencies: Built 100% on Python standard library.
📦 Installation
pip install regexml
⚡ Quick Start
1. Fluent Dot-Syntax (XMLText)
Wrap any string with XMLText to unlock dot-methods while retaining 100% string compatibility:
from regexml import XMLText
raw_data = """
<article id="101">
<title>Resilient XML Extraction</title>
<author>
<first_name>Ishan</first_name>
<last_name>Jain</last_name>
</author>
</article>
"""
doc = XMLText(raw_data)
# Extract single tag value:
print(doc.tagvalue("title"))
# Output: Resilient XML Extraction
# Method Chaining:
print(doc.tagvalue("author").tagvalue("first_name"))
# Output: Ishan
# Path Shorthand:
print(doc.tagvalue("author/last_name"))
# Output: Jain
2. Functional API (Without Wrapping)
from regexml import tagvalue, tagvalues
data = "<user><name>Alice</name><name>Bob</name></user>"
print(tagvalue(data, "name")) # Alice
print(tagvalues(data, "name")) # ['Alice', 'Bob']
🎯 Advanced Features
Balanced Nested Tags of the Same Name
Standard regex chops off at the first closing tag. regexml tracks depth counter to return the true balanced outermost tag:
xml = """
<div id="outer">
Hello
<div id="inner">World</div>
Welcome!
</div>
"""
doc = XMLText(xml)
print(doc.tagvalue("div"))
# Output:
# Hello
# <div id="inner">World</div>
# Welcome!
Truncated / Broken XML Recovery
If your XML was cut off mid-stream (e.g., from network drop or LLM token limit):
truncated_xml = "<user><id>123</id><bio>Software engineer who loves Python... [CUT OFF]"
doc = XMLText(truncated_xml)
bio = doc.tagvalue("bio")
print(bio) # "Software engineer who loves Python... [CUT OFF]"
print(bio.is_truncated) # True
Tag Inspection & Broken Markup Detection (check_tags)
report = doc.check_tags()
# View all tags found:
print(report.tags) # ['user', 'id', 'bio']
# Pinpoint unclosed tags (truncated points):
print(report.unclosed_tags) # ['user', 'bio']
# Print terminal ASCII tree:
print(report.tree())
Output:
└── user (unclosed)
├── id
└── bio (unclosed)
The tree instantly visualizes the markup hierarchy and flags unclosed tags, making it easy to pinpoint where the XML stream cut off.
📄 License
MIT License. Developed by Ishan.
Metadata
Release files for regexml 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| regexml-0.1.0.tar.gz | 19.6 kB | Without provenance | Details for regexml-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| regexml-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for regexml-0.1.0-py3-none-any.whl |
Total release size: 31.1 kB
Release files / regexml-0.1.0.tar.gz
| Download URL | regexml-0.1.0.tar.gz |
|---|---|
| Size | 19.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68aa8a793bcf21d92fb1f94bed8cc820ff233af607c508487b14cc0dc879b804
|
|
BLAKE2b-256 checksum How to use checksums |
c232bb4272ca9bab452a45b08756777dc0f31a67f54da4dda0961ca5dd97c298
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / regexml-0.1.0-py3-none-any.whl
| Download URL | regexml-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33c9e9b9c5fcbbb3acdc33d252ee7448c139abb27fd1e5641e56e9ac1c40165f
|
|
BLAKE2b-256 checksum How to use checksums |
e372622d3f2170a51c5a76850d9e2a1c6c63476d63db83744b9bf2aad6489ab2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for regexml 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.