Registry / communication / pynliner

pynliner

JSON →
library0.8.0pypypi✓ verified 87d ago

Pynliner is a Python library that converts CSS styles in an HTML document to inline styles, primarily designed for crafting HTML emails to ensure consistent rendering across various email clients. It leverages BeautifulSoup for HTML parsing and cssutils for CSS processing. The current stable version is 0.8.0, released in 2019, indicating an infrequent release cadence and a current state of maintenance rather than active development.

pip install pynliner
INSTALL
IMPORT
SIG · PYNLINER
P
pynliner
communicationpythonv0.8.0
Install
2.2s avg
Import
643ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.0 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.666s · 22.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.2s · import 0.620s · 24MB
21MB installed
● package 21MB
Code
Verified usage

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

Pynliner
from pynliner import Pynliner

Initialize Pynliner and apply CSS styles from an HTML string into inline 'style' attributes. This is the primary method for inlining CSS for email clients.

from pynliner import Pynliner html_content = """ <html> <head> <style type="text/css"> h1 { color: red; } p { font-size: 16px; margin: 0; } .container { background-color: #f0f0f0; padding: 20px; } </style> </head> <body> <div class="container"> <h1>Hello, Pynliner!</h1> <p>This is a paragraph with inlined styles.</p> </div> </body> </html> """ inliner = Pynliner() inlined_html = inliner.from_string(html_content) # The inlined_html string now contains the HTML with CSS styles moved inline. # print(inlined_html)
Debug
Known issues
gotchaPynliner only processes CSS found within <style> blocks and existing 'style' attributes in the HTML string. It explicitly ignores external CSS files linked via <link rel="stylesheet"> tags.
fix
Ensure all CSS intended for inlining is embedded directly within <style> tags in the HTML document's <head> section.
affects: All versions
gotchaPynliner does not resolve CSS @import rules within <style> blocks. Any styles imported this way will not be processed or inlined.
fix
Consolidate all CSS into a single <style> block, avoiding @import rules for external stylesheets.
affects: All versions
gotchaThe library's last release was in 2019 (v0.8.0), and development appears dormant. It may not fully support modern CSS features (e.g., Flexbox, Grid, advanced pseudo-selectors) or newer HTML5 structures, potentially leading to incomplete or incorrect inlining for contemporary web designs.
fix
Test thoroughly with target email clients. For cutting-edge CSS, consider alternative, more actively maintained tools or simplify designs to what's well-supported by email clients.
affects: All versions after 0.8.0 (due to lack of updates)
gotchaPynliner respects CSS specificity rules. If a style is defined with `!important` in a <style> block, it will override an existing inline style or a less specific rule, which can lead to unexpected results if not carefully managed.
fix
Carefully manage CSS specificity and the use of `!important`. Test the output to ensure styles are applied as intended, especially when combining authored CSS with existing inline styles.
affects: All versions
Errors
Common errors & fixes
cssutils.css.CSSSyntaxError: [err] ... (e.g., 'Expected semicolon or '}', got 'invalid_token')
The input CSS contains syntax errors, which cssutils (Pynliner's underlying CSS parser) cannot process.
fix
Review and validate your CSS syntax. Use a CSS linter or validator to identify and correct any malformed rules or properties before passing the HTML to Pynliner.
AttributeError: 'NoneType' object has no attribute 'find_all' (or similar BeautifulSoup errors like 'NoneType' object has no attribute 'select')
This error typically occurs when Pynliner's internal BeautifulSoup parsing cannot find an expected HTML element, and subsequent operations are attempted on a 'None' object. This can happen with malformed HTML or incorrect CSS selectors used internally by Pynliner if the HTML structure is very unusual.
fix
Ensure your HTML is well-formed and valid. Check for unclosed tags, incorrect nesting, or other structural issues that might confuse the HTML parser.
Pynliner output does not include expected styles (styles are missing or incorrect in the output HTML).
The most common causes are using external CSS files (<link>), @import rules, or very complex/modern CSS selectors that Pynliner's older version might not fully support or correctly resolve against the HTML.
fix
Verify that all CSS is embedded in <style> tags. Avoid @import. Simplify complex CSS selectors if possible. Remember Pynliner processes styles in order, so later rules might override earlier ones based on specificity and document order.
Upgrade
Version history
0.8.0latest on PyPI · released Jan 10, 2017
Audit
Dependencies
beautifulsoup4requiredRequired for HTML parsing and manipulation.
cssutilsrequiredRequired for CSS parsing and manipulation.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
homepageUNKNOWN
pynliner — pip install pynliner · libregistry