On this page
astree
Prev: sametime | Up: projects | Next: parse-md
Rel: wispsy, Foundation, parse-html5, builtouts
Ref: wispsy on GitHub | astree pyproject.toml
Tags: #public #wispsy #project #foundation #tier/core
Role
Shared structural traversal (walk, ancestors, descendants, transform) with specialized HTML (html.parser), JSON, Markdown, Python, and optional JavaScript (tree-sitter) syntax-tree adapters, plus CSS selectors and declarative Field extraction.
Install
pip install astree
# Optional JavaScript adapter (tree-sitter):
pip install "astree[javascript]"
Quickstart
from astree import Document, Field, extract_all
doc = Document.from_html('<article class="card" data-id="42"><h2>Headline</h2></article>')
records = extract_all(doc, "article.card", {
"id": Field(attribute="data-id", convert=int),
"headline": Field("h2"),
})
assert records == [{"id": 42, "headline": "Headline"}]
When to Reach for It
- Querying or extracting structured records from HTML, JSON, Markdown, or Python trees using a unified traversal API.
- Reach for parse-html5 when you specifically need bounded HTML5 parsing and safe typed HTML rendering.
Gotchas & Pitfalls
- Optional JavaScript extra: Core HTML, JSON, Markdown, and Python adapters have zero third-party deps, while JavaScript traversal requires the optional
tree-sitterextra. - HTML parsing vs. HTML5 rendering:
astreewraps stdlibhtml.parserfor querying andFieldextraction; reach for parse-html5 if you need bounded HTML5 source spans or safe escaped rendering. - Python 3.14+ floor: Targets Python
>=3.14and immutable structural traversal—transformreturns a new tree rather than mutating nodes in place.
Pairs With
- requ — Fetches bounded HTTP(S) pages before
astreeextracts structured nodes. - escape-colors — Uses
astreefor optional syntax and terminal Markdown rendering.
Metadata
type: project-card
slug: astree
org: wispsy
repo: wispsy/astree
package: astree
version: 0.1.1
requires_python: ">=3.14"
layer: foundation
topic: wispsy-foundation
status: active
language: python
source_docs: README.md, docs/
Linked from
Related notes
- wiki/projects/builtouts Linked here; links to this page; shared tags: #foundation, #project, #tier, #wispsy
- wiki/projects/escape-colors Linked here; links to this page; shared tags: #foundation, #project, #tier, #wispsy
- wiki/projects/parse-html5 Linked here; links to this page; shared tags: #foundation, #project, #tier, #wispsy
- wiki/projects/parse-md Linked here; links to this page; shared tags: #foundation, #project, #tier, #wispsy
- wiki/projects/requ Linked here; links to this page; shared tags: #foundation, #project, #tier, #wispsy
- wiki/projects/sametime Linked here; links to this page; shared tags: #foundation, #project, #tier, #wispsy
- wiki/stack/foundation Linked here; links to this page; shared tags: #foundation, #tier, #wispsy
- wiki/projects Linked here; links to this page; shared tags: #wispsy
- wiki/projects/parse-xml1 links to this page; shared tags: #foundation, #project, #tier, #wispsy
- wiki/choosing links to this page; shared tags: #tier, #wispsy