skillfed

lesscpy

Python LESS compiler

lesscpy v0.15.2 179.9K downloads/30d#10,158 on PyPI144
Permissive license MIT Active released

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 lesscpy

uv

uv add lesscpy

poetry

poetry add lesscpy

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersIntended Audience :: End Users/DesktopIntended Audience :: System AdministratorsOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Code GeneratorsTopic :: Software Development :: Pre-processors

Tags

less compiler pythonless to css conversionpython less preprocessorlesscss compilerless stylesheet compilercss preprocessor pythonless language support
css-preprocessingless-compilerbuild-tool

More Code Generators packages