Pynliner

0.8.0 · maintenance · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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)

view raw JSON →