skillfed

premailer

Turns CSS blocks into style attributes

premailer v3.10.0 5.0M downloads/30d#2,181 on PyPI1,084
Permissive license Python DORMANT released

What it is and what it does

Premailer is a Python library that transforms HTML documents by inlining CSS styles into HTML element attributes. It parses HTML, extracts CSS from style blocks and external stylesheets, and rewrites the DOM to apply those styles as inline style attributes—a requirement for most email clients, which strip out style tags for security reasons.

The package handles relative URL rewriting (converting relative links to absolute ones using a base URL), CSS selector parsing via cssutils and cssselect, and HTML parsing via lxml. It offers both a simple transform() function for basic use and a full Premailer class for advanced configuration. It can preserve or strip certain CSS features (pseudoclasses, !important declarations, class attributes) and supports command-line usage for batch processing.

Use it for:

  • Prepare HTML newsletters and transactional emails for delivery by inlining all styles before sending.
  • Convert relative URLs in email templates to absolute URLs using a base_url parameter.
  • Strip !important declarations and pseudoclasses from CSS to ensure compatibility with email clients.
  • Process HTML templates from a file or stdin via the command-line interface for CI/CD pipelines.
  • Preserve specific CSS or links (e.g., handlebar syntax, cid: attachments) while inlining other styles.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts CSS style blocks into inline style attributes on HTML elements, making HTML suitable for email clients that don't support style tags.

Yes, if you are building email systems. Premailer solves a real, specific problem—email clients require inline styles—and does it reliably. The dormant maintenance is a minor concern given the stable classifier and zero known vulnerabilities, but verify that its CSS and HTML parsing behavior still meets your email client compatibility needs before adopting it for new projects.

Install

premailer on PyPI

pip

pip install premailer

uv

uv add premailer

poetry

poetry add premailer

Installing premailer

Before you install

Low friction: pure Python wheel with five straightforward runtime dependencies (lxml, cssselect, cssutils, requests, cachetools). Maintenance is dormant—last release was 2021-08-02 and last commit 2023-12-16—but the package is marked Production/Stable and has no known vulnerabilities.

License in practice

Licensed under the Python Software Foundation License, a permissive license. No restrictions on use, modification, or distribution in commercial or private projects.

Quickstart

pip install premailer

from premailer import transform
html = '<style>p { color: red; }</style><p>Hello</p>'
result = transform(html)
print(result)

By default, premailer attempts to download external stylesheets over the network; use allow_network=False to prevent this if needed.

Verify before relying

  • Whether the dormant maintenance status (last release 2021-08-02) affects compatibility with modern email clients or CSS specifications.
  • Performance characteristics when processing large HTML documents or many external stylesheets.

Package facts

License Python (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 5 — lxml, cssselect, cssutils, requests, cachetools
Maintenance dormant — 1,838 days since the last release
Last repo commit
First released
Downloads 5,013,987/month — #2,181 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: premailer-3.10.0-py2.py3-none-any.whl

Keywords: html, lxml, email, mail, style

Development Status :: 5 - Production/StableEnvironment :: Other EnvironmentEnvironment :: Web EnvironmentIntended Audience :: DevelopersLicense :: OSI Approved :: Python Software Foundation LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: CommunicationsTopic :: Internet :: WWW/HTTPTopic :: Other/Nonlisted TopicTopic :: Software Development :: Libraries :: Python Modules

Tags

css to inline styleshtml email preprocessingstyle tag inliningemail html transformationcss inlining for emailhtml style attributesemail client compatibility
email-processinghtml-transformationcss-inlining

More Python Modules packages