--- id: dict2css version: "0.6.0" license: MIT license_treatment: permissive maintenance: active --- # dict2css — A μ-library for constructing cascading style sheets from Python dictionaries. License: permissive · Maintenance: active · Downloads: 669.5K/mo ## 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 above — 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 pip install dict2css uv add dict2css 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_current - Install friction: low - Maintenance: active - Downloads: 669.5K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags python dict to css, css from dictionary, serialize css python, css parser dictionary, generate stylesheet python, css builder library, css-generation, serialization [View on SkillFed](https://skillfed.io/packages/dict2css) · [View on PyPI](https://pypi.org/project/dict2css/)