Skip to main content

The lessc Python package compiles content in LESS syntax into CSS by first preprocessing it and then invoking the nodejs lessc program to actually compile it. The preprocessing resolves imports which allows the LESS content to come from anywhere, including the filesystem, zipped EGG files, databases, etc. This solves one of the greatest limitations of the nodejs lessc program which requires all of the LESS dependencies to be actual files and imports to be non-absolute.

It is possible, but quite improbable, that this package turns into a pure-Python implementation of a LESS compiler.

For more information on LESS, please see http://lesscss.org/.

Project

Installation

$ npm install less
$ export PATH="`pwd`/node_modules/.bin:$PATH"
$ pip install lessc

Usage

import lessc

# compile a less asset in the "mypackage" python module:
css = lessc.compile_asset('mypackage:path/to/style.less')

# compile a less file on the filesystem
css = lessc.compile_file('../path/to/style.less')

# compile a less file-like object
# (if there are any relative imports, specifying `base` is necessary)
css = lessc.compile_file(open('../path/to/style.less'))

# compile a less string
# (if there are any relative imports, specifying `base` is necessary)

less = '''
  @import "mypackage:path/to/style.less";
  // ...other less statements...
'''

css = lessc.compile(less)

For more import resolution control, you can specify a custom URI resolver (which resolves a relative URI to an absolute URI) and a custom URI loader (which loads an absolute URI), using the resolver and loader keywords to any compile* function:

import lessc

def resolver(uri, base=None):
  '''
  Returns the absolute URI given a base URI and a potentially
  absolute or relative URI. Note that `base` may be ``None`` when
  the initial URI is being resolved (depending on the Compiler
  configuration).
  '''
  # calculate the absolute URI...
  return absolute_uri

def loader(uri):
  '''
  Returns a file-like object that will return the content of
  the specified URI.
  '''
  # fetch the object defined by `uri`
  return file_like_object

css = lessc.compile_asset(uri, resolver=resolver, loader=loader)

Or you can create a custom compiler and set it as the default compiler:

import lessc

compiler = lessc.Compiler(resolver=my_custom_resolver, loader=my_custom_loader)
lessc.set_default_compiler(compiler)

# this will now use `my_custom_resolver` and `my_custom_loader`
# to compile asset `uri`
css = lessc.compile_asset(uri)

Limitations

Currently, there exist the following restrictions in what kind of LESS syntax is used:

  • Recursive imports are not supported and will be silently ignored.

  • Only the following import keywords are explicitly supported:

    • less

    • css

    • once

    • optional

    The keywords reference, inline, and multiple are NOT supported. Any other keywords may or may not be supported (since only the above keywords were documented as of this writing, 2015/06/26).

Metadata

Release files for lessc 0.1.3

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

Source distribution (sdist)

Source distribution for lessc 0.1.3
File Size Uploaded Provenance
lessc-0.1.3.tar.gz 8.3 kB Without provenance Details

Release files / lessc-0.1.3.tar.gz

Download URL lessc-0.1.3.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
97a12f5f04731c9e77b5e14106ae07a77409081c901000fbec88e4a0a2e6de82
BLAKE2b-256 checksum
How to use checksums
28d3018ea21e5438b7b461d475a8df1cea1755608e731a1c55ebb351d8531629
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Security for lessc 0.1.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.3 This release

1 release file No provenance

0.1.0

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