selectolax
A fast HTML5 parser with CSS selectors, written in Cython, using Modest and Lexbor engines.
What it is and what it does
selectolax wraps the Lexbor and Modest C HTML5 parsing engines in Cython to provide a fast, Python-friendly interface for parsing and querying HTML. It supports standard CSS selectors and some extended pseudo-classes (like `:lexbor-contains` for text matching), and exposes parsed nodes with methods to extract text, attributes, and HTML fragments. The package is designed for web scraping and data extraction tasks where parsing speed matters.
The library has no runtime dependencies and comes as pre-compiled wheels for modern Python versions (3.9–3.14) on major platforms. Installation is straightforward on supported configurations; older or edge-case Python versions may require building from source. The Lexbor backend is now preferred over Modest, which is maintained for backward compatibility only.
Use it for:
- Extract structured data from web pages during web scraping by querying elements with CSS selectors and reading text or attributes.
- Parse and filter large HTML documents quickly when performance is critical, such as processing thousands of pages in batch jobs.
- Find elements matching complex CSS selectors including pseudo-classes like `:nth-child` and `:not`, or text-based matching with `:lexbor-contains`.
- Build DOM navigation tools that need to traverse parent and sibling nodes after selecting an element.
- Replace slower pure-Python HTML parsers in existing projects when parsing becomes a bottleneck.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
selectolax is a fast HTML5 parser with CSS selector support, written in Cython and backed by either the Modest or Lexbor C parsing engines.
Yes. selectolax is actively maintained, has no security vulnerabilities, uses a permissive MIT license, and offers a significant speed advantage over pure-Python HTML parsers for typical web-scraping tasks. Install friction is medium but manageable thanks to pre-built wheels. Choose it if parsing performance matters or if you need CSS selector support; it's a solid, production-ready choice for HTML extraction work.
Install
selectolax on PyPI
pip
pip install selectolaxuv
uv add selectolaxpoetry
poetry add selectolaxInstalling selectolax
Before you install
Medium install friction due to compiled Cython components; pre-built wheels are available for Python 3.9–3.14 on macOS, Linux, Windows, and ARM architectures. Installation typically succeeds without intervention, though older versions on newer Python releases may require Cython to be installed separately.
License in practice
MIT license (permissive). The underlying Modest engine uses LGPL2.1 and Lexbor uses Apache-2.0, but selectolax itself is MIT, allowing use in proprietary and commercial projects without copyleft obligations.
Quickstart
from selectolax.lexbor import LexborHTMLParser
html = '<h1 id="title">Hi there</h1><p class="post">Lorem ipsum</p>'
tree = LexborHTMLParser(html)
print(tree.css_first('h1#title').text())
print([node.text() for node in tree.css('.post')])
Requires Python 3.9 or later; compiled wheels are provided for most platforms but compilation from source requires a C compiler and Cython.
Verify before relying
- Whether the Lexbor backend is materially faster than Modest in typical web-scraping workloads beyond the benchmark shown.
- Performance characteristics when parsing very large HTML documents or handling malformed HTML.
- Whether the `lexbor-contains` pseudo-class and advanced CSS selectors cover all real-world scraping patterns.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<3.15,>=3.9) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 30 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,064,384/month — #1,976 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: selectolax-0.4.11-cp310-cp310-macosx_10_9_x86_64.whl; selectolax-0.4.11-cp310-cp310-macosx_11_0_arm64.whl; selectolax-0.4.11-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; selectolax-0.4.11-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; selectolax-0.4.11-cp310-cp310-musllinux_1_2_aarch64.whl; selectolax-0.4.11-cp310-cp310-musllinux_1_2_x86_64.whl; selectolax-0.4.11-cp310-cp310-win32.whl; selectolax-0.4.11-cp310-cp310-win_amd64.whl; selectolax-0.4.11-cp310-cp310-win_arm64.whl; selectolax-0.4.11-cp311-cp311-macosx_10_9_x86_64.whl; selectolax-0.4.11-cp311-cp311-macosx_11_0_arm64.whl; selectolax-0.4.11-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; selectolax-0.4.11-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; selectolax-0.4.11-cp311-cp311-musllinux_1_2_aarch64.whl; selectolax-0.4.11-cp311-cp311-musllinux_1_2_x86_64.whl; selectolax-0.4.11-cp311-cp311-win32.whl; selectolax-0.4.11-cp311-cp311-win_amd64.whl; selectolax-0.4.11-cp311-cp311-win_arm64.whl; selectolax-0.4.11-cp312-cp312-macosx_10_13_x86_64.whl; selectolax-0.4.11-cp312-cp312-macosx_11_0_arm64.whl
Keywords: selectolax, html, parser, css, fast, lexbor, modest
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
cssselectcssselect parses CSS3 selectors and translates…
permissive · top 1,000 on PyPI
soupsieveSoupsieve is a CSS selector library designed to…
permissive · top 100 on PyPI
parselParsel extracts data from HTML, JSON, and XML…
permissive · top 5,000 on PyPI
cssselect2cssselect2 parses and matches CSS4 selectors…
permissive · top 1,000 on PyPI
turbohtmlParse, query, edit, and serialize HTML and XML…
permissive · top 15,000 on PyPI
itemloadersItemloaders extracts and standardizes…
permissive · top 5,000 on PyPI
selectors2Provides a backported, cross-platform…
permissive · top 15,000 on PyPI
BeautifulSoupBeautiful Soup parses HTML and XML documents…
permissive · top 15,000 on PyPI
requests-htmlParses and scrapes HTML from web pages using a…
permissive · top 15,000 on PyPI
Selenium-ScreenshotCaptures full-page or element-level screenshots…
permissive · top 15,000 on PyPI