| 1 |
lxml |
| 2 |
==== |
| 3 |
|
| 4 |
.. meta:: |
| 5 |
:description: lxml - the most feature-rich and easy-to-use library for processing XML and HTML in the Python language |
| 6 |
:keywords: Python XML, XML processing, HTML, lxml, simple XML, ElementTree, etree, lxml.etree, objectify, XML parsing, XML validation, XPath, XSLT |
| 7 |
|
| 8 |
.. class:: pagequote |
| 9 |
|
| 10 |
| `» lxml takes all the pain out of XML. « <https://mailman-mail5.webfaction.com/pipermail/lxml/20080131/019119.html>`_ |
| 11 |
| Stephan Richter |
| 12 |
|
| 13 |
.. class:: eyecatcher |
| 14 |
|
| 15 |
lxml is the most feature-rich |
| 16 |
and easy-to-use library |
| 17 |
for processing XML and HTML |
| 18 |
in the Python language. |
| 19 |
|
| 20 |
.. |
| 21 |
1 Introduction |
| 22 |
2 Documentation |
| 23 |
3 Download |
| 24 |
4 Mailing list |
| 25 |
5 Bug tracker |
| 26 |
6 License |
| 27 |
7 Old Versions |
| 28 |
|
| 29 |
|
| 30 |
Introduction |
| 31 |
------------ |
| 32 |
|
| 33 |
The lxml XML toolkit is a Pythonic binding for the C libraries |
| 34 |
libxml2_ and libxslt_. It is unique in that it combines the speed and |
| 35 |
XML feature completeness of these libraries with the simplicity of a |
| 36 |
native Python API, mostly compatible but superior to the well-known |
| 37 |
ElementTree_ API. The latest release works with all CPython versions |
| 38 |
from 3.6 to 3.12. See the introduction_ for more information about |
| 39 |
background and goals of the lxml project. Some common questions are |
| 40 |
answered in the FAQ_. |
| 41 |
|
| 42 |
.. _libxml2: http://xmlsoft.org/ |
| 43 |
.. _libxslt: http://xmlsoft.org/XSLT/ |
| 44 |
|
| 45 |
.. _introduction: intro.html |
| 46 |
.. _FAQ: FAQ.html |
| 47 |
|
| 48 |
|
| 49 |
Documentation |
| 50 |
------------- |
| 51 |
|
| 52 |
.. The complete lxml documentation is available for download as `PDF documentation`_. |
| 53 |
|
| 54 |
The HTML documentation from this web site is part of |
| 55 |
the normal `source download <#download>`_. |
| 56 |
|
| 57 |
* Tutorials: |
| 58 |
|
| 59 |
* the `lxml.etree tutorial for XML processing`_ |
| 60 |
|
| 61 |
* John Shipman's tutorial on `Python XML processing with lxml`_ |
| 62 |
|
| 63 |
* Fredrik Lundh's `tutorial for ElementTree`_ |
| 64 |
|
| 65 |
* ElementTree: |
| 66 |
|
| 67 |
* `ElementTree API`_ |
| 68 |
|
| 69 |
* compatibility_ and differences of lxml.etree |
| 70 |
|
| 71 |
* `ElementTree performance`_ characteristics and comparison |
| 72 |
|
| 73 |
* lxml.etree: |
| 74 |
|
| 75 |
* `lxml.etree specific API`_ documentation |
| 76 |
|
| 77 |
* the `generated API documentation`_ as a reference |
| 78 |
|
| 79 |
* parsing_ and validating_ XML |
| 80 |
|
| 81 |
* `XPath and XSLT`_ support |
| 82 |
|
| 83 |
* Python `XPath extension functions`_ for XPath and XSLT |
| 84 |
|
| 85 |
* `custom XML element classes`_ for custom XML APIs (see `EuroPython 2008 talk`_) |
| 86 |
|
| 87 |
* a `SAX compliant API`_ for interfacing with other XML tools |
| 88 |
|
| 89 |
* a `C-level API`_ for interfacing with external C/Cython modules |
| 90 |
|
| 91 |
* lxml.objectify: |
| 92 |
|
| 93 |
* `lxml.objectify`_ API documentation |
| 94 |
|
| 95 |
* a brief comparison of `objectify and etree`_ |
| 96 |
|
| 97 |
lxml.etree follows the ElementTree_ API as much as possible, building |
| 98 |
it on top of the native libxml2 tree. If you are new to ElementTree, |
| 99 |
start with the `lxml.etree tutorial for XML processing`_. See also the |
| 100 |
ElementTree compatibility_ overview and the `ElementTree performance`_ |
| 101 |
page comparing lxml to the original ElementTree_ and cElementTree_ |
| 102 |
implementations. |
| 103 |
|
| 104 |
Right after the `lxml.etree tutorial for XML processing`_ and the |
| 105 |
ElementTree_ documentation, the next place to look is the `lxml.etree |
| 106 |
specific API`_ documentation. It describes how lxml extends the |
| 107 |
ElementTree API to expose libxml2 and libxslt specific XML |
| 108 |
functionality, such as XPath_, `Relax NG`_, `XML Schema`_, XSLT_, and |
| 109 |
`c14n`_ (including `c14n 2.0`_). |
| 110 |
Python code can be called from XPath expressions and XSLT |
| 111 |
stylesheets through the use of `XPath extension functions`_. lxml |
| 112 |
also offers a `SAX compliant API`_ that works with the SAX support in |
| 113 |
the standard library. |
| 114 |
|
| 115 |
There is a separate module `lxml.objectify`_ that implements a data-binding |
| 116 |
API on top of lxml.etree. See the `objectify and etree`_ FAQ entry for a |
| 117 |
comparison. |
| 118 |
|
| 119 |
In addition to the ElementTree API, lxml also features a sophisticated |
| 120 |
API for `custom XML element classes`_. This is a simple way to write |
| 121 |
arbitrary XML driven APIs on top of lxml. lxml.etree also has a |
| 122 |
`C-level API`_ that can be used to efficiently extend lxml.etree in |
| 123 |
external C modules, including fast custom element class support. |
| 124 |
|
| 125 |
.. _ElementTree: http://effbot.org/zone/element-index.htm |
| 126 |
.. _`ElementTree API`: http://effbot.org/zone/element-index.htm#documentation |
| 127 |
.. _cElementTree: http://effbot.org/zone/celementtree.htm |
| 128 |
|
| 129 |
.. _`tutorial for ElementTree`: https://web.archive.org/web/20200720191942/http://effbot.org:80/zone/element.htm |
| 130 |
.. _`lxml.etree tutorial for XML processing`: tutorial.html |
| 131 |
.. _`Python XML processing with lxml`: https://web.archive.org/web/20110108100213/https://infohost.nmt.edu/tcc/help/pubs/pylxml/ |
| 132 |
.. _`generated API documentation`: api/index.html |
| 133 |
.. _`ElementTree performance`: performance.html |
| 134 |
.. _`compatibility`: compatibility.html |
| 135 |
.. _`lxml.etree specific API`: api.html |
| 136 |
.. _`parsing`: parsing.html |
| 137 |
.. _`validating`: validation.html |
| 138 |
.. _`XPath and XSLT`: xpathxslt.html |
| 139 |
.. _`XPath extension functions`: extensions.html |
| 140 |
.. _`custom XML element classes`: element_classes.html |
| 141 |
.. _`SAX compliant API`: sax.html |
| 142 |
.. _`C-level API`: capi.html |
| 143 |
.. _`lxml.objectify`: objectify.html |
| 144 |
.. _`objectify and etree`: FAQ.html#what-is-the-difference-between-lxml-etree-and-lxml-objectify |
| 145 |
.. _`EuroPython 2008 talk`: s5/lxml-ep2008.html |
| 146 |
|
| 147 |
.. _XPath: https://www.w3.org/TR/xpath/ |
| 148 |
.. _`Relax NG`: https://relaxng.org/ |
| 149 |
.. _`XML Schema`: https://www.w3.org/XML/Schema |
| 150 |
.. _`XSLT`: https://www.w3.org/TR/xslt |
| 151 |
.. _`c14n`: https://www.w3.org/TR/xml-c14n |
| 152 |
.. _`c14n 2.0`: https://www.w3.org/TR/xml-c14n2 |
| 153 |
|
| 154 |
|
| 155 |
Download |
| 156 |
-------- |
| 157 |
|
| 158 |
The best way to download lxml is to visit `lxml at the Python Package |
| 159 |
Index <http://pypi.python.org/pypi/lxml/>`_ (PyPI). It has the source |
| 160 |
that compiles on various platforms. The source distribution is signed |
| 161 |
with `this key <pubkey.asc>`_. |
| 162 |
|
| 163 |
The latest version is `lxml 6.1.3`_, released 2026-09-02 |
| 164 |
(`changes for 6.1.3`_). `Older versions <#old-versions>`_ |
| 165 |
are listed below. |
| 166 |
|
| 167 |
Please take a look at the |
| 168 |
`installation instructions <installation.html>`_ ! |
| 169 |
|
| 170 |
This complete website (including the generated API documentation) is |
| 171 |
part of the source distribution, so if you want to download the |
| 172 |
documentation for offline use, take the source archive and copy the |
| 173 |
``doc/html`` directory out of the source tree. |
| 174 |
|
| 175 |
.. , or use the `PDF documentation`_. |
| 176 |
|
| 177 |
The latest `installable developer sources <https://github.com/lxml/lxml/archive/master.zip>`_ |
| 178 |
are available from Github. It's also possible to check out |
| 179 |
the latest development version of lxml from Github directly, using a command |
| 180 |
like this:: |
| 181 |
|
| 182 |
git clone https://github.com/lxml/lxml.git lxml |
| 183 |
|
| 184 |
You can browse the `source repository`_ and its history through |
| 185 |
the web. Please read `how to build lxml from source <build.html>`_ |
| 186 |
first. The `latest CHANGES`_ of the developer version are also |
| 187 |
accessible. You can check there if a bug you found has been fixed |
| 188 |
or a feature you want has been implemented in the latest trunk version. |
| 189 |
|
| 190 |
.. _`source repository`: https://github.com/lxml/lxml/ |
| 191 |
.. _`latest CHANGES`: https://github.com/lxml/lxml/blob/master/CHANGES.txt |
| 192 |
|
| 193 |
|
| 194 |
Mailing list |
| 195 |
------------ |
| 196 |
|
| 197 |
Questions? Suggestions? Code to contribute? We have a `mailing list`_. |
| 198 |
|
| 199 |
You can also `search the archive`_ for past questions and discussions. |
| 200 |
|
| 201 |
.. _`search the archive`: https://mail.python.org/archives/list/[email protected]/ |
| 202 |
.. _`mailing list`: https://lxml.de/mailinglist/ |
| 203 |
|
| 204 |
|
| 205 |
Bug tracker |
| 206 |
----------- |
| 207 |
|
| 208 |
lxml uses the `launchpad bug tracker`_. If you are sure you found a |
| 209 |
bug in lxml, please file a bug report there. If you are not sure |
| 210 |
whether some unexpected behaviour of lxml is a bug or not, please |
| 211 |
check the documentation and ask on the `mailing list`_ first. Do not |
| 212 |
forget to `search the archive`_! |
| 213 |
|
| 214 |
.. _`launchpad bug tracker`: https://launchpad.net/lxml/ |
| 215 |
|
| 216 |
|
| 217 |
License |
| 218 |
------- |
| 219 |
|
| 220 |
The lxml library is shipped under a `BSD license`_. libxml2 and libxslt2 |
| 221 |
itself are shipped under the `MIT license`_. There should therefore be no |
| 222 |
obstacle to using lxml in your codebase. |
| 223 |
|
| 224 |
.. _`BSD license`: https://github.com/lxml/lxml/blob/master/doc/licenses/BSD.txt |
| 225 |
.. _`MIT license`: https://opensource.org/licenses/mit-license.html |
| 226 |
|
| 227 |
|
| 228 |
Old Versions |
| 229 |
------------ |
| 230 |
|
| 231 |
See the websites of lxml |
| 232 |
`6.0 <https://lxml.de/6.0/>`_, |
| 233 |
`5.4 <https://lxml.de/5.4/>`_, |
| 234 |
`5.3 <https://lxml.de/5.3/>`_, |
| 235 |
`5.2 <https://lxml.de/5.2/>`_, |
| 236 |
`5.1 <https://lxml.de/5.1/>`_, |
| 237 |
`5.0 <https://lxml.de/5.0/>`_, |
| 238 |
`4.9 <https://lxml.de/4.9/>`_, |
| 239 |
`4.8 <https://lxml.de/4.8/>`_, |
| 240 |
`4.7 <https://lxml.de/4.7/>`_, |
| 241 |
`4.6 <https://lxml.de/4.6/>`_, |
| 242 |
`4.5 <https://lxml.de/4.5/>`_, |
| 243 |
`4.4 <https://lxml.de/4.4/>`_, |
| 244 |
`4.3 <https://lxml.de/4.3/>`_, |
| 245 |
`4.2 <https://lxml.de/4.2/>`_, |
| 246 |
`4.1 <https://lxml.de/4.1/>`_, |
| 247 |
`4.0 <https://lxml.de/4.0/>`_, |
| 248 |
`3.8 <https://lxml.de/3.8/>`_, |
| 249 |
`3.7 <https://lxml.de/3.7/>`_, |
| 250 |
`3.6 <https://lxml.de/3.6/>`_, |
| 251 |
`3.5 <https://lxml.de/3.5/>`_, |
| 252 |
`3.4 <https://lxml.de/3.4/>`_, |
| 253 |
`3.3 <https://lxml.de/3.3/>`_, |
| 254 |
`3.2 <https://lxml.de/3.2/>`_, |
| 255 |
`3.1 <https://lxml.de/3.1/>`_, |
| 256 |
`3.0 <https://lxml.de/3.0/>`_, |
| 257 |
`2.3 <https://lxml.de/2.3/>`_, |
| 258 |
`2.2 <https://lxml.de/2.2/>`_, |
| 259 |
`2.1 <https://lxml.de/2.1/>`_, |
| 260 |
`2.0 <https://lxml.de/2.0/>`_, |
| 261 |
`1.3 <https://lxml.de/1.3/>`_ |
| 262 |
|
| 263 |
.. |
| 264 |
and the `latest in-development version <https://lxml.de/dev/>`_. |
| 265 |
|
| 266 |
.. _`PDF documentation`: lxmldoc-6.1.3.pdf |
| 267 |
|
| 268 |
* `lxml 6.1.3`_, released 2026-09-02 (`changes for 6.1.3`_) |
| 269 |
|
| 270 |
* `lxml 6.1.2`_, released 2026-08-18 (`changes for 6.1.2`_) |
| 271 |
|
| 272 |
* `lxml 6.1.1`_, released 2026-05-18 (`changes for 6.1.1`_) |
| 273 |
|
| 274 |
* `lxml 6.1.0`_, released 2026-04-17 (`changes for 6.1.0`_) |
| 275 |
|
| 276 |
* `lxml 6.0.4`_, released 2026-04-12 (`changes for 6.0.4`_) |
| 277 |
|
| 278 |
* `lxml 6.0.3`_, released 2026-04-09 (`changes for 6.0.3`_) |
| 279 |
|
| 280 |
* `lxml 6.0.2`_, released 2025-09-21 (`changes for 6.0.2`_) |
| 281 |
|
| 282 |
* `lxml 6.0.1`_, released 2025-08-22 (`changes for 6.0.1`_) |
| 283 |
|
| 284 |
* `lxml 6.0.0`_, released 2025-06-26 (`changes for 6.0.0`_) |
| 285 |
|
| 286 |
* `lxml 5.4.0`_, released 2025-04-22 (`changes for 5.4.0`_) |
| 287 |
|
| 288 |
* `older releases <https://lxml.de/5.4/#old-versions>`_ |
| 289 |
|
| 290 |
.. _`lxml 6.1.3`: /files/lxml-6.1.3.tgz |
| 291 |
.. _`lxml 6.1.2`: /files/lxml-6.1.2.tgz |
| 292 |
.. _`lxml 6.1.1`: /files/lxml-6.1.1.tgz |
| 293 |
.. _`lxml 6.1.0`: /files/lxml-6.1.0.tgz |
| 294 |
.. _`lxml 6.0.4`: /files/lxml-6.0.4.tgz |
| 295 |
.. _`lxml 6.0.3`: /files/lxml-6.0.3.tgz |
| 296 |
.. _`lxml 6.0.2`: /files/lxml-6.0.2.tgz |
| 297 |
.. _`lxml 6.0.1`: /files/lxml-6.0.1.tgz |
| 298 |
.. _`lxml 6.0.0`: /files/lxml-6.0.0.tgz |
| 299 |
.. _`lxml 5.4.0`: /files/lxml-5.4.0.tgz |
| 300 |
|
| 301 |
.. _`changes for 6.1.3`: /changes-6.1.3.html |
| 302 |
.. _`changes for 6.1.2`: /changes-6.1.2.html |
| 303 |
.. _`changes for 6.1.1`: /changes-6.1.1.html |
| 304 |
.. _`changes for 6.1.0`: /changes-6.1.0.html |
| 305 |
.. _`changes for 6.0.4`: /changes-6.0.4.html |
| 306 |
.. _`changes for 6.0.3`: /changes-6.0.3.html |
| 307 |
.. _`changes for 6.0.2`: /changes-6.0.2.html |
| 308 |
.. _`changes for 6.0.1`: /changes-6.0.1.html |
| 309 |
.. _`changes for 6.0.0`: /changes-6.0.0.html |
| 310 |
.. _`changes for 5.4.0`: /changes-5.4.0.html |