main.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. lxml
  2. ====
  3. .. meta::
  4. :description: lxml - the most feature-rich and easy-to-use library for processing XML and HTML in the Python language
  5. :keywords: Python XML, XML processing, HTML, lxml, simple XML, ElementTree, etree, lxml.etree, objectify, XML parsing, XML validation, XPath, XSLT
  6. .. class:: pagequote
  7. | `» lxml takes all the pain out of XML. « <http://thread.gmane.org/gmane.comp.python.lxml.devel/3252/focus=3258>`_
  8. | Stephan Richter
  9. .. class:: eyecatcher
  10. lxml is the most feature-rich
  11. and easy-to-use library
  12. for processing XML and HTML
  13. in the Python language.
  14. ..
  15. 1 Introduction
  16. 2 Documentation
  17. 3 Download
  18. 4 Mailing list
  19. 5 Bug tracker
  20. 6 License
  21. 7 Old Versions
  22. Introduction
  23. ------------
  24. The lxml XML toolkit is a Pythonic binding for the C libraries
  25. libxml2_ and libxslt_. It is unique in that it combines the speed and
  26. XML feature completeness of these libraries with the simplicity of a
  27. native Python API, mostly compatible but superior to the well-known
  28. ElementTree_ API. The latest release works with all CPython versions
  29. from 2.4 to 3.4. See the introduction_ for more information about
  30. background and goals of the lxml project. Some common questions are
  31. answered in the FAQ_.
  32. .. _libxml2: http://xmlsoft.org/
  33. .. _libxslt: http://xmlsoft.org/XSLT/
  34. .. _introduction: intro.html
  35. .. _FAQ: FAQ.html
  36. Documentation
  37. -------------
  38. The complete lxml documentation is available for download as `PDF
  39. documentation`_. The HTML documentation from this web site is part of
  40. the normal `source download <#download>`_.
  41. * Tutorials:
  42. * the `lxml.etree tutorial for XML processing`_
  43. * John Shipman's tutorial on `Python XML processing with lxml`_
  44. * Fredrik Lundh's `tutorial for ElementTree`_
  45. * ElementTree:
  46. * `ElementTree API`_
  47. * compatibility_ and differences of lxml.etree
  48. * `ElementTree performance`_ characteristics and comparison
  49. * lxml.etree:
  50. * `lxml.etree specific API`_ documentation
  51. * the `generated API documentation`_ as a reference
  52. * parsing_ and validating_ XML
  53. * `XPath and XSLT`_ support
  54. * Python `XPath extension functions`_ for XPath and XSLT
  55. * `custom XML element classes`_ for custom XML APIs (see `EuroPython 2008 talk`_)
  56. * a `SAX compliant API`_ for interfacing with other XML tools
  57. * a `C-level API`_ for interfacing with external C/Cython modules
  58. * lxml.objectify:
  59. * `lxml.objectify`_ API documentation
  60. * a brief comparison of `objectify and etree`_
  61. lxml.etree follows the ElementTree_ API as much as possible, building
  62. it on top of the native libxml2 tree. If you are new to ElementTree,
  63. start with the `lxml.etree tutorial for XML processing`_. See also the
  64. ElementTree compatibility_ overview and the `ElementTree performance`_
  65. page comparing lxml to the original ElementTree_ and cElementTree_
  66. implementations.
  67. Right after the `lxml.etree tutorial for XML processing`_ and the
  68. ElementTree_ documentation, the next place to look is the `lxml.etree
  69. specific API`_ documentation. It describes how lxml extends the
  70. ElementTree API to expose libxml2 and libxslt specific XML
  71. functionality, such as XPath_, `Relax NG`_, `XML Schema`_, XSLT_, and
  72. `c14n`_. Python code can be called from XPath expressions and XSLT
  73. stylesheets through the use of `XPath extension functions`_. lxml
  74. also offers a `SAX compliant API`_, that works with the SAX support in
  75. the standard library.
  76. There is a separate module `lxml.objectify`_ that implements a data-binding
  77. API on top of lxml.etree. See the `objectify and etree`_ FAQ entry for a
  78. comparison.
  79. In addition to the ElementTree API, lxml also features a sophisticated
  80. API for `custom XML element classes`_. This is a simple way to write
  81. arbitrary XML driven APIs on top of lxml. lxml.etree also has a
  82. `C-level API`_ that can be used to efficiently extend lxml.etree in
  83. external C modules, including fast custom element class support.
  84. .. _ElementTree: http://effbot.org/zone/element-index.htm
  85. .. _`ElementTree API`: http://effbot.org/zone/element-index.htm#documentation
  86. .. _cElementTree: http://effbot.org/zone/celementtree.htm
  87. .. _`tutorial for ElementTree`: http://effbot.org/zone/element.htm
  88. .. _`lxml.etree tutorial for XML processing`: tutorial.html
  89. .. _`Python XML processing with lxml`: http://www.nmt.edu/tcc/help/pubs/pylxml/
  90. .. _`generated API documentation`: api/index.html
  91. .. _`ElementTree performance`: performance.html
  92. .. _`compatibility`: compatibility.html
  93. .. _`lxml.etree specific API`: api.html
  94. .. _`parsing`: parsing.html
  95. .. _`validating`: validation.html
  96. .. _`XPath and XSLT`: xpathxslt.html
  97. .. _`XPath extension functions`: extensions.html
  98. .. _`custom XML element classes`: element_classes.html
  99. .. _`SAX compliant API`: sax.html
  100. .. _`C-level API`: capi.html
  101. .. _`lxml.objectify`: objectify.html
  102. .. _`objectify and etree`: FAQ.html#what-is-the-difference-between-lxml-etree-and-lxml-objectify
  103. .. _`EuroPython 2008 talk`: s5/lxml-ep2008.html
  104. .. _XPath: http://www.w3.org/TR/xpath/
  105. .. _`Relax NG`: http://www.relaxng.org/
  106. .. _`XML Schema`: http://www.w3.org/XML/Schema
  107. .. _`XSLT`: http://www.w3.org/TR/xslt
  108. .. _`c14n`: http://www.w3.org/TR/xml-c14n
  109. Download
  110. --------
  111. The best way to download lxml is to visit `lxml at the Python Package
  112. Index <http://pypi.python.org/pypi/lxml/>`_ (PyPI). It has the source
  113. that compiles on various platforms. The source distribution is signed
  114. with `this key <pubkey.asc>`_.
  115. The latest version is `lxml 3.3.6`_, released 2014-08-28
  116. (`changes for 3.3.6`_). `Older versions <#old-versions>`_
  117. are listed below.
  118. Please take a look at the
  119. `installation instructions <installation.html>`_ !
  120. This complete web site (including the generated API documentation) is
  121. part of the source distribution, so if you want to download the
  122. documentation for offline use, take the source archive and copy the
  123. ``doc/html`` directory out of the source tree, or use the
  124. `PDF documentation`_.
  125. The latest installable developer sources should usually be available from the
  126. `build server <http://lxml.de/build/>`_. It's also possible to check out
  127. the latest development version of lxml from github directly, using a command
  128. like this (assuming you use hg and have hg-git installed)::
  129. hg clone git://github.com/lxml/lxml.git lxml
  130. Alternatively, if you use git, this should work as well::
  131. git clone git://github.com/lxml/lxml.git lxml
  132. You can browse the `source repository`_ and its history through
  133. the web. Please read `how to build lxml from source <build.html>`_
  134. first. The `latest CHANGES`_ of the developer version are also
  135. accessible. You can check there if a bug you found has been fixed
  136. or a feature you want has been implemented in the latest trunk version.
  137. .. _`source repository`: https://github.com/lxml/lxml/
  138. .. _`latest CHANGES`: https://github.com/lxml/lxml/blob/master/CHANGES.txt
  139. Mailing list
  140. ------------
  141. Questions? Suggestions? Code to contribute? We have a `mailing list`_.
  142. You can search the archive with Gmane_ or Google_.
  143. .. _`mailing list`: http://lxml.de/mailinglist/
  144. .. _Gmane: http://blog.gmane.org/gmane.comp.python.lxml.devel
  145. .. _Google: http://www.google.com/webhp?q=site:comments.gmane.org%2Fgmane.comp.python.lxml.devel+
  146. Bug tracker
  147. -----------
  148. lxml uses the `launchpad bug tracker`_. If you are sure you found a
  149. bug in lxml, please file a bug report there. If you are not sure
  150. whether some unexpected behaviour of lxml is a bug or not, please
  151. check the documentation and ask on the `mailing list`_ first. Do not
  152. forget to search the archive (e.g. with Gmane_)!
  153. .. _`launchpad bug tracker`: https://launchpad.net/lxml/
  154. License
  155. -------
  156. The lxml library is shipped under a `BSD license`_. libxml2 and libxslt2
  157. itself are shipped under the `MIT license`_. There should therefore be no
  158. obstacle to using lxml in your codebase.
  159. .. _`BSD license`: https://github.com/lxml/lxml/blob/master/doc/licenses/BSD.txt
  160. .. _`MIT license`: http://www.opensource.org/licenses/mit-license.html
  161. Old Versions
  162. ------------
  163. See the web sites of lxml
  164. `1.3 <http://lxml.de/1.3/>`_,
  165. `2.0 <http://lxml.de/2.0/>`_,
  166. `2.1 <http://lxml.de/2.1/>`_,
  167. `2.2 <http://lxml.de/2.2/>`_
  168. `2.3 <http://lxml.de/2.3/>`_
  169. `3.0 <http://lxml.de/3.0/>`_
  170. `3.1 <http://lxml.de/3.1/>`_
  171. `3.2 <http://lxml.de/3.2/>`_
  172. and the `latest in-development version <http://lxml.de/dev/>`_.
  173. .. _`PDF documentation`: lxmldoc-3.3.6.pdf
  174. * `lxml 3.3.6`_, released 2014-08-28 (`changes for 3.3.6`_)
  175. * `lxml 3.3.5`_, released 2014-04-18 (`changes for 3.3.5`_)
  176. * `lxml 3.3.4`_, released 2014-04-03 (`changes for 3.3.4`_)
  177. * `lxml 3.3.3`_, released 2014-03-04 (`changes for 3.3.3`_)
  178. * `lxml 3.3.2`_, released 2014-02-26 (`changes for 3.3.2`_)
  179. * `lxml 3.3.1`_, released 2014-02-12 (`changes for 3.3.1`_)
  180. * `lxml 3.3.0`_, released 2014-01-26 (`changes for 3.3.0`_)
  181. * `lxml 3.3.0beta5`_, released 2014-01-18 (`changes for 3.3.0beta5`_)
  182. * `lxml 3.3.0beta4`_, released 2014-01-12 (`changes for 3.3.0beta4`_)
  183. * `lxml 3.3.0beta3`_, released 2014-01-02 (`changes for 3.3.0beta3`_)
  184. * `lxml 3.3.0beta2`_, released 2013-12-20 (`changes for 3.3.0beta2`_)
  185. * `lxml 3.3.0beta1`_, released 2013-12-12 (`changes for 3.3.0beta1`_)
  186. * `lxml 3.2.4`_, released 2013-11-07 (`changes for 3.2.4`_)
  187. * `lxml 3.2.3`_, released 2013-07-28 (`changes for 3.2.3`_)
  188. * `lxml 3.2.2`_, released 2013-07-28 (`changes for 3.2.2`_)
  189. * `lxml 3.2.1`_, released 2013-05-11 (`changes for 3.2.1`_)
  190. * `lxml 3.2.0`_, released 2013-04-28 (`changes for 3.2.0`_)
  191. * `lxml 3.1.2`_, released 2013-04-12 (`changes for 3.1.2`_)
  192. * `lxml 3.1.1`_, released 2013-03-29 (`changes for 3.1.1`_)
  193. * `lxml 3.1.0`_, released 2013-02-10 (`changes for 3.1.0`_)
  194. * `lxml 3.1beta1`_, released 2012-12-21 (`changes for 3.1beta1`_)
  195. * `lxml 3.0.2`_, released 2012-12-14 (`changes for 3.0.2`_)
  196. * `lxml 3.0.1`_, released 2012-10-14 (`changes for 3.0.1`_)
  197. * `lxml 3.0`_, released 2012-10-08 (`changes for 3.0`_)
  198. * `older releases <http://lxml.de/3.0/#old-versions>`_
  199. .. _`lxml 3.3.6`: /files/lxml-3.3.6.tgz
  200. .. _`lxml 3.3.5`: /files/lxml-3.3.5.tgz
  201. .. _`lxml 3.3.4`: /files/lxml-3.3.4.tgz
  202. .. _`lxml 3.3.3`: /files/lxml-3.3.3.tgz
  203. .. _`lxml 3.3.2`: /files/lxml-3.3.2.tgz
  204. .. _`lxml 3.3.1`: /files/lxml-3.3.1.tgz
  205. .. _`lxml 3.3.0`: /files/lxml-3.3.0.tgz
  206. .. _`lxml 3.3.0beta5`: /files/lxml-3.3.0beta5.tgz
  207. .. _`lxml 3.3.0beta4`: /files/lxml-3.3.0beta4.tgz
  208. .. _`lxml 3.3.0beta3`: /files/lxml-3.3.0beta3.tgz
  209. .. _`lxml 3.3.0beta2`: /files/lxml-3.3.0beta2.tgz
  210. .. _`lxml 3.3.0beta1`: /files/lxml-3.3.0beta1.tgz
  211. .. _`lxml 3.2.4`: /files/lxml-3.2.4.tgz
  212. .. _`lxml 3.2.3`: /files/lxml-3.2.3.tgz
  213. .. _`lxml 3.2.2`: /files/lxml-3.2.2.tgz
  214. .. _`lxml 3.2.1`: /files/lxml-3.2.1.tgz
  215. .. _`lxml 3.2.0`: /files/lxml-3.2.0.tgz
  216. .. _`lxml 3.1.2`: /files/lxml-3.1.2.tgz
  217. .. _`lxml 3.1.1`: /files/lxml-3.1.1.tgz
  218. .. _`lxml 3.1.0`: /files/lxml-3.1.0.tgz
  219. .. _`lxml 3.1beta1`: /files/lxml-3.1beta1.tgz
  220. .. _`lxml 3.0.2`: /files/lxml-3.0.2.tgz
  221. .. _`lxml 3.0.1`: /files/lxml-3.0.1.tgz
  222. .. _`lxml 3.0`: /files/lxml-3.0.tgz
  223. .. _`changes for 3.3.6`: /changes-3.3.6.html
  224. .. _`changes for 3.3.5`: /changes-3.3.5.html
  225. .. _`changes for 3.3.4`: /changes-3.3.4.html
  226. .. _`changes for 3.3.3`: /changes-3.3.3.html
  227. .. _`changes for 3.3.2`: /changes-3.3.2.html
  228. .. _`changes for 3.3.1`: /changes-3.3.1.html
  229. .. _`changes for 3.3.0`: /changes-3.3.0.html
  230. .. _`changes for 3.3.0beta5`: /changes-3.3.0beta5.html
  231. .. _`changes for 3.3.0beta4`: /changes-3.3.0beta4.html
  232. .. _`changes for 3.3.0beta3`: /changes-3.3.0beta3.html
  233. .. _`changes for 3.3.0beta2`: /changes-3.3.0beta2.html
  234. .. _`changes for 3.3.0beta1`: /changes-3.3.0beta1.html
  235. .. _`changes for 3.2.4`: /changes-3.2.4.html
  236. .. _`changes for 3.2.3`: /changes-3.2.3.html
  237. .. _`changes for 3.2.2`: /changes-3.2.2.html
  238. .. _`changes for 3.2.1`: /changes-3.2.1.html
  239. .. _`changes for 3.2.0`: /changes-3.2.0.html
  240. .. _`changes for 3.1.2`: /changes-3.1.2.html
  241. .. _`changes for 3.1.1`: /changes-3.1.1.html
  242. .. _`changes for 3.1.0`: /changes-3.1.0.html
  243. .. _`changes for 3.1beta1`: /changes-3.1beta1.html
  244. .. _`changes for 3.0.2`: /changes-3.0.2.html
  245. .. _`changes for 3.0.1`: /changes-3.0.1.html
  246. .. _`changes for 3.0`: /changes-3.0.html