Python LESS compiler
Python CSS
Latest commit 8d3484d Mar 17, 2016 @saschpe saschpe Bump to version 0.11.1
Failed to load latest commit information.
lesscpy Bump to version 0.11.1 Mar 17, 2016
scripts Move bin/ to scripts/ Feb 2, 2014
test Support for percentage keyframe selectors Aug 21, 2015
.gitignore Ignore *.egg-info Nov 26, 2014
.travis.yml Produce code coverage results and publish to Feb 6, 2014
AUTHORS Add AUTHORS file Feb 2, 2014
LICENSE initial commit Jan 28, 2012 Add test-requirements.txt Feb 2, 2014
README.rst Remove duplicated feature : "Keyframe blocks" Mar 12, 2015
requirements.txt Add support for py3. Feb 16, 2014
setup.cfg Support publishing wheels Feb 2, 2014 Change to more platform-independent Oct 30, 2014


LESSCPY 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 (yet). Some features wil probably never be supported (JavaScript evaluation). This program uses PLY (Python Lex-Yacc) to tokenize / parse the input and is considerably slower than the NodeJS compiler. The plan is to utilize this to build in proper syntax checking and perhaps YUI compressing.

This is an early version, so you are likely to find bugs.

For more information on LESS: or
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. eg, #f7e923
  • Does not preserve CSS comments

Not supported

  • JavaScript evaluation


  • Python 2.6, 2.7, or 3.3
  • ply (Python Lex-Yacc) (check requirements.txt)


To install lesscpy from the Python Package Index, simply:

$ pip install lesscpy

To do a local system-wide install:

python install

Or simply place the package into your Python path. Or rather use packages provided by your distribution (openSUSE has them at least).

Compiler script Usage

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

LessCss Compiler

positional arguments:
  target                less file or directory

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -I INCLUDE, --include INCLUDE
                        Included less-files (comma separated)
  -V, --verbose         Verbose mode

Formatting options:
  -x, --minify          Minify output
  -X, --xminify         Minify output, no end of block newlines
  -t, --tabs            Use tabs
  -s SPACES, --spaces SPACES
                        Number of startline spaces (default 2)

Directory options:
  Compiles all \*.less files in directory that have a newer timestamp than
  it's css file.

  -o OUT, --out OUT     Output directory
  -r, --recurse         Recursive into subdirectorys
  -f, --force           Force recompile on all files
  -m, --min-ending      Add '.min' into output filename. eg, name.min.css
  -D, --dry-run         Dry run, do not write files

  -g, --debug           Debugging information
  -S, --scopemap        Scopemap
  -L, --lex-only        Run lexer on target
  -N, --no-css          No css output

Python usage

If you want to use the compiler from within Python, you can do it like this:

import lesscpy
from six import StringIO

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

The output will be:



See the LICENSE file