lesscpy
Python LESS compiler
What it is and what it does
Lesscpy is a Python implementation of a LESS-to-CSS compiler that lets you use LESS stylesheets in environments where Node.js is unavailable or undesirable. It tokenizes and parses LESS syntax using PLY (Python Lex-Yacc) and outputs valid CSS. The package supports a substantial subset of LESS features including variables, mixins with nesting and recursion, guard expressions, color manipulation functions, and string interpolation.
You can use it either as a command-line tool (with options for minification, includes, and output control) or programmatically by calling `lesscpy.compile()` on a file-like object or string. The main trade-off is speed: it runs slower than the Node.js reference implementation because it's written in Python, and it does not support JavaScript evaluation within LESS files. All colors are normalized to six-digit hex format, and CSS comments are not preserved.
Use it for:
- Compile LESS stylesheets in Python web frameworks (Django, Flask) without a Node.js dependency
- Integrate LESS compilation into Python-based build pipelines or static site generators
- Process LESS files in containerized or restricted environments where Node.js cannot be installed
- Automate stylesheet preprocessing in CI/CD workflows using only Python tooling
- Support LESS in legacy Python projects that cannot adopt modern JavaScript tooling
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Compiles LESS stylesheets to CSS using Python, without requiring Node.js. Supports variables, mixins, nesting, color functions, and guard expressions, but not JavaScript evaluation.
Yes, if you need LESS compilation in a Python-only environment and can accept slower performance than Node.js. The low install friction, active maintenance, MIT license, and lack of vulnerabilities make it a straightforward choice. No, if you already have Node.js available or require JavaScript evaluation within LESS files—use the reference compiler instead.
Install
lesscpy on PyPI
pip
pip install lesscpyuv
uv add lesscpypoetry
poetry add lesscpyInstalling lesscpy
Before you install
Low friction: pure Python wheel with a single runtime dependency (ply). Active maintenance with a release 15 days ago and last commit on 2026-07-30. Stable production status and no known vulnerabilities.
License in practice
MIT license permits commercial and private use with minimal restrictions, making it safe to integrate into most projects without licensing concerns.
Quickstart
from io import StringIO
import lesscpy
result = lesscpy.compile(StringIO("a { border-width: 2px * 3; }"), minify=True)
print(result)
Requires Python 3.11 or later
Verify before relying
- Whether the package's performance characteristics (described as 'considerably slower than the Node.js compiler') are acceptable for your build pipeline
- Completeness of LESS feature coverage beyond the listed supported features for your specific stylesheets
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — ply |
| Maintenance | actively maintained — 15 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 179,946/month — #10,158 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: lesscpy-0.15.2-py3-none-any.whl
Tags
More Code Generators packages
Proto Plus wraps protocol buffers to provide…
permissive · top 1,000 on PyPI
CythonCython is a source code translator that…
permissive · top 1,000 on PyPI
asttokensAnnotates Python abstract syntax trees with the…
permissive · top 1,000 on PyPI
beartypeBeartype is a runtime type checker that…
permissive · top 1,000 on PyPI
llvmlitellvmlite provides a lightweight Python binding…
permissive · top 1,000 on PyPI
astorastor converts Python abstract syntax trees…
permissive · top 5,000 on PyPI
pyScssCompiles Sass/SCSS stylesheets to CSS,…
permissive · top 15,000 on PyPI
vbuildCompiles Vue single-file components (*.vue) to…
permissive · top 15,000 on PyPI
stylusBridges Python code to the Stylus CSS compiler,…
permissive · top 15,000 on PyPI
pscriptPScript compiles a Python subset to JavaScript,…
unclear · top 15,000 on PyPI
Flask-MinifyFlask extension that automatically minifies…
permissive · top 15,000 on PyPI
django-compressorDjango Compressor combines, minifies, and…
permissive · top 5,000 on PyPI
CoffeeScriptCompiles CoffeeScript code to JavaScript from…
permissive · top 15,000 on PyPI
dukpyDukPy is a JavaScript interpreter for Python…
permissive · top 15,000 on PyPI
pytailwindcssInstalls and wraps the standalone Tailwind CSS…
permissive · top 15,000 on PyPI
pcppA pure Python implementation of a C99…
permissive · top 15,000 on PyPI