Registry / web-framework / libsass

libsass

JSON →
library0.23.0pypypi✓ verified 24d ago

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.

pip install libsass
INSTALL
IMPORT
SIG · LIBSASS
L
libsass
web-frameworkpythonv0.23.0
Install
1.9s avg
Import
28ms
Disk
48MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.23.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.9s · import 0.028s · 51MB
48MB installed
● package 48MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile
from sass import compile
The primary function to compile Sass/SCSS to CSS.
CompileError
from sass import CompileError
Exception raised on compilation errors.

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}")
sassc --version
Debug
Known issues
breakingThe upstream LibSass C/C++ library, which `libsass-python` wraps, reached its End-of-Life in October 2025 and is no longer maintained. It will not receive feature updates or compatibility with new CSS/Sass features. Users are strongly advised to migrate to Dart Sass or a Python binding for Dart Sass, such as `sass-embedded-python`.
fix
Migrate to `sass-embedded-python` (or another Dart Sass wrapper) for future-proof Sass compilation.
affects: All versions (due to upstream dependency)
deprecatedPython 2.x support was removed in version 0.22.0.
fix
Ensure your project runs on Python 3.8 or newer (as required by PyPI metadata).
affects: >=0.22.0
deprecatedThe `sassc` command-line interface, previously shipped with libsass-python, was removed in version 0.22.0.
fix
Use the `pysassc` command-line tool, which provides SassC-compliant functionality, or use the `sass.compile()` API directly.
affects: >=0.22.0
gotchaInstallation of `libsass` may require a C++ compiler (like GCC, Clang, or MSVC) on your system, especially if pre-built wheels are not available for your specific platform or Python version. It requires a compiler that supports recent C++ standards (C++11 or newer).
fix
Ensure a compatible C++ compiler is installed and configured in your build environment (e.g., `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS, Visual Studio Build Tools on Windows).
affects: All versions, especially on non-standard environments
gotchaLibSass has known incompatibilities and differences in behavior compared to Dart Sass (the current reference implementation), particularly regarding `@import` vs `@use`, `/` for division, custom property parsing, and `@extend` rules with complex selectors.
fix
Review the Sass documentation on LibSass migration to understand potential behavioral differences when using `libsass-python` vs. Dart Sass. Consider using the Sass migrator tools if transitioning.
affects: All versions
gotchaThe `source_comments` parameter for `sass.compile()` changed its accepted values. Historically, it could take strings like 'none', 'line_numbers', 'map'. As of 0.6.0, it primarily accepts boolean values (`True`/`False`).
fix
Always use boolean values (`True` or `False`) for the `source_comments` parameter. String values are deprecated and will be obsolete.
affects: >=0.6.0
Errors
Common errors & fixes
AttributeError: module 'sass' has no attribute 'compile'
This usually happens due to a naming conflict where another Python package also named 'sass' (not the libsass-python binding) is installed, or an older version of libsass-python is in use where the primary compilation functions were named `compile_string` or `compile_file`.
fix
First, check for conflicting 'sass' packages using `pip freeze | grep sass`. If another 'sass' package is found, uninstall it. Ensure you are importing `sass` from the `libsass` package. If using an older version, try `sass.compile_string(scss_code)` or `sass.compile_file(filepath)` instead of `sass.compile()`.
ImportError: DLL load failed: The specified module could not be found.
On Windows, this error often indicates that the necessary Visual C++ Redistributable runtime libraries are not installed, which are required for the underlying C/C++ LibSass library that libsass-python binds to.
fix
Install the appropriate Microsoft Visual C++ Redistributable for Visual Studio (e.g., 2015, 2017, 2019, or 2022, depending on your Python version's build toolchain) from the official Microsoft website.
ModuleNotFoundError: No module named '_sass'
This error typically occurs when the C extension module (`_sass.pyd` on Windows, `_sass.so` on Linux/macOS) which `libsass` depends on, could not be built or found during installation, often due to missing build tools (like a C++ compiler) or environment issues.
fix
Ensure you have the necessary C++ compiler installed (e.g., Build Tools for Visual Studio on Windows, `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS). Then, uninstall and reinstall `libsass` using `pip uninstall libsass && pip install libsass` to force a rebuild of the extension module.
ModuleNotFoundError: No module named 'distutils.msvc9compiler'
This specific ModuleNotFoundError arises when trying to install libsass from source (e.g., without a pre-built wheel) on newer Python versions (3.10+) with recent `setuptools` versions, because `distutils` has been deprecated and largely removed.
fix
The most reliable fix is to ensure `pip` can install a pre-built wheel for your system. If that's not possible, a workaround can be to temporarily downgrade `setuptools` to a version prior to 74 (e.g., `pip install setuptools<74`) before installing `libsass`, and then optionally upgrading `setuptools` again.
Upgrade
Version history
0.23.0latest on PyPI · released Jan 6, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
Resources
libsass — pip install libsass · libregistry