--- id: selectolax version: "0.4.11" license: MIT license_treatment: permissive maintenance: active --- # selectolax — A fast HTML5 parser with CSS selectors, written in Cython, using Modest and Lexbor engines. License: permissive · Maintenance: active · Downloads: 6.1M/mo ## 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 above — 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 pip install selectolax uv add selectolax 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 = '
Lorem ipsum
' 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_current - Install friction: medium - Maintenance: active - Downloads: 6.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags fast html parser python, css selectors html parsing, html5 parser cython, web scraping parser, lexbor html parser, html parsing performance, dom selector extraction, web-scraping, html-parsing, performance-critical [View on SkillFed](https://skillfed.io/packages/selectolax) · [View on PyPI](https://pypi.org/project/selectolax/)