libsass-python: Sass/SCSS for Python¶
This package provides a simple Python extension module sass which is
binding LibSass (written in C/C++ by Hampton Catlin and Aaron Leung).
It’s very straightforward and there isn’t any headache related to Python
distribution/deployment. That means you can add just libsass into
your setup.py’s install_requires list or requirements.txt
file.
It currently supports CPython 3.7+ and PyPy 3!
Features¶
You don’t need any Ruby/Node.js stack at all, for development or deployment either.
Fast. (LibSass is written in C++.)
Simple API. See example code for details.
Custom functions.
@importcallbacks.Support both tabbed (Sass) and braces (SCSS) syntax.
WSGI middleware for ease of development. It automatically compiles Sass/SCSS files for each request. See also
sassutils.wsgifor details.setuptools/distutilsintegration. You can build all Sass/SCSS files using setup.py build_sass command. See alsosassutils.distutilsfor details.Works also on PyPy.
Provides prebuilt wheel (PEP 427) binaries for Windows and Mac.
Install¶
It’s available on PyPI, so you can install it using pip:
$ pip install libsass
Note
libsass requires some features introduced by the recent C++ standard. You need a C++ compiler that support those features. See also libsass project’s README file.
Examples¶
Compile a String of Sass to CSS¶
>>> import sass
>>> sass.compile(string='a { b { color: blue; } }')
'a b {\n color: blue; }\n'
Compile a Directory of Sass Files to CSS¶
>>> import sass
>>> import os
>>> os.mkdir('css')
>>> os.mkdir('sass')
>>> scss = """\
... $theme_color: #cc0000;
... body {
... background-color: $theme_color;
... }
... """
>>> with open('sass/example.scss', 'w') as example_scss:
... example_scss.write(scss)
...
>>> sass.compile(dirname=('sass', 'css'), output_style='compressed')
>>> with open('css/example.css') as example_css:
... print(example_css.read())
...
body{background-color:#c00}
User’s Guide¶
- Using with Flask
- Changelog
- Version 0.23.0
- Version 0.22.0
- Version 0.21.0
- Version 0.20.1
- Version 0.20.0
- Version 0.19.4
- Version 0.19.3
- Version 0.19.2
- Version 0.19.1
- Version 0.19.0
- Version 0.18.0
- Version 0.17.0
- Version 0.16.1
- Version 0.16.0
- Version 0.15.1
- Version 0.15.0
- Version 0.14.5
- Version 0.14.4
- Version 0.14.3
- Version 0.14.2
- Version 0.14.1
- Version 0.14.0
- Version 0.13.7
- Version 0.13.6
- Version 0.13.5
- Version 0.13.4
- Version 0.13.3
- Version 0.13.2
- Version 0.13.1
- Version 0.13.0
- Version 0.12.3
- Version 0.12.2
- Version 0.12.1
- Version 0.12.0
- Version 0.11.2
- Version 0.11.1
- Version 0.11.0
- Version 0.10.1
- Version 0.10.0
- Version 0.9.3
- Version 0.9.2
- Version 0.9.1
- Version 0.9.0
- Version 0.8.3
- Version 0.8.2
- Version 0.8.1
- Version 0.8.0
- Version 0.7.0
- Version 0.6.2
- Version 0.6.1
- Version 0.6.0
- Version 0.5.1
- Version 0.5.0
- Unstable version 0.4.2.20140529.cd3ee1cbe3
- Unstable Version 0.4.2-20140528-cd3ee1cbe3
- Version 0.4.2
- Version 0.4.1
- Version 0.4.0
- Version 0.3.0
- Version 0.2.4
- Version 0.2.3
- Version 0.2.2
- Version 0.2.1
- Version 0.2.0
- Version 0.1.1
- Version 0.1.0
References¶
pysassc— SassC compliant command line interfacesass— Binding oflibsassCompileErrorMODESOUTPUT_STYLESSOURCE_COMMENTSSassColorSassErrorSassFunctionSassListSassMapSassNumberSassWarningand_join()compile()sassutils— Additional utilities related to Sasssassutils.builder— Build the whole directoryManifestSUFFIXESSUFFIX_PATTERNbuild_directory()sassutils.distutils—setuptools/distutilsintegrationbuild_sassvalidate_manifests()sassutils.wsgi— WSGI middleware for development purposeSassMiddleware
Credit¶
Hong Minhee wrote this Python binding of LibSass.
Hampton Catlin and Aaron Leung wrote LibSass, which is portable C/C++ implementation of Sass.
Hampton Catlin originally designed Sass language and wrote the first reference implementation of it in Ruby.
The above three are all distributed under MIT license.
Open source¶
- GitHub (Git repository + issues)
GitHub Actions (linux + macos + windows)
- PyPI
https://pypi.org/pypi/libsass/
- Changelog