Skip to main content

astree

Dependency-free HTML tree parsing, CSS selector querying, and structured record extraction powered by Python's html.parser.

Requires Python 3.14+.

Highlights

  • Dependency-Free: Built strictly on Python standard library primitives.
  • Full DOM Navigation: Navigable Document and Node tree with parent/child links and attributes.
  • CSS Selectors: Fast CSS selector queries (select, select_one).
  • Streaming Collectors: Single-pass LinkCollector and TextCollector with bounds protection.
  • Declarative Schema Extraction: extract and extract_all using Field definitions with type converters and cardinality validation.
  • Configurable Limits: Protect against deeply nested tags or resource exhaustion (max_depth, max_nodes, max_chars).

Installation

pip install astree

For development:

git clone https://github.com/wispsy/astree.git
cd astree
uv sync

Quick Start

Basic Parsing & Queries

from astree import Document

doc = Document.from_html('''
<!doctype html>
<html>
  <head><title>My Article</title></head>
  <body>
    <article class="card" data-id="42">
      <h2>Headline</h2>
      <a href="/post/42">Read story</a>
    </article>
  </body>
</html>
''')

assert doc.title == 'My Article'
card = doc.select_one('article.card')
assert card is not None
assert card.attrs['data-id'] == '42'

link = card.find('a', href=True)
assert link is not None
assert link.attrs['href'] == '/post/42'
assert card.get_text(' ', strip=True) == 'Headline Read story'

Structured Record Extraction

from astree import Document, Field, extract_all

records = extract_all(doc, 'article.card', {
    'id': Field(attribute='data-id', convert=int),
    'headline': Field('h2'),
    'url': Field('a', attribute='href'),
})

# [{'id': 42, 'headline': 'Headline', 'url': '/post/42'}]

Documentation

See docs/api.md for full API details, selector capabilities, collectors, and structured extraction specifications.

Running Tests

python -m unittest discover -s tests -v

License

MIT

Metadata

Release files for astree 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for astree 0.1.0
File Size Uploaded Provenance Actions
astree-0.1.0.tar.gz 19.2 kB With provenance Details for astree-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for astree 0.1.0
File Interpreter ABI Platform Actions
astree-0.1.0-py3-none-any.whl Python 3 none any Details for astree-0.1.0-py3-none-any.whl

Total release size: 32.0 kB

Release files / astree-0.1.0.tar.gz

Download URL astree-0.1.0.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c4da48e551b46d2241e3d92f384c87ad04b0de0f7f2467f6586a91b419116cc4
BLAKE2b-256 checksum
How to use checksums
de78028d0248e31236a3e0f49251652e5d2d7427f93e7feb4263115bf4a43d71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Release files / astree-0.1.0-py3-none-any.whl

Download URL astree-0.1.0-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b6cc157d6407945a99f89cf761915b09d91e073126b97b4e300ddf4815fada2
BLAKE2b-256 checksum
How to use checksums
e303237d6981288c60dbbac2e699c97f44bf118ad8fa021baee85cf07f2827ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Security for astree 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for astree-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page