skillfed

dict2css

A μ-library for constructing cascading style sheets from Python dictionaries.

dict2css v0.6.0 669.5K downloads/30d#5,413 on PyPI2
Permissive license MIT Active released

What it is and what it does

dict2css is a lightweight library that bridges Python dictionaries and CSS stylesheets. It provides dump and load functions—similar to the json and toml standard library modules—allowing you to construct CSS from nested Python dicts where keys are CSS selectors and values are property mappings. Property values can optionally include an "important" flag as a tuple. The library depends on domdf-python-tools and tinycss2 for parsing and serialization.

The package targets developers who want to programmatically generate or manipulate CSS within Python, such as in static site generators, template systems, or configuration-driven styling. It is typed, actively maintained, and supports modern Python versions from 3.8 onward.

Use it for:

  • Generate CSS stylesheets programmatically from configuration dictionaries in static site generators or template engines.
  • Parse existing CSS files into Python dicts for inspection, modification, or transformation.
  • Build theme or style configuration systems where CSS is defined as nested Python data structures.
  • Serialize dynamic styling rules computed at runtime into valid CSS output.

Worth the install?

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

dict2css converts Python dictionaries to CSS stylesheets and parses CSS back into dictionaries, with an API modeled on json and toml modules.

Yes, if you need to work with CSS as Python data structures. The library is small, actively maintained, has no known vulnerabilities, and installs with low friction. MIT licensing is unrestrictive. The main unknown is whether it handles advanced CSS features (at-rules, media queries) or only basic selectors and properties—verify against your use case before committing.

Install

dict2css on PyPI

pip

pip install dict2css

uv

uv add dict2css

poetry

poetry add dict2css

Installing dict2css

Before you install

Low friction installation with a pure-Python wheel. Active maintenance as of 2026-07-06, with support across Python 3.8–3.13 and PyPy.

License in practice

MIT license is permissive; you can use, modify, and distribute dict2css with minimal restrictions.

Quickstart

from dict2css import dump

styles = {
    "body": {"margin": "0", "padding": "0"},
    ".header": {"background-color": ("red", "important")}
}

css_string = dump(styles)

Verify before relying

  • Whether the package handles CSS at-rules (@media, @keyframes, etc.) or only simple selectors and properties.
  • Performance characteristics when working with large stylesheets.
  • Whether round-trip fidelity (dump then load) preserves all CSS semantics.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 2 — domdf-python-tools, tinycss2
Maintenance actively maintained — 85 days since the last release
Last repo commit
First released
Downloads 669,534/month — #5,413 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: dict2css-0.6.0-py3-none-any.whl

Keywords: css, serialize

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

python dict to csscss from dictionaryserialize css pythoncss parser dictionarygenerate stylesheet pythoncss builder library
css-generationserialization

More Python Modules packages