https://github.com/nephi-dev/rxml
A Python library to read xml files written in rust
https://github.com/nephi-dev/rxml
cpython maturin pypy python rust xml
Last synced: 15 days ago
JSON representation
A Python library to read xml files written in rust
- Host: GitHub
- URL: https://github.com/nephi-dev/rxml
- Owner: nephi-dev
- License: mit
- Created: 2023-04-26T14:15:46.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-10-08T14:20:13.000Z (5 months ago)
- Last Synced: 2025-10-08T16:16:40.996Z (5 months ago)
- Topics: cpython, maturin, pypy, python, rust, xml
- Language: Rust
- Homepage: https://pypi.org/project/rxml/
- Size: 105 KB
- Stars: 18
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rxml
[](https://pypi.org/project/rxml)
[](https://pypi.org/project/rxml)
[](https://opensource.org/licenses/MIT)
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.
---
## Features
- **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 `.pyi` stub file for full editor autocompletion and type checking.
- **Cross-platform** - Supports CPython and PyPy on Windows, macOS, and Linux.
## Installation
```bash
pip install rxml
```
## Quick Start
### Reading XML
Given an XML file `note.xml`:
```xml
Example Name
Example Name
An Example Heading
An Example Body!
```
Parse it with `rxml`:
```python
from rxml import read_file
root = read_file("note.xml", "note")
for child in root.children:
print(child.name, child.text)
```
### Writing XML
```python
from rxml import Node, write_file
node = Node(
name="greeting",
attrs={"lang": "en"},
text="Hello, World!",
)
write_file(node, "greeting.xml")
```
### The `Node` Object
Every parsed element is represented as a `Node`:
```python
class Node:
name: str # Tag name
attrs: dict[str, str] # Element attributes
children: list[Node] # Child nodes
text: str # Text content
```
Refer to the [`rxml.pyi`](rxml.pyi) stub file for the complete API surface, including `read_string`, `write_string`, and additional utilities.
## Development
`rxml` is built with [PyO3](https://pyo3.rs) and [Maturin](https://www.maturin.rs/).
### Prerequisites
- Python 3.10+
- Rust toolchain (stable)
- [Maturin](https://www.maturin.rs/) (`pip install maturin`)
### Building from Source
```bash
git clone https://github.com/nephi-dev/rxml.git
cd rxml
python -m venv .venv && source .venv/bin/activate
pip install maturin
maturin develop
```
### Running Tests
```bash
cargo test
```
## Contributing
Contributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/nephi-dev/rxml).
## License
This project is licensed under the [MIT License](LICENSE).
## Support
If you find this project useful, consider supporting me:
[](https://buymeacoffee.com/nephilim)