Registry / serialization / prettierfier

prettierfier

JSON →
library1.0.3pypypi✓ verified 24d ago

Prettierfier is a Python library designed to intelligently pretty-print HTML/XML strings, specifically addressing the issue of unwanted line breaks that often occur with other tools like BeautifulSoup's `prettify()` method. It focuses on preserving inline tags without introducing extraneous whitespace. The current version is 1.0.3, and its release cadence appears to be inactive, with the last update in 2019, suggesting a stable but unmaintained project.

pip install prettierfier
INSTALL
IMPORT
SIG · PRETTIERFIER
P
prettierfier
serializationpythonv1.0.3
Install
1.5s avg
Import
57ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.062s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.052s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

prettierfier
import prettierfier
from prettierfier import prettify_html # or prettify_xml
The library exposes functions directly under the main module, so importing the module itself is the standard approach before calling its methods.

This example demonstrates how to use `prettierfier.prettify_html()` and `prettierfier.prettify_xml()` to reformat HTML and XML strings, respectively, addressing undesirable whitespace around inline tags or applying indentation.

import prettierfier ugly_html = """<p> Introducing GitHub <sup> &reg; </sup> </p>""" pretty_html = prettierfier.prettify_html(ugly_html) print(pretty_html) ugly_xml = """<root><tag1>Text</tag1><tag2 attr='value'></tag2></root>""" pretty_xml = prettierfier.prettify_xml(ugly_xml, indent=4) print(pretty_xml)
Debug
Known issues
gotchaThis library (prettierfier) is distinct from the popular JavaScript code formatter 'Prettier'. Do not confuse the two; `prettierfier` is for HTML/XML string formatting in Python, while the main Prettier formatter is a multi-language (primarily JS) code formatter with a separate, deprecated Python plugin.
fix
Ensure you are installing `prettierfier` (for HTML/XML) and not attempting to use it for general Python code formatting, for which alternatives like Black or Ruff are recommended.
affects: All versions
gotchaThe `prettierfier` library's `prettify_html()` function is 'originally created to process BeautifulSoup.prettify() output' and 'does not add or remove regular line breaks' in general HTML if they are not already present. It primarily cleans up whitespace around inline tags, rather than imposing a complete formatting style from scratch.
fix
For heavily unformatted HTML without existing newlines, `prettierfier` might not introduce all the line breaks you expect for full readability. It works best on HTML that already has some structure or has been partially formatted (e.g., by BeautifulSoup.prettify()) and needs fine-tuning for inline elements.
affects: All versions
deprecatedThe library has not received updates since version 1.0.3 in July 2019. While it uses only the Python Standard Library, long-term maintenance, compatibility with future Python versions, and community support might be limited.
fix
Evaluate if the specific HTML/XML formatting needs are met by this library. For active development, consider alternative, more actively maintained tools if broader or more robust formatting features are required. Given its simple scope and reliance on standard libraries, it might continue to function well for its intended purpose.
affects: 1.0.3 and older
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'prettierfier'
The 'prettierfier' library is not installed in your active Python environment, or your Python environment is not correctly configured to find installed packages.
fix
Ensure you have installed the library using pip: `pip install prettierfier`
AttributeError: module 'prettierfier' has no attribute 'prettify'
You are attempting to call a function named 'prettify' directly on the 'prettierfier' module, which does not exist. The library's main functions are `prettify_html` and `prettify_xml`.
fix
Use the correct function names: `prettierfier.prettify_html(html_string)` for HTML or `prettierfier.prettify_xml(xml_string)` for XML.
prettierfier not adding newlines
The `prettify_html()` and `prettify_xml()` functions are designed to intelligently clean up whitespace around inline tags and preserve existing line breaks, rather than introducing extensive new line breaks to entirely unformatted HTML/XML strings. It works best on input that already has some structural line breaks.
fix
For heavily unformatted HTML or XML, consider a pre-processing step (e.g., using `BeautifulSoup.prettify()` if working with HTML) to introduce initial line breaks before using `prettierfier` to refine inline tag spacing and consolidate unwanted whitespace.
Upgrade
Version history
1.0.3latest on PyPI · released Jul 22, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
prettierfier — pip install prettierfier · libregistry