skillfed

selectolax

A fast HTML5 parser with CSS selectors, written in Cython, using Modest and Lexbor engines.

selectolax v0.4.11 6.1M downloads/30d#1,976 on PyPI1,663
Permissive license MIT Active released

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 selectolax

uv

uv add selectolax

poetry

poetry add selectolax

Installing 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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentIntended Audience :: DevelopersNatural Language :: EnglishOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: OS IndependentOperating System :: UnixProgramming Language :: CythonProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonTopic :: InternetTopic :: Internet :: WWW/HTTPTopic :: Software DevelopmentTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: Text ProcessingTopic :: Text Processing :: MarkupTopic :: Text Processing :: Markup :: HTMLTyping :: Typed

Tags

fast html parser pythoncss selectors html parsinghtml5 parser cythonweb scraping parserlexbor html parserhtml parsing performancedom selector extraction
web-scrapinghtml-parsingperformance-critical

More Software Development packages