Skip to main content

Quick start

import confext

html = '''
<!DOCTYPE html>
<html><body>
  <div id="main" class="wrap card">
    <p class="lead">Hello <b>world</b></p>
    <ul><li>1</li><li>2</li></ul>
  </div>
</body></html>
'''

doc = confext.parse(html)              # -> parse html
doc.doctype                            # '<!DOCTYPE html>'
doc.stats()                            # {'elements': 7, 'comments': 0, 'max_depth': 4}
doc.to_html()                          # serialized markup
doc.root.iter_elements()               # walk every element node

API

Functions

Function Description
parse(html) Parse str or bytes into a ParsedDocument using the default engine.

That is the whole module-level API, confext is a parser, nothing else.

ParsedDocument

Member Description
to_html() Re-serialize the tree.
stats() {'elements', 'comments', 'max_depth'}.
to_dict() {'doctype', 'stats', 'html', 'errors'}.
doctype, root, comments, errors Raw parse artifacts.

Node

tag, attrs, parent, children (mix of Nodes and text strs), plus: get_attr, has_class, append_child, remove, text_content, iter_elements, to_html, to_dict.

Engine

For isolated runs with a custom config and no global state:

from confext import Engine, ConfextError

engine = Engine({'strict_mode': True})
doc = engine.parse('<div><p>ok</p></div>')
engine.parse('<div><p>oops</div>')   # raises ConfextError in strict mode

Also accepts use_cache=False to disable document memoization (cache_size is clamped to a minimum of 1).

Configuration

DEFAULT_CONFIG is a plain dict; Engine(config) merges over it. Settings can also be persisted to and loaded from a default.config file:

from confext import Config, load_config, save_config

cfg = load_config()                    # finds the caller's default.config
cfg.get('max_depth')                   # user setting layered over defaults
save_config(cfg, 'default.config', compression='xz')

The binary layout is [8-byte sha256][4-byte size][payload], where the payload is a raw, lzma (xz), or zlib compressed payload of a plain-data dict. Size and checksum are verified before decompression and unpickling; both checks run before any decompression is attempted. Failures raise ConfigLoadError, ConfigChecksumError, or ConfigDecompressError.

Key Default Used by
encoding 'utf-8' Fallback when bytes input has no BOM / <meta charset>.
max_depth 100 Element nesting cap (deeper nodes are dropped).
max_file_size_mb 10 Input size cap; parse raises ConfextError beyond it.
cache_size 50 LRU capacity for parsed documents.
strict_mode False If true, malformed HTML (unclosed/stray tags) raises.
strip_whitespace True Collapse whitespace runs in text nodes at parse time.
preserve_comments False Keep comments in the tree (always captured in doc.comments).

Output and sanitize keys (remove_comments, pretty_indent, allowed_tags, …) are consumed by paster, not confext.

Errors

ConfextError  parse failures, strict-mode violations (unclosed/
                  stray tags and depth-limit breaches — deeper nodes
                  are silently dropped outside strict mode) and
                  size-limit breaches

Invalid selectors now raise paster's SelectorSyntaxError.

Layout

confext/
├── __init__.py     public API: parse; re-exports Engine,
│                   DEFAULT_CONFIG, ConfextError, Node,
│                   ParsedDocument, VOID_ELEMENTS, Config,
│                   load_config/save_config, config errors
├── errors.py       ConfextError, ConfigLoadError family
├── tree.py         Node, ParsedDocument (tree model + stats)
├── reader.py       encoding detection, TreeBuilder (stdlib tokenizer)
├── engine.py       Engine, DEFAULT_CONFIG, LRU cache
└── config.py       Config, load_config/save_config (default.config)

Metadata

Release files for confext 0.7.2

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

Source distribution (sdist)

Source distribution for confext 0.7.2
File Size Uploaded Provenance Actions
confext-0.7.2.tar.gz 12.7 kB Without provenance Details for confext-0.7.2.tar.gz

Built distribution (wheel)

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

Total release size: 25.0 kB

Release files / confext-0.7.2.tar.gz

Download URL confext-0.7.2.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8d6356f24ecb66b1ee166fec2351f1787e13d10aab90456d52a7010b17406159
BLAKE2b-256 checksum
How to use checksums
65a1fb5c103d6540c4e7525a35b7e0f7881a7992a7160702787517cbd34bb9b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.4

Release files / confext-0.7.2-py3-none-any.whl

Download URL confext-0.7.2-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b39970f7fc5c58646980092f0114753280ca5ed7df00f3e8d0774f430281631
BLAKE2b-256 checksum
How to use checksums
602fb99579bbb3b76aff6080884e10ca404a02299a8751e885db5551ca9ad35e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.4

Security for confext 0.7.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.7.2 This release

2 release files No 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