Sass for Python (libsass)

0.23.0 · maintenance · verified Sat Apr 11

Libsass is a Python binding for LibSass, the C/C++ port of the original Sass CSS preprocessor. It allows Python developers to compile Sass/SCSS files to CSS without needing a Ruby or Node.js runtime. While the `libsass-python` wrapper is actively maintained and currently at version 0.23.0 (released January 6, 2024), the underlying LibSass C/C++ library reached its official End-of-Life in October 2025 and is no longer receiving updates.

Warnings

Install

Imports

Quickstart

Compiles a SCSS string to a compressed CSS string. The `compile` function can also take `filename` or `dirname` arguments for file-based compilation.

import sass

scss_code = """
$primary-color: #337ab7;

.container {
  h1 {
    color: $primary-color;
  }
  p {
    font-size: 1.2em;
  }
}
"""

try:
    css_output = sass.compile(string=scss_code, output_style='compressed')
    print(css_output)
except sass.CompileError as e:
    print(f"Sass compilation error: {e}")

view raw JSON →