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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lesscpy-0.15.2.tar.gz (153.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lesscpy-0.15.2-py3-none-any.whl (45.7 kB view details)

Uploaded Python 3

File details

Details for the file lesscpy-0.15.2.tar.gz.

File metadata

  • Download URL: lesscpy-0.15.2.tar.gz
  • Upload date:
  • Size: 153.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lesscpy-0.15.2.tar.gz
Algorithm Hash digest
SHA256 4f6b7f34c22c5ce137e7ee280dcb1984ade0d500b6dab591d4a4d84252d18de9
MD5 e2c1f1f31caf92e645d77a6534d4f30a
BLAKE2b-256 8e7adaf1c09148be007f6afc3d224afb548c64910772619a083a0a331556d78a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lesscpy-0.15.2.tar.gz:

Publisher: main.yml on lesscpy/lesscpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lesscpy-0.15.2-py3-none-any.whl.

File metadata

  • Download URL: lesscpy-0.15.2-py3-none-any.whl
  • Upload date:
  • Size: 45.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lesscpy-0.15.2-py3-none-any.whl
Algorithm Hash digest
SHA256 39da3e9779674889fc67b50d16dff267677e7594cdc9da897e486f6244fd2b1b
MD5 214baae7e12c0aee06a43a869efe7745
BLAKE2b-256 759eac02bb38b217d657afe2edb8c9048d6f4008526d1b19e0e69f9fa5336aaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for lesscpy-0.15.2-py3-none-any.whl:

Publisher: main.yml on lesscpy/lesscpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.15.2 This release

2 files

0.15.1

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.11.2

2 files

0.11.1

2 files

0.10.2

2 files

0.10.1

2 files

0.10

1 file

0.9

0.7

0.6

1 file

0.9j

1 file

0.9i

2 files

0.9h

1 file

0.9g

1 file

0.9f

1 file

0.9e

1 file

0.9d

1 file

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