Skip to main content

LESSCPY

Build Status Coverage Status PyPI Downloads PyPI Version Wheel Status License

Python LESS Compiler.

A compiler written in Python for the LESS language. For those of us not willing or able to have node.js installed in our environment. Not all features of LESS are supported. Some features will probably never be supported (JavaScript evaluation). This program uses PLY (Python Lex-Yacc) to tokenize / parse the input and is considerably slower than the Node.js compiler.

For more information on LESS:

Development files:

Supported features

  • Variables
  • String interpolation
  • Mixins (nested, calls, closures, recursive)
  • Guard expressions
  • Parametered mixins (class / id)
  • @arguments
  • Nesting
  • Escapes ~/e()
  • Expressions
  • Keyframe blocks
  • Color functions (lighten, darken, saturate, desaturate, spin, hue, mix, saturation, lightness)
  • Other functions (round, increment, decrement, format '%(...))

Differences from less.js

  • All colors are auto-formatted to #nnnnnn (for example, #f7e923)
  • Does not preserve CSS comments

Not supported

  • JavaScript evaluation

Requirements

  • Python 3.11+
  • pip

Installation

Install from PyPI:

pip install lesscpy

Local setup

Create and activate a virtual environment, then install test dependencies from pyproject.toml:

python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[test]"

Build

Build source and wheel distributions:

python -m pip install --upgrade build
python -m build

Artifacts are created in dist/.

Test

Run unit tests:

pytest -v

Run lint checks:

flake8

Using tox

tox is useful for running the project test workflow in isolated environments and for reproducing the same multi-version checks used in CI.

Run all configured environments:

python -m pip install -e ".[tox]"
tox

Run a single environment:

tox -e py3.12
tox -e flake8

Compiler script usage

usage: lesscpy [-h] [-v] [-I INCLUDE] [-V] [-C] [-x] [-X] [-t] [-s SPACES]
               [-o OUT] [-r] [-f] [-m] [-D] [-g] [-S] [-L] [-N]
               target [output]

Python usage

from io import StringIO
import lesscpy

print(lesscpy.compile(StringIO("a { border-width: 2px * 3; }"), minify=True))

Output:

a{border-width:6px;}

License

See the LICENSE file.

Metadata

Release files for lesscpy 0.15.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lesscpy 0.15.2
File Size Uploaded Provenance
lesscpy-0.15.2.tar.gz 153.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for lesscpy 0.15.2
File Interpreter ABI Platform
lesscpy-0.15.2-py3-none-any.whl Python 3 none any Details

Total release size: 199.1 kB

Release files / lesscpy-0.15.2.tar.gz

Download URL lesscpy-0.15.2.tar.gz
Size 153.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4f6b7f34c22c5ce137e7ee280dcb1984ade0d500b6dab591d4a4d84252d18de9
BLAKE2b-256 checksum
How to use checksums
8e7adaf1c09148be007f6afc3d224afb548c64910772619a083a0a331556d78a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Release files / lesscpy-0.15.2-py3-none-any.whl

Download URL lesscpy-0.15.2-py3-none-any.whl
Size 45.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39da3e9779674889fc67b50d16dff267677e7594cdc9da897e486f6244fd2b1b
BLAKE2b-256 checksum
How to use checksums
759eac02bb38b217d657afe2edb8c9048d6f4008526d1b19e0e69f9fa5336aaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Security for lesscpy 0.15.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for lesscpy-0.15.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page