xmltodict VS lxml

Compare xmltodict vs lxml and see what are their differences.

xmltodict

Python module that makes working with XML feel like you are working with JSON (by martinblech)

lxml

The lxml XML toolkit for Python (by lxml)
Our great sponsors
  • InfluxDB - Build time-series-based applications quickly and at scale.
  • Zigi - Delete the most useless function ever: context switching.
  • Sonar - Write Clean Python Code. Always.
  • Scout APM - Truly a developer’s best friend
xmltodict lxml
6 16
4,981 2,232
- 1.7%
0.0 8.3
2 months ago 17 days ago
Python Python
MIT License BSD 3-clause "New" or "Revised" License
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

xmltodict

Posts with mentions or reviews of xmltodict. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2022-03-28.
  • Top python libraries/ frameworks that you suggest every one
    15 projects | reddit.com/r/Python | 28 Mar 2022
    Nope, sorry, it's just an XML generator. The Python stdlib offers https://docs.python.org/3/library/xml.etree.elementtree.html and PyPI offers https://github.com/martinblech/xmltodict for parsing, and you could write CSV with csvwriter or pandas.
  • Like JQ, but for HTML
    21 projects | news.ycombinator.com | 7 Sep 2021
    xmlstarlet is really nothing like jq, as a language. But yes, I use it because it is the best commandline xml processor I'd found. That's the only similarity to jq.

    Is this the yq? https://kislyuk.github.io/yq/ It does contain an 'xq', as a literal wrapper for jq, piping output into it after transcoding XML to JSON using xmltodict https://github.com/martinblech/xmltodict (which explodes xml into separate JSON data structures).

    This is a bash one-liner! But TBF it really is a 'jq for xml'. I think it would be horrible for some things, but you could also do a lot of useful things painlessly.

lxml

Posts with mentions or reviews of lxml. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2022-10-07.
  • 13 ways to scrape any public data from any website
    6 projects | dev.to | 7 Oct 2022
    Parsel is a library build to extract data from XML/HTML documents with XPath and CSS selectors support, and could be combined with regular expressions. It's usees lxml parser under the hood by default.
  • lazy and fast .mpd file parser - for video streaming
    2 projects | reddit.com/r/Python | 13 Aug 2022
    So, now that I no longer work in that industry, and I had some free time, I created a lazy parsing package using lxml instead of the xml parser in the standard library, which can help people who want to have a python only parsing solution.
  • There is framework for everything.
    107 projects | reddit.com/r/ProgrammerHumor | 4 Aug 2022
  • Parsing XML file deletes whitespace. How to avoid it?
    2 projects | reddit.com/r/learnpython | 2 Apr 2022
    I got curious about this now so I did some tests on my own, and it appears that the XML parser implementation in Python does indeed strip all newline characters from attributes. Whether this is according to XML standard I do not know; I also briefly tried an alternative XML implementation for Python and it behaves the same, so I would assume that this is standard behavior, but I'm not knowledgable enough about XML to say for certain.
  • Use case for ETL over ELT?
    2 projects | reddit.com/r/dataengineering | 27 Mar 2022
    I use lxml for the XML parsing and pyodbc as the ODBC library. We have a small team so I just keep it as simple as possible: 1. A cursor yields the XML documents from a SQL query as a stream 2. A generator function parses the XML document and yields the rows (you could parallelize this step) 3. Stream each of the resulting rows to a single CSV file 4. Scoop up the resulting CSV file into the target database (usually with the DB engine's loader; bulk insert isn't so fast over ODBC) It ends up being a straight forward, low-overhead approach.
  • How do i go about building a vidoe conferencing app?
    10 projects | reddit.com/r/rust | 20 Aug 2021
    Generally, I'm already using Python to glue together things like OpenCV or libxml, which do the heavy-lifting, and taking advantage of how things like Qt's QImage release Python's Global Interpreter Lock, allowing me to load and process images on a background thread, so the Python code itself is usually already I/O-bound, but yes. If the Python code would become a bottleneck, it helps with that too.
  • Big brained meme I created
    2 projects | reddit.com/r/ProgrammerHumor | 25 Jul 2021
  • Where to start: Learning Web-scraping
    2 projects | reddit.com/r/learnpython | 26 Jun 2021
    lxml is an XML parser however, it also supports HTML parsing. It's blazing fast and supports XPath. I think it isn't as beginner friendly to use, though it has detailed documentation. It works less well with heavily broken HTML documents and the encoding detection isn't as good as the one of BS4.
  • Python is better than C they said
    4 projects | reddit.com/r/ProgrammerHumor | 6 Jun 2021
    According to lxml benchmarking docs, Python’s built in xml parser wouldn’t behave that bad either: https://github.com/lxml/lxml/blob/master/doc/performance.txt
    4 projects | reddit.com/r/ProgrammerHumor | 6 Jun 2021

What are some alternatives?

When comparing xmltodict and lxml you can also consider the following projects:

untangle - Converts XML to Python objects

html5lib - Standards-compliant library for parsing and serializing HTML documents and fragments in Python

pyquery - A jquery-like library for python

selectolax - Python binding to Modest and Lexbor engines (fast HTML5 parser with CSS selectors).

bleach - Bleach is an allowed-list-based HTML sanitizing library that escapes or strips markup and attributes

rust-cpython - Rust <-> Python bindings

MarkupSafe - Safely add untrusted strings to HTML/XML markup.

gazpacho - 🥫 The simple, fast, and modern web scraping library

xmldataset - xmldataset: xml parsing made easy 🗃️