A fast, lightweight Python library for reading and writing XML files, powered by Rust.
rxml provides up to 2× faster XML parsing compared to Python's built-in xml.etree.ElementTree, with a simple and intuitive API.
- Fast - Rust-powered XML parsing, up to 2× faster than the standard library.
- Simple API - Read, traverse, and write XML with minimal boilerplate.
- Type-safe - Ships with a
.pyistub file for full editor autocompletion and type checking. - Cross-platform - Supports CPython and PyPy on Windows, macOS, and Linux.
pip install rxmlGiven an XML file note.xml:
<?xml version="1.0" encoding="UTF-8"?> <note example_attr="example value"> <to> <name>Example Name</name> </to> <from> <name>Example Name</name> </from> <heading>An Example Heading</heading> <body>An Example Body!</body> </note>Parse it with rxml:
from rxml import read_file root = read_file("note.xml", "note") for child in root.children: print(child.name, child.text)from rxml import Node, write_file node = Node( name="greeting", attrs={"lang": "en"}, text="Hello, World!", ) write_file(node, "greeting.xml")Every parsed element is represented as a Node:
class Node: name: str # Tag name attrs: dict[str, str] # Element attributes children: list[Node] # Child nodes text: str # Text contentRefer to the rxml.pyi stub file for the complete API surface, including read_string, write_string, and additional utilities.
rxml is built with PyO3 and Maturin.
- Python 3.10+
- Rust toolchain (stable)
- Maturin (
pip install maturin)
git clone https://github.com/nephi-dev/rxml.git cd rxml python -m venv .venv && source .venv/bin/activate pip install maturin maturin developcargo testContributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License.
If you find this project useful, consider supporting me: