| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- lxml
- ====
- .. meta::
- :description: lxml - the most feature-rich and easy-to-use library for processing XML and HTML in the Python language
- :keywords: Python XML, XML processing, HTML, lxml, simple XML, ElementTree, etree, lxml.etree, objectify, XML parsing, XML validation, XPath, XSLT
- .. class:: pagequote
- | `» lxml takes all the pain out of XML. « <https://mailman-mail5.webfaction.com/pipermail/lxml/20080131/019119.html>`_
- | Stephan Richter
- .. class:: eyecatcher
- lxml is the most feature-rich
- and easy-to-use library
- for processing XML and HTML
- in the Python language.
- ..
- 1 Introduction
- 2 Documentation
- 3 Download
- 4 Mailing list
- 5 Bug tracker
- 6 License
- 7 Old Versions
- Introduction
- ------------
- The lxml XML toolkit is a Pythonic binding for the C libraries
- libxml2_ and libxslt_. It is unique in that it combines the speed and
- XML feature completeness of these libraries with the simplicity of a
- native Python API, mostly compatible but superior to the well-known
- ElementTree_ API. The latest release works with all CPython versions
- from 2.7 to 3.9. See the introduction_ for more information about
- background and goals of the lxml project. Some common questions are
- answered in the FAQ_.
- .. _libxml2: http://xmlsoft.org/
- .. _libxslt: http://xmlsoft.org/XSLT/
- .. _introduction: intro.html
- .. _FAQ: FAQ.html
- Documentation
- -------------
- .. The complete lxml documentation is available for download as `PDF documentation`_.
- The HTML documentation from this web site is part of
- the normal `source download <#download>`_.
- * Tutorials:
- * the `lxml.etree tutorial for XML processing`_
- * John Shipman's tutorial on `Python XML processing with lxml`_
- * Fredrik Lundh's `tutorial for ElementTree`_
- * ElementTree:
- * `ElementTree API`_
- * compatibility_ and differences of lxml.etree
- * `ElementTree performance`_ characteristics and comparison
- * lxml.etree:
- * `lxml.etree specific API`_ documentation
- * the `generated API documentation`_ as a reference
- * parsing_ and validating_ XML
- * `XPath and XSLT`_ support
- * Python `XPath extension functions`_ for XPath and XSLT
- * `custom XML element classes`_ for custom XML APIs (see `EuroPython 2008 talk`_)
- * a `SAX compliant API`_ for interfacing with other XML tools
- * a `C-level API`_ for interfacing with external C/Cython modules
- * lxml.objectify:
- * `lxml.objectify`_ API documentation
- * a brief comparison of `objectify and etree`_
- lxml.etree follows the ElementTree_ API as much as possible, building
- it on top of the native libxml2 tree. If you are new to ElementTree,
- start with the `lxml.etree tutorial for XML processing`_. See also the
- ElementTree compatibility_ overview and the `ElementTree performance`_
- page comparing lxml to the original ElementTree_ and cElementTree_
- implementations.
- Right after the `lxml.etree tutorial for XML processing`_ and the
- ElementTree_ documentation, the next place to look is the `lxml.etree
- specific API`_ documentation. It describes how lxml extends the
- ElementTree API to expose libxml2 and libxslt specific XML
- functionality, such as XPath_, `Relax NG`_, `XML Schema`_, XSLT_, and
- `c14n`_ (including `c14n 2.0`_).
- Python code can be called from XPath expressions and XSLT
- stylesheets through the use of `XPath extension functions`_. lxml
- also offers a `SAX compliant API`_, that works with the SAX support in
- the standard library.
- There is a separate module `lxml.objectify`_ that implements a data-binding
- API on top of lxml.etree. See the `objectify and etree`_ FAQ entry for a
- comparison.
- In addition to the ElementTree API, lxml also features a sophisticated
- API for `custom XML element classes`_. This is a simple way to write
- arbitrary XML driven APIs on top of lxml. lxml.etree also has a
- `C-level API`_ that can be used to efficiently extend lxml.etree in
- external C modules, including fast custom element class support.
- .. _ElementTree: http://effbot.org/zone/element-index.htm
- .. _`ElementTree API`: http://effbot.org/zone/element-index.htm#documentation
- .. _cElementTree: http://effbot.org/zone/celementtree.htm
- .. _`tutorial for ElementTree`: http://effbot.org/zone/element.htm
- .. _`lxml.etree tutorial for XML processing`: tutorial.html
- .. _`Python XML processing with lxml`: http://www.nmt.edu/tcc/help/pubs/pylxml/
- .. _`generated API documentation`: api/index.html
- .. _`ElementTree performance`: performance.html
- .. _`compatibility`: compatibility.html
- .. _`lxml.etree specific API`: api.html
- .. _`parsing`: parsing.html
- .. _`validating`: validation.html
- .. _`XPath and XSLT`: xpathxslt.html
- .. _`XPath extension functions`: extensions.html
- .. _`custom XML element classes`: element_classes.html
- .. _`SAX compliant API`: sax.html
- .. _`C-level API`: capi.html
- .. _`lxml.objectify`: objectify.html
- .. _`objectify and etree`: FAQ.html#what-is-the-difference-between-lxml-etree-and-lxml-objectify
- .. _`EuroPython 2008 talk`: s5/lxml-ep2008.html
- .. _XPath: https://www.w3.org/TR/xpath/
- .. _`Relax NG`: https://relaxng.org/
- .. _`XML Schema`: https://www.w3.org/XML/Schema
- .. _`XSLT`: https://www.w3.org/TR/xslt
- .. _`c14n`: https://www.w3.org/TR/xml-c14n
- .. _`c14n 2.0`: https://www.w3.org/TR/xml-c14n2
- Download
- --------
- The best way to download lxml is to visit `lxml at the Python Package
- Index <http://pypi.python.org/pypi/lxml/>`_ (PyPI). It has the source
- that compiles on various platforms. The source distribution is signed
- with `this key <pubkey.asc>`_.
- The latest version is `lxml 4.9.1`_, released 2022-07-01
- (`changes for 4.9.1`_). `Older versions <#old-versions>`_
- are listed below.
- Please take a look at the
- `installation instructions <installation.html>`_ !
- This complete website (including the generated API documentation) is
- part of the source distribution, so if you want to download the
- documentation for offline use, take the source archive and copy the
- ``doc/html`` directory out of the source tree.
- .. , or use the `PDF documentation`_.
- The latest `installable developer sources <https://github.com/lxml/lxml/archive/master.zip>`_
- are available from Github. It's also possible to check out
- the latest development version of lxml from Github directly, using a command
- like this::
- git clone https://github.com/lxml/lxml.git lxml
- You can browse the `source repository`_ and its history through
- the web. Please read `how to build lxml from source <build.html>`_
- first. The `latest CHANGES`_ of the developer version are also
- accessible. You can check there if a bug you found has been fixed
- or a feature you want has been implemented in the latest trunk version.
- .. _`source repository`: https://github.com/lxml/lxml/
- .. _`latest CHANGES`: https://github.com/lxml/lxml/blob/master/CHANGES.txt
- Mailing list
- ------------
- Questions? Suggestions? Code to contribute? We have a `mailing list`_.
- You can also `search the archive`_ for past questions and discussions.
- .. _`search the archive`: https://mail.python.org/archives/list/lxml@python.org/
- .. _`mailing list`: https://lxml.de/mailinglist/
- Bug tracker
- -----------
- lxml uses the `launchpad bug tracker`_. If you are sure you found a
- bug in lxml, please file a bug report there. If you are not sure
- whether some unexpected behaviour of lxml is a bug or not, please
- check the documentation and ask on the `mailing list`_ first. Do not
- forget to `search the archive`_!
- .. _`launchpad bug tracker`: https://launchpad.net/lxml/
- License
- -------
- The lxml library is shipped under a `BSD license`_. libxml2 and libxslt2
- itself are shipped under the `MIT license`_. There should therefore be no
- obstacle to using lxml in your codebase.
- .. _`BSD license`: https://github.com/lxml/lxml/blob/master/doc/licenses/BSD.txt
- .. _`MIT license`: https://opensource.org/licenses/mit-license.html
- Old Versions
- ------------
- See the websites of lxml
- `4.8 <https://lxml.de/4.8/>`_,
- `4.7 <https://lxml.de/4.7/>`_,
- `4.6 <https://lxml.de/4.6/>`_,
- `4.5 <https://lxml.de/4.5/>`_,
- `4.4 <https://lxml.de/4.4/>`_,
- `4.3 <https://lxml.de/4.3/>`_,
- `4.2 <https://lxml.de/4.2/>`_,
- `4.1 <https://lxml.de/4.1/>`_,
- `4.0 <https://lxml.de/4.0/>`_,
- `3.8 <https://lxml.de/3.8/>`_,
- `3.7 <https://lxml.de/3.7/>`_,
- `3.6 <https://lxml.de/3.6/>`_,
- `3.5 <https://lxml.de/3.5/>`_,
- `3.4 <https://lxml.de/3.4/>`_,
- `3.3 <https://lxml.de/3.3/>`_,
- `3.2 <https://lxml.de/3.2/>`_,
- `3.1 <https://lxml.de/3.1/>`_,
- `3.0 <https://lxml.de/3.0/>`_,
- `2.3 <https://lxml.de/2.3/>`_,
- `2.2 <https://lxml.de/2.2/>`_,
- `2.1 <https://lxml.de/2.1/>`_,
- `2.0 <https://lxml.de/2.0/>`_,
- `1.3 <https://lxml.de/1.3/>`_
- ..
- and the `latest in-development version <https://lxml.de/dev/>`_.
- .. _`PDF documentation`: lxmldoc-4.9.1.pdf
- * `lxml 4.9.1`_, released 2022-07-01 (`changes for 4.9.1`_)
- * `lxml 4.9.0`_, released 2022-06-01 (`changes for 4.9.0`_)
- * `lxml 4.8.0`_, released 2022-02-17 (`changes for 4.8.0`_)
- * `lxml 4.7.1`_, released 2021-12-13 (`changes for 4.7.1`_)
- * `lxml 4.7.0`_, released 2021-12-13 (`changes for 4.7.0`_)
- * `lxml 4.6.5`_, released 2021-12-12 (`changes for 4.6.5`_)
- * `lxml 4.6.4`_, released 2021-11-01 (`changes for 4.6.4`_)
- * `lxml 4.6.3`_, released 2021-03-21 (`changes for 4.6.3`_)
- * `lxml 4.6.2`_, released 2020-11-26 (`changes for 4.6.2`_)
- * `lxml 4.6.1`_, released 2020-10-18 (`changes for 4.6.1`_)
- * `lxml 4.6.0`_, released 2020-10-17 (`changes for 4.6.0`_)
- * `older releases <https://lxml.de/4.6/#old-versions>`_
- .. _`lxml 4.9.1`: /files/lxml-4.9.1.tgz
- .. _`lxml 4.9.0`: /files/lxml-4.9.0.tgz
- .. _`lxml 4.8.0`: /files/lxml-4.8.0.tgz
- .. _`lxml 4.7.1`: /files/lxml-4.7.1.tgz
- .. _`lxml 4.7.0`: /files/lxml-4.7.0.tgz
- .. _`lxml 4.6.5`: /files/lxml-4.6.5.tgz
- .. _`lxml 4.6.4`: /files/lxml-4.6.4.tgz
- .. _`lxml 4.6.3`: /files/lxml-4.6.3.tgz
- .. _`lxml 4.6.2`: /files/lxml-4.6.2.tgz
- .. _`lxml 4.6.1`: /files/lxml-4.6.1.tgz
- .. _`lxml 4.6.0`: /files/lxml-4.6.0.tgz
- .. _`changes for 4.9.1`: /changes-4.9.1.html
- .. _`changes for 4.9.0`: /changes-4.9.0.html
- .. _`changes for 4.8.0`: /changes-4.8.0.html
- .. _`changes for 4.7.1`: /changes-4.7.1.html
- .. _`changes for 4.7.0`: /changes-4.7.0.html
- .. _`changes for 4.6.5`: /changes-4.6.5.html
- .. _`changes for 4.6.4`: /changes-4.6.4.html
- .. _`changes for 4.6.3`: /changes-4.6.3.html
- .. _`changes for 4.6.2`: /changes-4.6.2.html
- .. _`changes for 4.6.1`: /changes-4.6.1.html
- .. _`changes for 4.6.0`: /changes-4.6.0.html
|