lesscpy - Python LESS Compiler

0.15.1 · maintenance · verified Fri Apr 17

lesscpy is a Python compiler for LESS stylesheets, converting .less files into standard CSS. Its current version is 0.15.1, released in 2018. The project is largely unmaintained, with no significant development since its last release, indicating a maintenance-only status.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to compile a LESS string into minified CSS using the `lesscpy.compile` function, which accepts a file-like object (like `StringIO`) as input.

from io import StringIO
import lesscpy

# Example LESS code as a string
less_code = """
@primary-color: #3498db;
@spacing: 10px;

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: @spacing;

  h1 {
    color: @primary-color;
    margin-bottom: @spacing * 2;
  }

  p {
    line-height: 1.6;
  }
}

.button {
  background-color: @primary-color;
  color: white;
  padding: @spacing @spacing * 2;
  border: none;
  cursor: pointer;

  &:hover {
    opacity: 0.9;
  }
}
"""

# Compile the LESS code from a StringIO object
# lesscpy.compile expects a file-like object or a filename string.
# The 'minify' argument is common for output control.
css_output = lesscpy.compile(StringIO(less_code), minify=True)

print("--- Compiled and Minified CSS ---")
print(css_output)

view raw JSON →