Skip to main content

Python Dependencies Tests

Features

  • Parse HTML into structured tag / text / metadata results
  • CSS-style selectors (#id, .class, tag name)
  • Whitelist-based sanitization
  • Minification with comment stripping
  • Link and table extraction
  • LRU result caching with TTL
  • RSS 2.0 feed parsing
  • JSON / CSV export
  • CLI tool
  • Standard library only — no third-party dependencies

Installation

pip install pafer

Quickstart

from pafer import HTMLPafer

html = '<div class="post"><h1>Title</h1><a href="/about">About</a></div>'

p = HTMLPafer()
result = p.parse(html)

result['tags']        # list of {name, attributes, content, rows?}
result['metadata']    # {'title': ...}
result['doctype']     # '<!DOCTYPE ...>' or None

p.select(html, '.post')    # match by #id, .class or tag name
p.sanitize(html)           # keep only allowed tags
p.minify(html)             # collapse whitespace, strip comments
p.extract_links(html)      # [{'url': ..., 'text': ..., 'attributes': ...}]

Enable the parsed-result cache with HTMLPafer(use_cache=True).

Configuration

load_config(path) loads an exact file and raises ConfigLoadError (or a subclass) when it is missing, invalid, or corrupted. Omitting path auto-finds the caller's default.config — module directory first, then the package directory; find_default_config() exposes that lookup directly. Config() (or Config.load_default()) uses built-in defaults without touching the filesystem. save_config auto-finds its target the same way when path is omitted.

File format

raw:   [8-byte MD5 checksum][4-byte size][pickle payload]
gzip:  [8-byte MD5 checksum][4-byte size][gzip.compress(pickle payload)]
xz:    [8-byte MD5 checksum][4-byte size][lzma.compress(pickle payload)]
zlib:  [8-byte MD5 checksum][4-byte size][zlib.compress(pickle payload)]
from pafer import load_config, save_config

settings = {'strip_whitespace': False, 'cache_size': 100}
save_config(settings, 'my.config')                   # raw
save_config(settings, 'my.config.gz', compression='gzip')
save_config(settings, 'my.config.xz', compression='xz')
cfg = load_config('my.config.gz')                    # format auto-detected

Default settings

Key Default Purpose
parse_tables True extract table rows while parsing
strip_whitespace True collapse whitespace
encoding utf-8 decode bytes input
max_depth 100 maximum element nesting
default_tag div fallback tag
preserve_comments False keep comments in the tree
strict_mode False raise on malformed HTML
remove_comments True strip comments when minifying
allowed_tags p, br, b, i, a, ul, ol, li, div, span sanitize whitelist
max_file_size_mb 10 reject oversized input
cache_size 50 cache capacity

Caching

pafer.cache.LRUCache is an in-memory LRU cache with TTL expiry:

from pafer.cache import LRUCache

cache = LRUCache(max_size=100, ttl_seconds=300)
cache.set('key', value)
cache.get('key')

RSS feeds

from pafer.feed import FeedPafer

items = FeedPafer().parse_rss(xml_content)
items[0]['title']       # 'title', 'link', 'description', 'pubDate'

Exporting

from pafer.exporters import DataExporter

DataExporter.to_json(data)    # JSON string with 2-space indent
DataExporter.to_csv(rows)     # CSV from a list of rows

Exceptions

HTMLPaferError (base), SanitizationError, SelectorSyntaxError, ConfigLoadError.

LICENSE

MIT

Metadata

Release files for pafer 0.9.8

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

Source distribution (sdist)

Source distribution for pafer 0.9.8
File Size Uploaded
pafer-0.9.8.tar.gz 11.9 kB Details

Built distribution (wheel)

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

Total release size: 23.7 kB

Release files / pafer-0.9.8.tar.gz

Download URL pafer-0.9.8.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9412507fff1c919ddc77cbe25c4a6b11145dd0f137001a3bb4798343c20189d2
BLAKE2b-256 checksum
How to use checksums
3f45fd4064eb2c73579386eb9782ea08860ed724f90a795a7a6fdda25e3052b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / pafer-0.9.8-py3-none-any.whl

Download URL pafer-0.9.8-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2274ad931e3f488ce962df13f43fed056b93c27d8c88e42d0fffd699ae2c5c9
BLAKE2b-256 checksum
How to use checksums
3c939502e12a80afa95dd2e8bcad8930f5cc9a00364f555a7044c68975eafff0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.9.8 This release

2 release files

0.9.7

2 release files

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