Skip to main content

Fast XML flattening library with Python bindings

Project description

fast-xml-flattener

PyPI Python License: MIT Rust CI codecov

Flatten nested XML into CSV, JSON, Parquet, or Python dicts — in milliseconds, not seconds.

fast-xml-flattener is a Rust-powered Python library that converts XML documents into flat, analysis-ready representations. It uses a zero-copy streaming parser and builds output structures in a single tree walk, with no intermediate serde_json::Value or DOM allocation. The result: throughput that leaves pure-Python parsers far behind.


Why fast-xml-flattener?

XML → flat dict (median of 7 runs, CPython 3.13)

Library 0.5 MB 5.4 MB 27 MB
fast-xml-flattener 11 ms 225 ms 1 089 ms
lxml + manual flatten 27 ms 407 ms 2 108 ms
xmltodict + manual flatten 63 ms 997 ms 4 952 ms

XML → flat JSON string (median of 7 runs)

Library 0.5 MB 5.4 MB 27 MB
fast-xml-flattener 13 ms 164 ms 884 ms
xmltodict + json.dumps 93 ms 1 147 ms 5 374 ms

Dell Vostro i7-1260P, 64 GB RAM, Linux, CPython 3.13. Synthetic XML with nested records (id, user, address, order fields). See benches/benchmark.py.

4–7× faster than xmltodict, 2–2.5× faster than lxml across all tested sizes. The gap widens with document size because the Rust parser operates at memory-bandwidth speed with zero DOM allocation. The GIL is held only for dict-returning functions (to_dict, to_flatten_dict); all other outputs release it entirely, making the library safe to use from thread pools.


Features

  • Flatten nested XML into JSON, flatten-JSON, native Python dict, flatten-dict, CSV, or Parquet
  • Single-pass streaming parser — no DOM, no intermediate Value allocation
  • GIL-free for string/CSV/Parquet outputs — safe to use from thread pools
  • xmltodict-compatible semantics: @attr, #text, auto-list for repeated tags
  • Namespace stripping, CDATA, entity references, comments — all handled correctly
  • Supports Python 3.10+

Output Formats

Function Returns Description
to_json(xml) str 1:1 JSON preserving XML structure (@attr, #text)
to_flatten_json(xml, separator=".") str Flat JSON with dot-notation keys (user.address.city)
to_dict(xml) dict 1:1 nested Python dict — built directly in Rust, no JSON round-trip
to_flatten_dict(xml, separator=".") dict Flat Python dict with dot-notation keys
to_csv(xml, include_attrs=True) str Tabular CSV, one row per XML record
to_parquet(xml, path, include_attrs=True) None Columnar Parquet file for big-data workflows

Installation

pip install fast-xml-flattener

Quick Start

import fast_xml_flattener as fxf

xml = """
<root>
  <user>
    <id>1</id>
    <name>Alice</name>
    <address>
      <city>Warsaw</city>
      <zip>00-001</zip>
    </address>
  </user>
</root>
"""

# 1:1 JSON string — preserves nesting
result = fxf.to_json(xml)
# '{"user": {"id": "1", "name": "Alice", "address": {"city": "Warsaw", "zip": "00-001"}}}'

# Flattened JSON string with dot-notation keys
flat = fxf.to_flatten_json(xml)
# '{"user.id": "1", "user.name": "Alice", "user.address.city": "Warsaw", "user.address.zip": "00-001"}'

# Native Python dict (1:1 nested) — no JSON round-trip
d = fxf.to_dict(xml)
print(d["user"]["name"])             # Alice
print(d["user"]["address"]["city"])  # Warsaw

# Flattened native Python dict
fd = fxf.to_flatten_dict(xml, separator=".")
print(fd["user.address.city"])       # Warsaw

# CSV — one row per <user> element
csv = fxf.to_csv(xml, include_attrs=True)

# Parquet — ready for pandas / Spark / DuckDB
fxf.to_parquet(xml, path="output.parquet", include_attrs=True)

Loading Parquet with pandas

import pandas as pd

df = pd.read_parquet("output.parquet")
print(df.head())

Using with DuckDB

import duckdb

duckdb.sql("SELECT * FROM 'output.parquet'").show()

Development

Requirements

  • Python 3.10+ (3.13 recommended for development)
  • Rust (stable)
  • maturin

Setup with pyenv (recommended)

# Install pyenv: https://github.com/pyenv/pyenv
pyenv install 3.13
pyenv local 3.13

# Create and activate virtual environment
pyenv virtualenv 3.13 xml-flattener
pyenv activate xml-flattener

# Install uv and dev dependencies
pip install uv
uv pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

Setup without pyenv

python -m venv venv
source venv/bin/activate
pip install uv
uv pip install -e ".[dev]"
pre-commit install

Build

uv run maturin develop   # development build
maturin build --release  # release wheel

Tests

uv run pytest            # Python integration tests (52 cases)
cargo test               # Rust unit tests (25 cases)
uv run ruff check .      # linting
cargo clippy --all-targets -- -D warnings  # Rust linting

Releasing

Releases are fully automated. Append one of these tags anywhere in your commit message (or PR title when squash-merging) to trigger a release:

Tag Bump Example
[fix] patch (0.1.0 → 0.1.1) fix null value in CSV output [fix]
[minor] minor (0.1.0 → 0.2.0) add streaming API [minor]
[major] major (0.1.0 → 1.0.0) redesign public API [major]

The release pipeline then:

  1. Bumps version in Cargo.toml and pyproject.toml
  2. Prepends an entry to CHANGELOG.md
  3. Commits (chore: bump version to X.Y.Z) and creates a vX.Y.Z git tag
  4. Builds wheels for Linux x86_64/aarch64, macOS universal2, Windows x86_64
  5. Publishes to PyPI via OIDC trusted publishing (no secrets needed)
  6. Creates a GitHub Release with the changelog entry and wheel artifacts

One-time PyPI setup (trusted publishing)

  1. Go to PyPI → Your projects → fast-xml-flattener → Publishing → Add a publisher
  2. Set: GitHub owner andree0, repo fast-xml-flattener, workflow release.yml, environment pypi
  3. On GitHub: Settings → Environments → New environment named pypi

No API tokens or secrets are required — OIDC handles authentication.

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

fast_xml_flattener-0.1.5.tar.gz (35.4 kB view details)

Uploaded Source

Built Distributions

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

fast_xml_flattener-0.1.5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

fast_xml_flattener-0.1.5-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

fast_xml_flattener-0.1.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

fast_xml_flattener-0.1.5-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

fast_xml_flattener-0.1.5-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

fast_xml_flattener-0.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

fast_xml_flattener-0.1.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

fast_xml_flattener-0.1.5-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (2.5 MB view details)

Uploaded CPython 3.13macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

fast_xml_flattener-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fast_xml_flattener-0.1.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

fast_xml_flattener-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fast_xml_flattener-0.1.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

fast_xml_flattener-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fast_xml_flattener-0.1.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

File details

Details for the file fast_xml_flattener-0.1.5.tar.gz.

File metadata

  • Download URL: fast_xml_flattener-0.1.5.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for fast_xml_flattener-0.1.5.tar.gz
Algorithm Hash digest
SHA256 0cdaa6f3ca4de5a4b050d8841e455a99d12d848f1b30d44244f2faabd0669f13
MD5 89606c4823d2e0f9bd75d5c84711361c
BLAKE2b-256 b7f1b71278507c01a5977487f440e2cd0548a462d44121bddf74e70ce82c547f

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 300eff907ad6d9d4248e248165093aeda50053447818d4d963df7ad5e8f0686f
MD5 eec113343c0898dc7efcf70debe07377
BLAKE2b-256 22ec7d2f794f11156a48e28f8771fea61e7ff6e53a2431848a5e126e79e4b19f

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a2851bdb15924bb4be2b67fa4f7ba582df5bc3dd3b887be7dece0a2b991a08fd
MD5 f769130266e17bb35e5ab7ccd0c219ee
BLAKE2b-256 6edbfd5106bf89dab3e07983f52ce6f907152971b05787a80cdcddd90a7a3f65

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b349d993870e300c38552757f3d60162429dd42bcdd937b9e37e8f41441e04ea
MD5 22f913f40c7b19860fa7cbd5c5aaff5a
BLAKE2b-256 04109abeccde2eed62975f6e9f333ecbc02e5abf4f840819f87363386618afb9

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b42bfc4bfeb83774e0e8ef585222c6ea61c0841f6b6df54763f7dda46575dd87
MD5 8310a87965d302a9207976664b4f6c35
BLAKE2b-256 f82e39310e9b7dc2f81a2188d466b623fe05e92e6847e41eac4113db70ced5bd

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 45cd66e411874b0cd246d09fb7b1703f9566b453c636954738a7261c2c38f138
MD5 9f887c206c5a8e582e671e79ac0a35ee
BLAKE2b-256 8b11b08df98e1c9738f4c41c4fe3786d6f410830520dd97bc56cd440eeb11598

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a69c908bbbd817c6723a928fe5e4390340b2c77a98c9a65ffa2f3d69402791ae
MD5 ffcf9636eb1080448f9380b838a036e6
BLAKE2b-256 67c3c240de25acc98c1fd557b11f06b0f2aa51464b0fbb7b8dce23d4b76d67a7

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6fc9495776664394106f8832fed946c7f3e60f87b9ac5d6c4fede0303162c79d
MD5 612c736bef756538d4f924588208e2ee
BLAKE2b-256 a67f7ab4f3cf74150c3ed9565f92dd3c7b08b85fd64cae46e8b3f7f0afda9eec

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9ca4370e123437e726e3e2355b3132bc1993ea1b6a55a2bd74a0b969bfa5d1fc
MD5 2bf9338f8fc9d8fc664b67fe1f1debe8
BLAKE2b-256 90003e5bbb43e83fc7e9f5dcd9163628495cfba01cd863a17c5b3ad6d1850181

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 3afdc9d6b3bcb61e716b1a963c3a356182efc35f72e9af8556e98b1ac52ed76d
MD5 49b6cd986d3fcdeeabba7a5c6d724e2c
BLAKE2b-256 668e8a0ed384507153bf6a45c256e67dd0b023b841a15ac8f311dc62bf606c1e

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9529ed861442b012748cdb1878f7116047b7a051278574b211f69b33220235c4
MD5 12749b2963397d8059a7503dad13b05b
BLAKE2b-256 0765cf39e8344dcb8df9ec5c3fcc8f00173ad5996602f220f36b0b4a771587c2

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fc594fe56914f791d5f946b5a0ad969ead2487c3e0188e3ef6aef5f8053c3235
MD5 f88fdda96e72286fe814b33daa5ea226
BLAKE2b-256 a6f00b3b42257b7f581bea09a62bde80ea6c2aba4234480884052d2bd67ed809

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e7229fe28ea0ae9f4eaedc779d271c8b176b44cd600b8fd6ee6e308dc0b7a8a7
MD5 74a6378f0e7ae93648f9dfaa27ffa25e
BLAKE2b-256 1d26588de2b957d0147261132dbb8b2b15f4d3c166d7442a9695972b34249774

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d2fd084d1d569613b4a56308a8c80335a47a7a434358ba326b5b7cf1d663f67c
MD5 ed1420a7143e6180d78fe16671d0be42
BLAKE2b-256 fef38cfb52bec784a9d732d15d3baa3fce25e24e80200154aac3741b703652b7

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 69caec9055b548a14bdd744d2530861e0ddc796cd104e0f9d89d96f6ae6029fc
MD5 78b9658913c32f62b774332d744e7e8c
BLAKE2b-256 d5286ac8ef7ff831c86a6c66886ada809071e221200be25907c12a68dd546efb

See more details on using hashes here.

File details

Details for the file fast_xml_flattener-0.1.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fast_xml_flattener-0.1.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8764cb71b215c61f1dc21e0044830a44fc816a75ad342fe785f860b782c2931c
MD5 2ee4acfea77134f33fee19cc2bc3cd31
BLAKE2b-256 c4b90c2e5a43cb7b213865f901583524d69d3425a8a0e52f33dc8e8ada5852f2

See more details on using hashes here.

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