Skip to main content

Rust-backed xmltodict-compatible XML parser/emitter with PyO3 bindings

Project description

orxml

Rust-backed XML ↔ Python dict conversion, API-compatible with the common surface of [xmltodict](https://github.com/martinblech/xmltodict). 3–8× faster on a representative corpus.

Uses the BadgerFish-lite convention: @ prefix for attributes, #text for text content, lists for repeated sibling elements. Because the shape is JSON-compatible, any parsed dict feeds straight into json.dumps.

Install (from source)

git clone https://github.com/bohdanhr/orxml
cd orxml
uv sync
uv run maturin develop --release

Requires a stable Rust toolchain and Python 3.11+.

Usage

import orxml

doc = orxml.parse("<a prop='x'>hello</a>")
# {'a': {'@prop': 'x', '#text': 'hello'}}

xml = orxml.unparse(doc)

Supported options

parse: attr_prefix, cdata_key, force_cdata (bool / tuple / list), cdata_separator, strip_whitespace, namespace_separator, process_namespaces, namespaces, process_comments, comment_key, force_list (bool / tuple / list), disable_entities, xml_attribs.

unparse: attr_prefix, cdata_key, comment_key, namespaces, namespace_separator, pretty, newl, indent (str or int), full_document, short_empty_elements, encoding.

Out-of-scope options (postprocessor, item_callback / item_depth streaming, callable force_list / force_cdata, dict_constructor, preprocessor, expand_iter, file-like / generator inputs) raise NotImplementedError if passed. Unknown options raise TypeError.

Parity

Behavior is matched on the observable surface: for every supported option combination, orxml.parse(xml) == xmltodict.parse(xml) and xmltodict.parse(orxml.unparse(d)) == d. Intentional divergences:

  • Exception classes: orxml.ParseError (a ValueError), not xml.parsers.expat.ExpatError.
  • Error messages and byte-level unparse output (e.g. attribute ordering) are not guaranteed identical.
  • Behavior on malformed XML is not defined.

Benchmarks

Run on an Apple Silicon laptop comparing orxml against xmltodict 0.14:

Operation Fixture orxml (mean) xmltodict (mean) Speedup
parse tiny.xml 3.55 µs 14.43 µs 4.07×
parse small.xml 33.56 µs 119.78 µs 3.57×
parse rss.xml 36.94 µs 131.46 µs 3.56×
parse soap.xml 30.11 µs 134.53 µs 4.47×
parse large_synthetic.xml 51.20 ms 162.10 ms 3.17×
unparse tiny.xml 2.56 µs 11.53 µs 4.51×
unparse small.xml 25.28 µs 108.40 µs 4.29×
unparse rss.xml 27.67 µs 112.74 µs 4.07×
unparse soap.xml 18.52 µs 88.06 µs 4.75×
unparse large_synthetic.xml 33.17 ms 257.12 ms 7.75×

Reproduce locally with make bench.

Development

make sync        # uv sync
make build       # maturin develop --release
make test        # pytest
make bench       # pytest-benchmark
make lint        # ruff check
make fmt         # ruff format
make typecheck   # ty check
make all         # sync + build + lint + typecheck + test

Corpus

bench/corpus/ holds fixtures used by both tests and benchmarks: tiny.xml, small.xml, rss.xml, soap.xml, and large_synthetic.xml. The last one is generated — regenerate it (or resize it) with:

uv run python bench/corpus/generate_large.py 5000   # ~3 MB

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

orxml-0.1.0.tar.gz (208.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

orxml-0.1.0-cp311-abi3-win_amd64.whl (314.6 kB view details)

Uploaded CPython 3.11+Windows x86-64

orxml-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl (647.2 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ x86-64

orxml-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl (612.9 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ ARM64

orxml-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (434.2 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

orxml-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (435.9 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

orxml-0.1.0-cp311-abi3-macosx_11_0_arm64.whl (407.1 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

orxml-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl (411.6 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file orxml-0.1.0.tar.gz.

File metadata

  • Download URL: orxml-0.1.0.tar.gz
  • Upload date:
  • Size: 208.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for orxml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dceb9210bc0f3605c939430494871f6e224418a384bd9f021e4fa36fee32f645
MD5 0ae8797f51e655f5092940033c666f6b
BLAKE2b-256 9251d691e9a3a67c721c2d65095fa16fa8ca30cb798755be6849ef5e86dc2345

See more details on using hashes here.

Provenance

The following attestation bundles were made for orxml-0.1.0.tar.gz:

Publisher: release.yml on bohdanhr/orxml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file orxml-0.1.0-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: orxml-0.1.0-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 314.6 kB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for orxml-0.1.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f0e654c9999d953c3a98c7819673266c3a8e8f9139ad10c39dccb9b09be100f9
MD5 0149e9896e6bad2b65ceb2b62aa0a6b1
BLAKE2b-256 a89dfb2e9cd4f6af7c9c13907940a876e7a0b8c4611e2791ecda3bc931163f14

See more details on using hashes here.

Provenance

The following attestation bundles were made for orxml-0.1.0-cp311-abi3-win_amd64.whl:

Publisher: release.yml on bohdanhr/orxml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file orxml-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for orxml-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b4e2a2183771fac29d1671a7dfdc07c55f353ed6b58f86bb7b9f55b944c79c53
MD5 b34e2bbcdfaf290dafdee12cbf0f8006
BLAKE2b-256 186f26ecdefe6a1f27bdeda38d41c4016dfb53a5e28a4f8ff817f1754a8656bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for orxml-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on bohdanhr/orxml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file orxml-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for orxml-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 015877600c96f90d687b9bef0b5ed00a76eb65dc0f12460d94fd6b3a269633fe
MD5 7e47a4e0a3f17f024324a4203060656e
BLAKE2b-256 b60000bcc0835d7d22a335a3db18d8ee43e8568e0315f5679aba948fd9dbeae6

See more details on using hashes here.

Provenance

The following attestation bundles were made for orxml-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on bohdanhr/orxml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file orxml-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for orxml-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc170cf004e0c273dec41edaddf584ad010e6517245110c6e9e1fb0cb0b83e04
MD5 59a374c6a4e7679012d6a4931fcb4b36
BLAKE2b-256 9dd7442ee29d9df190c29f419e2a9184004f57a0186ca61eba569a82bb0e1369

See more details on using hashes here.

Provenance

The following attestation bundles were made for orxml-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on bohdanhr/orxml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file orxml-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for orxml-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 effb3cc926ec468a6ccf72ea4c13532ad18f13e2066f04af8f326dee163c90df
MD5 d7f788a12836dad82f9460ea6fc01167
BLAKE2b-256 f783cb6e8235920b9528c68da5d7fcb345c0c43ac688fb4311fbc6c71034cdbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for orxml-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on bohdanhr/orxml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file orxml-0.1.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: orxml-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 407.1 kB
  • Tags: CPython 3.11+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for orxml-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b9be6d81373bea8fee0ec7dc30c17e800504edca0258cb5a40e7921d2e39ab8
MD5 51ee2edff350de8ccdd917d2bf2878a1
BLAKE2b-256 bd468899118317102f74a647f882ee54598c8f1d57274d1ee4c8ee15205f89d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for orxml-0.1.0-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on bohdanhr/orxml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file orxml-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for orxml-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9c5cae98043b59c7c52a2998d1080a1d1798593ecd3e6ccf7618fa23fae182ee
MD5 d2274addd6e7c9f00d06f6bc28a8373b
BLAKE2b-256 f1dab0ca6a342e05bfde5d4d8d31de667d825bcfa849e75abc15bdaf389ca818

See more details on using hashes here.

Provenance

The following attestation bundles were made for orxml-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on bohdanhr/orxml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page