Skip to main content

larzxml

Ergonomic XML builder + an XXE-safe parser — zero dependencies.

The standard library makes two XML tasks harder than they should be: building XML reads clumsily with ElementTree, and parsing untrusted XML is dangerous by default (XXE and billion-laughs attacks). larzxml fixes both — a fluent builder that escapes correctly, and a parser that refuses DTDs and entities, so external-entity and exponential-expansion attacks simply can't happen.

Install

pip install larzxml

Use

from larzxml import element, parse

root = element("order", id="42")
root.sub("item", text="Widget", sku="A1")
root.sub("item", text="Gadget & <friends>", sku="B2")   # escaped safely
print(root.to_xml(pretty=True))

tree = parse(xml_text)              # safe by default
tree.find("item").text
tree.findall("item")

Safe by construction

parse('<!DOCTYPE x [<!ENTITY e SYSTEM "file:///etc/passwd">]><x>&e;</x>')
# -> XMLError: DTD/DOCTYPE is not allowed (XXE-safe parser)

DTDs and entity declarations are rejected, so both XXE (reading local files / SSRF) and billion-laughs (exponential entity expansion) are impossible — you don't have to remember to harden anything.

Tests

python -m unittest discover -s tests -v   # 14 tests (incl. XXE + billion-laughs)

The Larz stack

One of 60+ pure-Python, zero-dependency libraries at github.com/larz-scripter. The XML sibling of larzhtml (XSS-safe HTML) and larzjson.

License

MIT (c) larz-scripter

Metadata

Release files for larzxml 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 larzxml 0.1.0
File Size Uploaded Provenance
larzxml-0.1.0.tar.gz 5.9 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 11.4 kB

Release files / larzxml-0.1.0.tar.gz

Download URL larzxml-0.1.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6f006cf3fefa6cc9325efef4b9be10b18d6fc15de4c23bb1803110fbecd6e910
BLAKE2b-256 checksum
How to use checksums
2da374fad2e3cff62055faf258a26d6d0cee9b63a64cb8f234cbf642a4b38c98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL larzxml-0.1.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a8cdba5ac745aea009491c08dfb33f6f8854338ac9721032a7a7e1a5b304ccf
BLAKE2b-256 checksum
How to use checksums
649cf4b7b53806c3f4d8b581f6589af4d75a018ad9fd0466fdc9215acab40233
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for larzxml 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