Repository navigation
feat(python): selectolax users had no way to try Parsec from Python - #80
Merged
Merged
Conversation
bindings/python is the parsec-html package, built with maturin and PyO3, and imported as parsec_html (a `parsec` already exists on PyPI). Its API is selectolax's: HTMLParser(html) with css, css_first, root, head, body, text, and nodes with tag, attributes, attrs, html, inner_html, navigation, iter, traverse, decompose, unwrap, replace_with, insert_before/after/child and merge_text_nodes. Type stubs ship in the wheel. A parser keeps its document behind a RwLock, so one page can be read from many threads and edited from any of them. The module declares that it doesn't need the GIL, and parsing and css() let go of it while they work. Nothing waits for the lock while attached to the interpreter, and nothing makes a Python object while holding it, so a stop-the-world pause or a finalizer can't deadlock it. The release builds a wheel per CPython from 3.9 to 3.15 and for 3.13t, 3.14t and 3.15t, plus an abi3t wheel for later versions: the stable ABI made creating 400,000 nodes take 31 ms against 22. Publishing uses PyPI trusted publishing and only runs once PYPI_PUBLISH is set.
PyO3 0.30 refuses free-threaded 3.13, so it's out of the test matrix and the release, and the manylinux builds name their interpreters rather than finding them, since those images carry a 3.13t. ubuntu-latest is now 26.04, which has no CPython 3.9 to install, so 3.9 tests on 24.04.
Two runs of bindings/python/bench.py at a load of 3: parsing the 13 pages takes 66 ms to selectolax's 106, and the 32 selectors 283 ms to its 781.
jamesconwaydev
enabled auto-merge (squash)
November 18, 2026 23:55
This was referenced Nov 19, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Most Python users meet Lexbor through selectolax, and there was no way to try Parsec from Python at all (#23).
Change
bindings/python: theparsec-htmlpackage, built with maturin and PyO3 0.30, imported asparsec_html. I didn't useparsecas the import name because PyPI already has aparsec(parser combinators), and two packages that install the same module overwrite each other.HTMLParser(html, is_fragment, fragment_tag, fragment_namespace, scripting)withroot,head,body,html,text(deep, separator, strip, skip_empty),css,css_first(default, strict),css_matches,any_css_matches,tags,create_node,merge_text_nodes,strip_tags,unwrap_tags. Nodes havetag,id,attributes,attrs(a live mapping),html,inner_html(settable),text_content,comment_content,parent/next/prev/first_child/last_child,iter,traverse,decompose/remove,unwrap,replace_with,insert_before/insert_after/insert_child(withmove=),merge_text_nodesand theis_*_nodechecks. Type stubs andpy.typedship in the wheel. The README and the wiki's Python page list each difference.RwLock, so a page can be read from many threads and edited from any of them. The module is declaredgil_used = false, and parsing andcss()let go of the GIL while they run. Nothing waits on the lock while attached to the interpreter, and nothing creates a Python object while holding it, so neither a stop-the-world pause nor a finalizer can deadlock it.budget=,max_depth=andurl=(which makes:targetand:local-linkmatch). Selectors like:lang(),:dir(),:validand:scopework; selectolax 1.0.2 rejects them as unparseable..github/workflows/python.ymllints the crate, runscargo deny, and builds and pytest-tests the wheel on Linux, macOS and Windows with 3.9, 3.14 and 3.14t, plus Linux with 3.15 and the abi3t wheel on 3.15 and 3.15t. 3.9 runs on Ubuntu 24.04, since 26.04 has none. PyO3 0.30 doesn't support free-threaded 3.13, so 3.13t isn't built. Pip installs use hashedci-requirements.txt..github/workflows/release-python.ymlruns onv*tags. It builds wheels per CPython version (3.9 to 3.15, plus 3.14t and 3.15t) on manylinux and musllinux (x86-64 and ARM), macOS (Intel and ARM) and Windows (x64 and ARM). It also builds one abi3t wheel for later versions, plus an sdist. Publishing is PyPI trusted publishing, and it's off until thePYPI_PUBLISHrepository variable istrueand thereleaseenvironment and the PyPI trusted publisher are set up. A manual run builds everything and publishes nothing. It's a separate file from ci: a release was neither signed nor reproducible #76'srelease.yml.css("*")on the WHATWG spec (400,000 nodes) took 31 ms, against 22 ms built for the version. So abi3t is only the fallback.Not here yet: source positions (the core has none until #8), XPath (#31), and
clone()(the core'sDocumentisn'tClone). This is part of #23, not all of it.Tests
pytest bindings/python/tests: 15 tests, all passing on CPython 3.9, 3.14, 3.14t (GIL off, checked) and 3.15 (abi3t wheel). They cover parsing, text options, selectors, attributes, navigation, every edit including copies between documents, templates, fragments, limits, and 8 reader threads plus a writer sharing one document.cargo fmt --check,cargo clippy -- -D warnings(with and withoutabi3t) andcargo deny checkon the new crate. The root workspace checks are unchanged and pass.bindings/python/bench.pyagainst selectolax 1.0.2 on bench's 13 pages; numbers in the README.Part of #23.