https://github.com/statnett/quick-xmltodict
Efficient XML-to-dict conversion backed by Rust
https://github.com/statnett/quick-xmltodict
xml-deserialization xml-deserializer xml-parser xml-to-json
Last synced: 5 months ago
JSON representation
Efficient XML-to-dict conversion backed by Rust
- Host: GitHub
- URL: https://github.com/statnett/quick-xmltodict
- Owner: statnett
- License: mit
- Created: 2024-03-19T21:06:30.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-08-22T21:38:32.000Z (10 months ago)
- Last Synced: 2025-08-23T00:02:20.288Z (10 months ago)
- Topics: xml-deserialization, xml-deserializer, xml-parser, xml-to-json
- Language: Python
- Homepage:
- Size: 4.62 MB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# quick-xmltodict
Efficient XML-to-dict conversion backed by Rust.
```python
>>> from quick_xmltodict import parse
>>> xml = """
...
...
... Her
... Spike Jonze
... 2013
... Science Fiction, Drama, Romance
...
...
... Encanto
... Byron Howard, Jared Bush
... 2021
... Animation, Family, Fantasy
...
...
... """
>>> parse(xml)
{'movies': {'movie': [{'director': 'Spike Jonze',
'genre': 'Science Fiction, Drama, Romance',
'title': 'Her',
'year': '2013'},
{'director': 'Byron Howard, Jared Bush',
'genre': 'Animation, Family, Fantasy',
'title': 'Encanto',
'year': '2021'}]}}
```
## Features
`quick-xmltodict` is a Rust-backed XML-to-dict conversion package designed to be fast and efficient.
It has a single function, `parse`, that takes an XML string and returns a Python dictionary.
You should be able to use this function as a drop-in replacement for the `xmltodict.parse` function from the original `xmltodict` package (used without any extra arguments).
Like `xmltodict`, `quick-xmltodict` follows [this](https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html) schema for converting XML to JSON.
`quick-xmltodict` currently does not support namespace expansion, or the reverse operation (dict-to-XML conversion). For these features, use the original `xmltodict` package.
## Performance
Since `xmltodict` uses the non-validating C-based [expat](https://docs.python.org/3/library/pyexpat.html) parser from Python's standard library, it is already very fast.
`quick-xmltodict` is nonetheless about 2-5 times faster than `xmltodict`.
## Contributing
PRs are very welcome! Please make sure to run the tests before submitting a PR.
## Development
This project uses [uv](https://docs.astral.sh/uv/) to manage the environment and Python dependencies,
so you'll need to have it installed in addition to Python and Rust.
To install the development environment and run the test suite:
```bash
uv sync
uv run maturin develop --uv
uv run pytest
```
Be sure to run `uv run maturin develop --uv` after making changes to the Rust code.
Add the `-r` flag for a release build (for example, if you want to run benchmarks).
It's recommended to install the pre-commit hooks:
```bash
uv run pre-commit install
```
This ensures that linting and formatting are run automatically on every commit.