LIBSASS(3)
π NAME π
libsass β this is literally the libsass documentation, bestie π
So this package hands you a simple Python extension module called sass that's binding LibSass (https://github.com/sass/libsass) β which, no cap, was 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. Which means you can add just libsass into your setup.py's install_requires list or requirements.txt file. So easy. So slay. β¨
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. Not even a little bit. π«π
- Fast. (Because LibSass (
https://github.com/sass/libsass) is written in C++. That's the whole reason. Iconic.) - Simple API. See the example code below for the details. π«Ά
- Custom functions.
@importcallbacks.- Support both tabbed (Sass) and braces (SCSS) syntax. Both vibes. πΈ
- WSGI middleware for ease of development. It automatically compiles Sass/SCSS files for each request. See also the
sassutils.wsgimodule for details. π₯ setuptools/distutilsintegration (/usr/share/doc/python3-doc/html/library/distutils.html#module-distutils). You can build all Sass/SCSS files using thesetup.py build_sasscommand. See also thesassutils.distutilsmodule for details. π οΈ- Works also on PyPy.
- Provides prebuilt wheel (PEP 427
https://peps.python.org/pep-0427/) binaries for Windows and Mac. πͺπ
π INSTALL π
It's available on PyPI (https://pypi.org/pypi/libsass/), so you can install it using pip:
$ pip install libsass
Note:libsassrequires some features introduced by the recent C++ standard. You need a C++ compiler that support those features. See also the libsass project's README file (https://github.com/sass/libsass#readme). π
πΈ 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
This guide explains how to use libsass with the Flask web framework (http://flask.pocoo.org/). The sassutils package provides several tools that can be integrated into web applications written in Flask. π«§
π§ Contents
- Using with Flask
- Directory layout
- Defining manifest
- Building Sass/SCSS for each request
- Building Sass/SCSS for each deployment
π§ Directory layout
Imagine the project contained in such directory layout:
setup.pymyapp/__init__.pystatic/sass/css/
templates/
Sass/SCSS files will go inside myapp/static/sass/ directory. Compiled CSS files will go inside myapp/static/css/ directory. CSS files can be regenerated, so add myapp/static/css/ into your ignore list like .gitignore or .hgignore. ποΈβ¨
π§ Defining manifest
The sassutils module defines a concept named manifest. Manifest is the build settings of Sass/SCSS. It specifies some paths related to building Sass/SCSS:
- The path of the directory which contains Sass/SCSS source files.
- The path of the directory which the compiled CSS files will go.
- The path, exposed to HTTP (through WSGI), of the directory that will contain the compiled CSS files.
Every package may have its own manifest. Paths have to be relative to the path of the package. π
For example, in the above project, the package name is myapp. The path of the package is myapp/. The path of the Sass/SCSS directory is static/sass/ (relative to the package directory). The path of the CSS directory is static/css/. The exposed path is /static/css.
These settings can be represented as the following manifests:
{
'myapp': ('static/sass', 'static/css', '/static/css')
}
As you can see the above, the set of manifests are represented in dictionary, in which the keys are packages names and the values are tuples of paths. ππ
π§ Building Sass/SCSS for each request
See also:
- Flask --- Hooking in WSGI Middlewares (
http://flask.pocoo.org/docs/quickstart/#hooking-in-wsgi-middlewares)- The section which explains how to integrate WSGI middlewares to Flask.
- Flask ---
flask:app-dispatch- The documentation which explains how Flask dispatches each request internally.
In development, manually building Sass/SCSS files for each change is a tedious task. SassMiddleware makes the web application build Sass/SCSS files for each request automatically. It's a WSGI middleware, so it can be plugged into the web app written in Flask. π
SassMiddleware takes two required parameters:
- The WSGI-compliant callable object.
- The set of manifests represented as a dictionary.
So:
from flask import Flask
from sassutils.wsgi import SassMiddleware
app = Flask(__name__)
app.wsgi_app = SassMiddleware(app.wsgi_app, {
'myapp': ('static/sass', 'static/css', '/static/css')
})
And then, if you want to link a compiled CSS file, use the url_for() function (/usr/share/doc/python-flask-doc/html/api.html#flask.url_for):
<link href="{{ url_for('static', filename='css/style.scss.css') }}"
rel="stylesheet" type="text/css">
Note: The linked filename isstyle.scss.css, not juststyle.scss. All compiled filenames have trailing.csssuffix. Don't get caught slipping on this one, fr fr. π
π§ Building Sass/SCSS for each deployment
Note: This section assumes that you usesetuptools(https://pypi.org/pypi/setuptools/) for deployment.
See also:
- Flask ---
flask:distribute-deployment- How to deploy Flask application using
setuptools(https://pypi.org/pypi/setuptools/).
- How to deploy Flask application using
If libsass is installed in the site-packages (for example, your virtualenv), the setup.py script also gets a new command provided by libsass: build_sass. The command is aware of the sass_manifests option of setup.py and builds all Sass/SCSS sources according to the manifests. π€―
Add these arguments to setup.py script:
setup(
# ...,
setup_requires=['libsass >= 0.6.0'],
sass_manifests={
'myapp': ('static/sass', 'static/css', '/static/css')
}
)
The setup_requires option makes sure that libsass is installed in site-packages (for example, your virtualenv) before the setup.py script. That means if you run the setup.py script and libsass isn't installed in advance, it will automatically install libsass first. Self-sufficient king behavior. π
The sass_manifests specifies the manifests for libsass.
Now setup.py build_sass will compile all Sass/SCSS files in the specified path and generates compiled CSS files inside the specified path (according to the manifests).
If you use it with sdist or bdist commands, the packed archive will also contain the compiled CSS files! π
$ python setup.py build_sass sdist
You can add aliases to make these commands always run the build_sass command first. Make setup.cfg config:
[aliases]
sdist = build_sass sdist
bdist = build_sass bdist
Now it automatically builds Sass/SCSS sources and include the compiled CSS files to the package archive when you run setup.py sdist. β¨
π§ Changelog
β Version 0.23.0
Released on January 6, 2024.
- Follow up the libsass upstream:
3.6.6β See the release notes of LibSass 3.6.6 (https://github.com/sass/libsass/releases/tag/3.6.6). [452(https://github.com/sass/libsass-python/issues/452) by Anthony Sottile]
β Version 0.22.0
Released on November 12, 2022.
- Remove python 2.x support [
373(https://github.com/sass/libsass-python/issues/373) by anthony sottile]. - Remove deprecated
sassccli [379(https://github.com/sass/libsass-python/issues/379) by anthony sottile].
β Version 0.21.0
Released on May 20, 2021.
- Fix build on OpenBSD. [
310(https://github.com/sass/libsass-python/issues/310) by Denis Fondras]. - Produce abi3 wheels on windows. [
322(https://github.com/sass/libsass-python/issues/322) by Anthony Sottile] - Make the manpage build reproducible. [
319(https://github.com/sass/libsass-python/issues/319) by Chris Lamb] - Follow up the libsass upstream:
3.6.5β See the release notes of LibSass 3.6.5 (https://github.com/sass/libsass/releases/tag/3.6.5). [344(https://github.com/sass/libsass-python/issues/344) by Anthony Sottile]
β Version 0.20.1
Released on August 27, 2020.
- (no changes, re-releasing to test build automation)
β Version 0.20.0
Released on May 1, 2020.
- Produce abi3 wheels on macos / linux [
307(https://github.com/sass/libsass-python/issues/307) by Anthony Sottile] - Follow up the libsass upstream:
3.6.4β See the release notes of LibSass 3.6.4 (https://github.com/sass/libsass/releases/tag/3.6.4). [313(https://github.com/sass/libsass-python/issues/313) by Anthony Sottile]
β Version 0.19.4
Released on November 3, 2019.
- Follow up the libsass upstream:
3.6.3β See the release notes of LibSass 3.6.3 (https://github.com/sass/libsass/releases/tag/3.6.3). [304(https://github.com/sass/libsass-python/issues/304) by Anthony Sottile]
β Version 0.19.3
Released on October 5, 2019.
- Follow up the libsass upstream:
3.6.2β See the release notes of LibSass 3.6.2 (https://github.com/sass/libsass/releases/tag/3.6.2). [302(https://github.com/sass/libsass-python/issues/302) by Anthony Sottile]
β Version 0.19.2
Released on June 16, 2019.
- Follow up the libsass upstream:
3.6.1β See the release notes of LibSass 3.6.1 (https://github.com/sass/libsass/releases/tag/3.6.1). [298(https://github.com/sass/libsass-python/issues/298) by Anthony Sottile]
β Version 0.19.1
Released on May 18, 2019.
- Re-release of
0.19.0with windowspython2.7wheels [297(https://github.com/sass/libsass-python/issues/297) by Anthony Sottile]
β Version 0.19.0
Released on May 18, 2019.
- Follow up the libsass upstream: 3.6.0 β go read the release notes of LibSass 3.6.0 over at
https://github.com/sass/libsass/releases/tag/3.6.0. π [295https://github.com/sass/libsass-python/issues/295by Anthony Sottile]
π Version 0.18.0
Release on March 13, 2019
- Added support for the previous import path in importer callbacks, bestie π«Ά [287
https://github.com/sass/libsass-python/issues/287291https://github.com/sass/libsass-python/issues/291by Frankie Dintino]
π Version 0.17.0
Release on January 03, 2019
- Added a whole lil stack of new cli options π₯ [279
https://github.com/sass/libsass-python/issues/279268https://github.com/sass/libsass-python/issues/268by Frankie Dintino]--sourcemap-fileβ the output file for the source map π--sourcemap-contentsβ embedssourcesContentright up in the source map--sourcemap-embedβ embeds thesourceMappingURLas a data uri--omit-sourcemap-urlβ omits that source map url comment from the output, gone, bye π--sourcemap-rootβ base path, emitted assourceRootin the source map
- Fixed
.sassinWsgiMiddlewareβ again π (it keeps coming back, it's giving sequel energy) [280https://github.com/sass/libsass-python/issues/280by Anthony Sottile]
π Version 0.16.1
Released on November 25, 2018.
- Fixed compilation on macos mojave, the tiny little nightmare π [276
https://github.com/sass/libsass-python/issues/276277https://github.com/sass/libsass-python/issues/277by Anthony Sottile] - Fixed
.sassinWsgiMiddlewareforstrip_extension=True[278https://github.com/sass/libsass-python/issues/278by Anthony Sottile]
π Version 0.16.0
Released on November 13, 2018.
- Use the
-lc++link flag when compiling with clang β¨ [270https://github.com/sass/libsass-python/issues/270by Christian Thieme 271https://github.com/sass/libsass-python/issues/271by Anthony Sottile] - Honor
strip_extensioninSassMiddleware, we love respect π [274https://github.com/sass/libsass-python/issues/274by Anthony Sottile] - Follow up the libsass upstream: 3.5.5 β release notes of LibSass 3.5.5 live at
https://github.com/sass/libsass/releases/tag/3.5.5. [275https://github.com/sass/libsass-python/issues/275by Anthony Sottile]
π Version 0.15.1
Released on September 24, 2018.
- Fixed
setup.py sdistβ which had regressed back in 0.15.0, not the glow-up we wanted π [267https://github.com/sass/libsass-python/issues/267by Anthony Sottile]
π Version 0.15.0
Released on September 16, 2018.
- Fixed invalid escape sequences π¦ [249
https://github.com/sass/libsass-python/issues/249by Anthony Sottile] - Added a code of conduct π [251
https://github.com/sass/libsass-python/issues/251by Nick Schonning] - Added support for python3.7 and removed testing for python3.4 π [254
https://github.com/sass/libsass-python/issues/254by Anthony Sottile] - Added the
strip_extensionoption for the wsgi / distutils builder, iconic β¨ [55https://github.com/sass/libsass-python/issues/55258https://github.com/sass/libsass-python/issues/258by Anthony Sottile 260https://github.com/sass/libsass-python/issues/260by Morten Brekkevold] - Deprecated
sasscβ it's replaced bypysasscnow, RIP to a real one ποΈ [262https://github.com/sass/libsass-python/issues/262by Anthony Sottile] - Import abc classes from
collections.abcto get rid of thatDeprecationWarning[264https://github.com/sass/libsass-python/issues/264by Gary van der Merwe 265https://github.com/sass/libsass-python/issues/265by Anthony Sottile]
π Version 0.14.5
Released on April 25, 2018.
- Follow up the libsass upstream: 3.5.4 β see the release notes of LibSass 3.5.4 at
https://github.com/sass/libsass/releases/tag/3.5.4. [247https://github.com/sass/libsass-python/issues/247by Anthony Sottile]
π Version 0.14.4
Released on April 24, 2018.
- Added the ability to specify imports for custom extensions. π This is the way to enable imports of
.cssfiles (which got removed back in 3.5.3). Specify--import-extensions .cssto restore the previous behavior, no cap. [246https://github.com/sass/libsass-python/issues/246by Samuel Colvin]
π Version 0.14.3
Released on April 23, 2018.
- Follow up the libsass upstream: 3.5.3 β see the release notes of LibSass 3.5.3 at
https://github.com/sass/libsass/releases/tag/3.5.3. [244https://github.com/sass/libsass-python/issues/244by Anthony Sottile]
π Version 0.14.2
Released on March 16, 2018.
- Follow up the libsass upstream: 3.5.2 β see the release notes of LibSass 3.5.2 at
https://github.com/sass/libsass/releases/tag/3.5.2. [243https://github.com/sass/libsass-python/issues/243by Anthony Sottile]
π Version 0.14.1
Released on March 12, 2018.
- Follow up the libsass upstream: 3.5.1 β see the release notes of LibSass 3.5.1 at
https://github.com/sass/libsass/releases/tag/3.5.1. [242https://github.com/sass/libsass-python/issues/242by Anthony Sottile]
π Version 0.14.0
Released on March 6, 2018.
- Follow up the libsass upstream: 3.5.0 β see the release notes of LibSass 3.5.0 at
https://github.com/sass/libsass/releases/tag/3.5.0. [241https://github.com/sass/libsass-python/issues/241by Anthony Sottile] - The
SassListtype gained an extra option,bracketed=False, to match the upstream changes to thesass_listtype π§ [184https://github.com/sass/libsass-python/issues/184by Anthony Sottile]
π Version 0.13.7
Released on February 5, 2018.
- Follow up the libsass upstream: 3.4.9 β see the release notes of LibSass 3.4.9 at
https://github.com/sass/libsass/releases/tag/3.4.9. [232https://github.com/sass/libsass-python/issues/232by Anthony Sottile]
π Version 0.13.6
Released on January 19, 2018.
libsass-pythonhas moved to the sass organization! π‘ main character relocation arc fr fr
π Version 0.13.5
Released on January 11, 2018.
- Follow up the libsass upstream: 3.4.8 β see the release notes of LibSass 3.4.8 at
https://github.com/sass/libsass/releases/tag/3.4.8. [228https://github.com/sass/libsass-python/issues/228by Anthony Sottile]
π Version 0.13.4
Released on November 14, 2017.
- Follow up the libsass upstream: 3.4.7 β see the release notes of LibSass 3.4.7 at
https://github.com/sass/libsass/releases/tag/3.4.7. [226https://github.com/sass/libsass-python/issues/226by Anthony Sottile]
π Version 0.13.3
Released on October 11, 2017.
- Sort input files for determinism, we love a predictable queen β¨ [212
https://github.com/sass/libsass-python/issues/212by Bernhard M. Wiedemann] - Include the
LICENSEfile in distributions π [216https://github.com/sass/libsass-python/issues/216by Dougal J. Sutherland] - Add a
pysasscentry to replacesassc[218https://github.com/sass/libsass-python/issues/218by Anthony Sottile] - Enable building with dynamic linking π [219
https://github.com/sass/libsass-python/issues/219by Marcel Plch] - Follow up the libsass upstream: 3.4.6 β see the release notes of LibSass 3.4.6 at
https://github.com/sass/libsass/releases/tag/3.4.6. [221https://github.com/sass/libsass-python/issues/221by Anthony Sottile]
π Version 0.13.2
Released on June 14, 2017.
- Always add
cwdto import paths π [208https://github.com/sass/libsass-python/issues/208by Anthony Sottile]
π Version 0.13.1
Released on June 8, 2017.
- Follow up the libsass upstream: 3.4.5 β see the release notes of LibSass 3.4.5 at
https://github.com/sass/libsass/releases/tag/3.4.5. [207https://github.com/sass/libsass-python/issues/207by Anthony Sottile]
π Version 0.13.0
Released on June 7, 2017.
- Use
getfullargspecwhen it's available in python 3 π [188https://github.com/sass/libsass-python/issues/188by Thom Wiggers] - Use
sass_copy_c_stringinstead ofstrdupfor portability [196https://github.com/sass/libsass-python/issues/196by Anthony Sottile] - Use
-std=gnu++0xto fix installation under cygwin [195https://github.com/sass/libsass-python/issues/195197https://github.com/sass/libsass-python/issues/197by Anthony Sottile] - Correct the source map url, details matter π
[201
https://github.com/sass/libsass-python/issues/201202https://github.com/sass/libsass-python/issues/202by Anthony Sottile] - Removed
--watchπ [203https://github.com/sass/libsass-python/issues/203by Anthony Sottile] - Follow up the libsass upstream: 3.4.4 β see the release notes of LibSass 3.4.4 at
https://github.com/sass/libsass/releases/tag/3.4.4. [205https://github.com/sass/libsass-python/issues/205by Anthony Sottile]
π Version 0.12.3
Released on January 7, 2017.
- Follow up the libsass upstream: 3.4.3 β see the release notes of LibSass 3.4.3 at
https://github.com/sass/libsass/releases/tag/3.4.3. [178https://github.com/sass/libsass-python/issues/178by Anthony Sottile]
π Version 0.12.2
Released on January 5, 2017.
- Follow up the libsass upstream: 3.4.2 β see the release notes of LibSass 3.4.2 at
https://github.com/sass/libsass/releases/tag/3.4.2. [176https://github.com/sass/libsass-python/issues/176by Anthony Sottile]
π Version 0.12.1
Released on December 20, 2016.
- Follow up the libsass upstream: 3.4.1 β see the release notes of LibSass 3.4.1 at
https://github.com/sass/libsass/releases/tag/3.4.1. [175https://github.com/sass/libsass-python/issues/175by Anthony Sottile]
π Version 0.12.0
Released on December 10, 2016.
- Follow up the libsass upstream: 3.4.0 β see the release notes of LibSass 3.4.0 at
https://github.com/sass/libsass/releases/tag/3.4.0. [173https://github.com/sass/libsass-python/issues/173by Anthony Sottile]
π Version 0.11.2
Released on October 24, 2016.
- Dropped support for python2.6 π [158
https://github.com/sass/libsass-python/issues/158by Anthony Sottile] - Deprecated
--watch, giving y'all a heads up bestie [156https://github.com/sass/libsass-python/issues/156by Anthony Sottile] - Preserve line endings, respect the whitespace π«Ά [160
https://github.com/sass/libsass-python/issues/160by Anthony Sottile] - Follow up the libsass upstream: 3.3.6 β see the release notes of LibSass 3.3.6 at
https://github.com/sass/libsass/releases/tag/3.3.6. [167https://github.com/sass/libsass-python/issues/167by Anthony Sottile]
π Version 0.11.1
Released on April 22, 2016.
- Follow up the libsass upstream: 3.3.5 β see the release notes of LibSass 3.3.5 at
https://github.com/sass/libsass/releases/tag/3.3.5. [148https://github.com/sass/libsass-python/issues/148by Anthony Sottile]
π Version 0.11.0
Released on March 23, 2016.
- Follow up the libsass upstream: 3.3.4 β see the release notes of LibSass 3.3.4 at
https://github.com/sass/libsass/releases/tag/3.3.4. [144https://github.com/sass/libsass-python/issues/144by Anthony Sottile] - Not me exposing the libsass version in
sassc --versionand insass.libsass_versionπ [142 <https://github.com/sass/libsass-python/issues/142> 141 <https://github.com/sass/libsass-python/issues/141> 140 <https://github.com/sass/libsass-python/issues/140> by Anthony Sottile] - Fixed the warning about an unused enum on switch π«ΆοΈ [127 <https://github.com/sass/libsass-python/issues/127> 131 <https://github.com/sass/libsass-python/issues/131> by Anthony Sottile]
- Sourcemaps no longer imply source comments, bestie πΊοΈ [124 <https://github.com/sass/libsass-python/issues/124> 130 <https://github.com/sass/libsass-python/issues/130> by Tim Tisdall]
- Added the
--source-commentsoption tosassc⨠[124 <https://github.com/sass/libsass-python/issues/124> 130 <https://github.com/sass/libsass-python/issues/130> by Anthony Sottile] - Made the formatting of
CompileErrorway nicer under python3 π [123 <https://github.com/sass/libsass-python/issues/123> by Anthony Sottile] - Now it raises when you compile a directory which does not exist π¨ (as it should, fr fr) [116 <https://github.com/sass/libsass-python/issues/116> 119 <https://github.com/sass/libsass-python/issues/119> by Anthony Sottile]
Version 0.10.1
Released on January 29, 2016.
- Followed up the libsass upstream to 3.3.3 β see the release notes of LibSass 3.3.3 <https://github.com/sass/libsass/releases/tag/3.3.3> β¨ [by Anthony Sottile]
- Allowed
-tfor style, likesasscdoes π [98 <https://github.com/sass/libsass-python/issues/98> by Anthony Sottile]
Version 0.10.0
Released on December 15, 2015.
- Support for custom import callbacks, let's gooo π [81 <https://github.com/sass/libsass-python/issues/81> by Alice ZoΓ« BevanβMcGregor, Anthony Sottile]
- Disallowed arbitrary kwargs in
compile()β no sneaking extra stuff in there π [109 <https://github.com/sass/libsass-python/issues/109> by Anthony Sottile]
Version 0.9.3
Released on December 03, 2015.
- Support for "indented" Sass compilation πΈ [41 <https://github.com/sass/libsass-python/issues/41> by Alice ZoΓ« BevanβMcGregor]
- Fixed the wheels on windows π¦ [28 <https://github.com/sass/libsass-python/issues/28> 49 <https://github.com/sass/libsass-python/issues/49> by Anthony Sottile]
Version 0.9.2
Released on November 12, 2015.
- Followed up the libsass upstream to 3.3.2 β see the release notes of LibSass 3.3.2 <https://github.com/sass/libsass/releases/tag/3.3.2> β¨ [by Anthony Sottile]
- Now requires VS 2015 to build on windows π€ [99 <https://github.com/sass/libsass-python/issues/99> by Anthony Sottile]
Version 0.9.1
Released on October 29, 2015.
- Followed up the libsass upstream to 3.3.1 β see the release notes of LibSass 3.3.1 <https://github.com/sass/libsass/releases/tag/3.3.1> β¨ [by Anthony Sottile]
Version 0.9.0
Released on October 28, 2015.
- Fixed a bug with writing UTF-8 to a file π [72 <https://github.com/sass/libsass-python/issues/72> by Caleb Ely]
- Fixed a segmentation fault on ^C π [87 <https://github.com/sass/libsass-python/issues/87> by Anthony Sottile]
- Followed up the libsass upstream to 3.3.0 β see the release notes of LibSass 3.3.0 <https://github.com/sass/libsass/releases/tag/3.3.0> β¨ [96 <https://github.com/sass/libsass-python/issues/96> by Anthony Sottile]
Version 0.8.3
Released on August 2, 2015.
- Followed up the libsass upstream to 3.2.5 β see the release notes of LibSass 3.2.5 <https://github.com/sass/libsass/releases/tag/3.2.5> β¨ [79 <https://github.com/sass/libsass-python/issues/79>, 80 <https://github.com/sass/libsass-python/issues/80> by Anthony Sottile]
- Fixed a bug that
*.sassfiles were ignored π [78 <https://github.com/sass/libsass-python/issues/78> by Guilhem MAS-PAITRAULT]
Version 0.8.2
Released on May 19, 2015.
- Followed up the libsass upstream to 3.2.4 β see the release notes of LibSass 3.2.3 <https://github.com/sass/libsass/releases/tag/3.2.3>, and 3.2.4 <https://github.com/sass/libsass/releases/tag/3.2.4> β¨ [69 <https://github.com/sass/libsass-python/issues/69> by Anthony Sottile]
- The default value of
SassMiddleware'serror_statusparameter was changed from'500 Internal Server Error'to'200 OK'so that Mozilla Firefox can render the error message well π¦ [67 <https://github.com/sass/libsass-python/issues/67>, 68 <https://github.com/sass/libsass-python/issues/68>, 70 <https://github.com/sass/libsass-python/issues/70> by zxv]
Version 0.8.1
Released on May 14, 2015.
- Fixed a bug that there was no
'expanded'insass.OUTPUT_STYLESbut'expected'instead, which is a typo π (iconic honestly) [66 <https://github.com/sass/libsass-python/issues/66> by Triangle717] - Fixed the broken FreeBSD build π οΈ [65 <https://github.com/sass/libsass-python/issues/65> by Toshiharu Moriyama]
Version 0.8.0
Released on May 3, 2015.
- Followed up the libsass upstream to 3.2.2 β see the release notes of LibSass 3.2.0 <https://github.com/sass/libsass/releases/tag/3.2.0>, 3.2.1 <https://github.com/sass/libsass/releases/tag/3.2.1>, and 3.2.2 <https://github.com/sass/libsass/releases/tag/3.2.2> β¨ [61 <https://github.com/sass/libsass-python/issues/61>, 52 <https://github.com/sass/libsass-python/issues/52>, 56 <https://github.com/sass/libsass-python/issues/56>, 58 <https://github.com/sass/libsass-python/issues/58>, 62 <https://github.com/sass/libsass-python/issues/62>, 64 <https://github.com/sass/libsass-python/issues/64> by Anthony Sottile]
- Compact and expanded output styles π [37 <https://github.com/sass/libsass-python/issues/37>]
- Strings and interpolation closer to Ruby Sass π
- The correctness of the generated sourcemap files πΊοΈ
- Directive buddling (yes, that's how it's spelled in the notes β we keep it exactly like that) π
- Full support for the
@at-rootdirective π - Full support for
!globalvariable scoping β
- Now underscored files are ignored when compiling a directory π ββοΈ [57 <https://github.com/sass/libsass-python/issues/57> by Anthony Sottile]
- Fixed the broken FreeBSD build π οΈ [34 <https://github.com/sass/libsass-python/issues/34>, 60 <https://github.com/sass/libsass-python/issues/60> by Ilya Baryshev]
SassMiddlewarenow logs syntax errors, if they exist during compilation, to thesassutils.wsgi.SassMiddlewarelogger with levelERRORπ [42 <https://github.com/sass/libsass-python/issues/42>]
Version 0.7.0
Released on March 6, 2015.
Anthony Sottile contributed to the most of this release. Huge thanks to him! ππ
- Followed up the libsass upstream to 3.1.0 β see the release note <https://github.com/sass/libsass/releases/tag/3.1.0> of LibSass β¨ [38 <https://github.com/sass/libsass-python/issues/38>, 43 <https://github.com/sass/libsass-python/issues/43> by Anthony Sottile]
- Custom functions and imports π
- Decrementing in
@forloops π @debugand@errorπnotoperator π«nth()for maps πΊοΈinspect()πfeature-exists()βunique-id()πrandom()π²
- Added custom functions support π
[13 <https://github.com/sass/libsass-python/issues/13>, 44 <https://github.com/sass/libsass-python/issues/44> by Anthony Sottile]
- Added the
sass.SassFunctionclass β¨ - Added the
custom_functionsparameter to thesass.compile()function π οΈ - Added data types for custom functions:
sass.SassNumbersass.SassColorsass.SassListsass.SassMapsass.SassErrorsass.SassWarning
- Added the
- Added the
precisionparameter to thesass.compile()function π― [39 <https://github.com/sass/libsass-python/issues/39> by Andrea Stagi] sasschas a new-p/--precisionoption π― [39 <https://github.com/sass/libsass-python/issues/39> by Andrea Stagi]
Version 0.6.2
Released on November 25, 2014.
Although 0.6.0--0.6.1 have needed GCC (G++) 4.8+, LLVM Clang 3.3+, now it became back to only need GCC (G++) 4.6+, LLVM Clang 2.9+, or Visual Studio 2013 Update 4+. π§
- Followed up the libsass upstream to 3.0.2 β see the release note <https://github.com/sass/libsass/releases/tag/3.0.2> of libsass β¨ [33 <https://github.com/sass/libsass-python/issues/33> by Rodolphe Pelloux-Prayer]
- Fixed a bug that
sassc --watchcrashed when a file is not compilable on the first try π [32 <https://github.com/sass/libsass-python/issues/32> by Alan Justino da Silva] - Fixed the broken build on Windows π οΈ
Version 0.6.1
Released on November 6, 2014.
- Followed up the libsass upstream to 3.0.1 β see the release note <https://github.com/sass/libsass/releases/tag/3.0.1> of LibSass β¨
- Fixed a bug that
SassMiddlewarenever closes the socket on some WSGI servers, e.g.eventlet.wsgiπ
Version 0.6.0
Released on October 27, 2014.
Note that since libsass-python 0.6.0 (and libsass 3.0) it requires C++11 to compile. Although 0.6.2 became back to only need GCC (G++) 4.6+, LLVM Clang 2.9+, from 0.6.0 to 0.6.1 you need GCC (G++) 4.8+, LLVM Clang 3.3+, or Visual Studio 2013 Update 4+. β οΈ
- Followed up the libsass upstream to 3.0 β see the release note <https://github.com/sass/libsass/releases/tag/3.0> of LibSass β¨
- Decent extends support π§¬
- Basic Sass Maps Support πΊοΈ
- Better UTF-8 Support π
call()function π- Better Windows Support πͺ
- Spec Enhancements π
- Added the missing partial import <https://sass-lang.com/documentation/file.SASS_REFERENCE.html#partials> support π§© [27 <https://github.com/sass/libsass-python/issues/27> by item4]
SOURCE_COMMENTSbecame deprecated π’sass.compile()'s parametersource_commentsnow can take onlyboolinstead ofstr. String values like'none','line_numbers', and'map'become deprecated, and will be obsolete soon π¨build_directory()function has a new optional parameteroutput_styleπ οΈbuild()method has a new optional parameteroutput_styleπ οΈ- Added the
--output-style/-soption to thebuild_sasscommand π [25 <https://github.com/sass/libsass-python/issues/25>]
Version 0.5.1
Released on September 23, 2014.
- Fixed a bug that
SassMiddlewareyieldedstr</usr/share/doc/python3-doc/html/library/stdtypes.html#str> instead ofbytes</usr/share/doc/python3-doc/html/library/stdtypes.html#bytes> on Python 3 π - Fixed several Unicode-related bugs on Windows π
- Fixed a bug that
build_directory(),SassMiddleware, andbuild_sassdon't recursively build subdirectories. π
Version 0.5.0 π
Released on June 6, 2014.
- Followed up on the libsass upstream, and bestie the upstream was at 2.0 β go peek at the release note (
https://github.com/sass/libsass/releases/tag/v2.0) for LibSass if you want the receipts π- Added indented syntax support (
*.sassfiles). yes, the other flavor β¨ - Added expanded selector support (BEM).
- Added string functions.
- Fixed UTF-8 support. π
- β οΈ Backward incompatibility: broken extends. not us being dramatic, that's literally what it says, watch out π«
- Added indented syntax support (
Unstable version 0.4.2.20140529.cd3ee1cbe3
Released on May 29, 2014.
- Version scheme changed to use periods (
.) instead of hyphens (-) because setuptools seems to treat hyphens special. it's giving "blame setuptools" energy and honestly valid π - Fixed malformed packaging that doesn't correctly preserve the package name and version.
Unstable Version 0.4.2-20140528-cd3ee1cbe3
Released on May 28, 2014.
- Followed up on the libsass upstream:
cd3ee1cbe34d5316eb762a43127a3de9575454ee(https://github.com/sass/libsass/commit/cd3ee1cbe34d5316eb762a43127a3de9575454ee).
Version 0.4.2
Released on May 22, 2014.
- Fixed build failing on Mac OS X 10.8 or earlier. [19 (
https://github.com/sass/libsass-python/issues/19)] - Fixed the
UnicodeEncodeError(/usr/share/doc/python3-doc/html/library/exceptions.html#UnicodeEncodeError) that theManifest.build_one()method rises when the input source contains any non-ASCII Unicode characters. π
Version 0.4.1
Released on May 20, 2014.
- Fixed the
UnicodeEncodeError(/usr/share/doc/python3-doc/html/library/exceptions.html#UnicodeEncodeError) that rises when the input source contains any non-ASCII Unicode characters.
Version 0.4.0
Released on May 6, 2014.
sasschas a new-w/--watchoption. π- Exposed source maps support, and this is the part where we eat π
sasschas a new-m/-g/--sourcemapoption.SassMiddlewarenow also creates source map files with filenames followed by a.mapsuffix.- The
Manifest.build_one()method has a newsource_mapoption. This option builds also a source map file with the filename followed by a.mapsuffix. sass.compile()has a new optional parametersource_comments. It can be one of thesass.SOURCE_COMMENTSkeys. It also has a new parametersource_map_filenamewhich is required only whensource_comments='map'.
- Fixed Python 3 incompatibility of the
sasscprogram. - Fixed a bug that multiple
include_pathsdoesn't work on Windows.
Version 0.3.0
Released on February 21, 2014.
- Added support for Python 3.3. [7 (
https://github.com/sass/libsass-python/issues/7)] - Dropped support for Python 2.5. bye bestie βοΈ
- Fixed build failing on Mac OS X. [4 (
https://github.com/sass/libsass-python/issues/4), 5 (https://github.com/sass/libsass-python/issues/5), 6 (https://github.com/sass/libsass-python/issues/6) by Hyungoo Kang] - Now the builder creates target subdirectories recursively even if they don't exist yet, rather than silently failing. π [8 (
https://github.com/sass/libsass-python/issues/8), 9 (https://github.com/sass/libsass-python/issues/9) by Philipp Volguine] - Merged recent changes from libsass 1.0.1:
57a2f62--v1.0.1(https://github.com/sass/libsass/compare/57a2f627b4d2fbd3cf1913b241f1d5aa31e35580...v1.0.1).- Supports variable arguments (
https://sass-lang.com/docs/yardoc/file.SASS_CHANGELOG.html#variable_arguments). - Supports sourcemaps.
- Supports variable arguments (
Version 0.2.4
Released on December 4, 2012.
- Added the
sasscCLI executable script. - Added the
sass.OUTPUT_STYLESconstant map. - Merged recent changes from the libsass upstream:
e997102--a84b181(https://github.com/sass/libsass/compare/e9971023785dabd41aa44f431f603f62b15e6017...a84b181a6e59463c0ac9796ca7fdaf4864f0ad84).
Version 0.2.3
Released on October 24, 2012.
sassutils.distutils: prevent double monkey patch of sdist. π- Merged upstream changes of libsass.
Version 0.2.2
Released on September 28, 2012.
- Fixed a link error on PyPy and Linux.
- Fixed build errors on Windows.
Version 0.2.1
Released on September 12, 2012.
- Support Windows. πͺ
Version 0.2.0
Released on August 24, 2012.
- Added the new
sassutilspackage.- Added the
sassutils.buildermodule to build the whole directory at a time. - Added the
sassutils.distutilsmodule fordistutilsand setuptools integration. - Added the
sassutils.wsgimodule which provides a development-purpose WSGI middleware.
- Added the
- Added the
build_sasscommand fordistutils/setuptools.
Version 0.1.1
Released on August 18, 2012.
- Fixed segmentation fault for reading a filename which does not exist. Now it raises a proper
exceptions.IOErrorexception instead of, you know, dying π
Version 0.1.0
Released on August 17, 2012. Initial version. the origin story π¬
β¨ REFERENCES β¨
π pysassc --- SassC compliant command line interface
This provides a SassC (https://github.com/sass/sassc) compliant CLI executable named pysassc:
$ pysassc
Usage: pysassc [options] SCSS_FILE [CSS_FILE]
There are options as well, bestie, here's the whole menu:
-t <style>,--style <style>β Coding style of the compiled result. The same as thesass.compile()function'soutput_stylekeyword argument. Default isnested.-s <style>,--output-style <style>β Alias for-t/--style.
Deprecated since version 0.11.0.
-I <dir>,--include-path <dir>β Optional directory path to find@imported (S)CSS files. Can be multiply used. stack them up π₯-m,-g,--sourcemapβ Emit source map. Requires the second argument (output CSS filename). The filename of source map will be the output CSS filename followed by.map.
Added in version 0.4.0.
-p,--precisionβ Set the precision for numbers. Default is5.
Added in version 0.7.0.
--source-commentsβ Include debug info in output.
Added in version 0.11.0.
--sourcemap-fileβ Output file for source map
Added in version 0.17.0.
--sourcemap-contentsβ EmbedsourcesContentin source map.
Added in version 0.17.0.
--sourcemap-embedβ EmbedsourceMappingUrlas data URI
Added in version 0.17.0.
--omit-sourcemap-urlβ Omit source map URL comment from output
Added in version 0.17.0.
--sourcemap-rootβ Base path, will be emitted tosourceRootin source-map as is
Added in version 0.17.0.
-v,--versionβ Prints the program version.-h,--helpβ Prints the help message.
π¦ sass --- Binding of libsass
This simple C extension module provides a very simple binding of libsass, which is written in C/C++. It contains only one function and one exception type. minimal. iconic. π
>>> import sass
>>> sass.compile(string='a { b { color: blue; } }')
'a b {
color: blue; }
'
exception sass.CompileError(msg)β The exception type that is raised bycompile(). It is a subtype ofexceptions.ValueError.sass.MODES = frozenset({'dirname', 'filename', 'string'})β (frozenset:/usr/share/doc/python3-doc/html/library/stdtypes.html#frozenset) The set of keywordscompile()can take.sass.OUTPUT_STYLES = {'compact': 2, 'compressed': 3, 'expanded': 1, 'nested': 0}β (collections.abc.Mapping:/usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Mapping) The dictionary of output styles. Keys are output name strings, and values are flag integers.sass.SOURCE_COMMENTS = {'default': 1, 'line_numbers': 1, 'map': 2, 'none': 0}β (collections.abc.Mapping:/usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Mapping) The dictionary of source comments styles. Keys are mode names, and values are corresponding flag integers.
Added in version 0.4.0. Deprecated since version 0.6.0. π’
class sass.SassColor(r, g, b, a)class sass.SassError(msg)class sass.SassFunction(name, arguments, callable_)β Custom function for Sass. It can be instantiated usingfrom_lambda()andfrom_named_function()as well.
Parameters
- name (
str:/usr/share/doc/python3-doc/html/library/stdtypes.html#str) -- the function name - arguments (
collections.abc.Sequence:/usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Sequence) -- the argument names - callable (
collections.abc.Callable:/usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Callable) -- the actual function to be called
Added in version 0.7.0.
classmethod from_lambda(name, lambda_)β Make aSassFunctionobject from the given lambda_ function. Since lambda functions don't have their name, it need its name as well. Arguments are automatically inspected.
Parameters
- name (
str:/usr/share/doc/python3-doc/html/library/stdtypes.html#str) -- the function name - lambda (
types.LambdaType:/usr/share/doc/python3-doc/html/library/types.html#types.LambdaType) -- the actual lambda function to be called
Returns a custom function wrapper of the lambda_ function
Return type SassFunction
classmethod from_named_function(function)β Make aSassFunctionobject from the named function. Function name and arguments are automatically inspected.
Parameters
- function (
types.FunctionType:/usr/share/doc/python3-doc/html/library/types.html#types.FunctionType) -- the named function to be called
Returns a custom function wrapper of the function
- Return type β
SassFunction</p> - property signature β the signature string of the function π
πΈ class sass.SassList(items, separator, bracketed=False)
πΈ class sass.SassMap(*args, **kwargs)
ok so here's the tea β because sass maps can have mapping types as keys, we need an immutable hashable mapping type. no cap.
Added in version 0.7.0. π
πΈ class sass.SassNumber(value, unit)
πΈ class sass.SassWarning(msg)
β¨ sass.and_join(strings)
Bestie, this one just joins the given strings by commas, with a last ' and ' conjunction. it's giving polite list energy π₯°
>>> and_join(['Korea', 'Japan', 'China', 'Taiwan'])
'Korea, Japan, China, and Taiwan'
Parameters
stringsβ a list of words to join
Returns
- a joined string
Return type
str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>,basestring
π sass.compile(**kwargs)
Okay so compile() is literally the main character here. β¨ There are three modes of parameters compile() can take: string, filename, and dirname. Three whole vibes, pick your fighter. π
π¦ the string mode
The string parameter is the most basic way to compile Sass. It simply takes a string of Sass code, and then returns a compiled CSS string. Simple, iconic, no notes. π
Parameters
string(str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β Sass source code to compile. it's exclusive tofilenameanddirnameparametersoutput_style(str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β an optional coding style of the compiled result. choose one of:'nested'(default),'expanded','compact','compressed'source_comments(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β whether to add comments about source lines.Falseby defaultsource_map_contents(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β embed include contents in mapsource_map_embed(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β embedsourceMappingUrlas data URIomit_source_map_url(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β omit source map URL comment from outputsource_map_root(str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β base path, will be emitted in source map as isinclude_paths(collections.abc.Sequence </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Sequence>) β an optional list of paths to find@imported Sass/CSS source filesprecision(int </usr/share/doc/python3-doc/html/library/functions.html#int>) β optional precision for numbers.5by default.custom_functions(set </usr/share/doc/python3-doc/html/library/stdtypes.html#set>,collections.abc.Sequence </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Sequence>,collections.abc.Mapping </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Mapping>) β optional mapping of custom functions. see also below custom functions descriptioncustom_import_extensionsβ (ignored, for backward compatibility) πindented(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β optional declaration that the string is Sass, not SCSS formatted.Falseby defaultimporters(collections.abc.Callable </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Callable>) β optional callback functions. see also below importer callbacks description
Returns
- the compiled CSS string
Return type
str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>
Raises
sass.CompileError <#sass.CompileError>β when it fails for any reason (for example the given Sass has broken syntax) π
π¦ the filename mode
The filename is the most commonly used way. It takes a string of Sass filename, and then returns a compiled CSS string. it's the one everybody reaches for fr fr. π₯
Parameters
filename(str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β the filename of Sass source code to compile. it's exclusive tostringanddirnameparametersoutput_style(str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β an optional coding style of the compiled result. choose one of:'nested'(default),'expanded','compact','compressed'source_comments(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β whether to add comments about source lines.Falseby defaultsource_map_filename(str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β use source maps and indicate the source map output filename.Nonemeans not using source maps.Noneby default.source_map_contents(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β embed include contents in mapsource_map_embed(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β embedsourceMappingUrlas data URIomit_source_map_url(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β omit source map URL comment from outputsource_map_root(str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β base path, will be emitted in source map as isinclude_paths(collections.abc.Sequence </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Sequence>) β an optional list of paths to find@imported Sass/CSS source filesprecision(int </usr/share/doc/python3-doc/html/library/functions.html#int>) β optional precision for numbers.5by default.custom_functions(set </usr/share/doc/python3-doc/html/library/stdtypes.html#set>,collections.abc.Sequence </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Sequence>,collections.abc.Mapping </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Mapping>) β
optional mapping of custom functions. see also below custom functions description
custom_import_extensionsβ (ignored, for backward compatibility) πimporters(collections.abc.Callable </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Callable>) β
optional callback functions. see also below importer callbacks description
Returns
- the compiled CSS string, or a pair of the compiled CSS string and the source map string if
source_map_filenameis set
Return type
str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>,tuple </usr/share/doc/python3-doc/html/library/stdtypes.html#tuple>
Raises
sass.CompileError <#sass.CompileError>β when it fails for any reason (for example the given Sass has broken syntax) πexceptions.IOErrorβ when the filename doesn't exist or cannot be read
π¦ the dirname mode
The dirname is useful for automation. π€ It takes a pair of paths. The first of the dirname pair refers the source directory, contains several Sass source files to compiled. Sass source files can be nested in directories. The second of the pair refers the output directory that compiled CSS files would be saved. Directory tree structure of the source directory will be maintained in the output directory as well. If dirname parameter is used the function returns None.
Parameters
dirname(tuple </usr/share/doc/python3-doc/html/library/stdtypes.html#tuple>) β a pair of(source_dir, output_dir). it's exclusive tostringandfilenameparametersoutput_style(str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β an optional coding style of the compiled result. choose one of:'nested'(default),'expanded','compact','compressed'source_comments(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β whether to add comments about source lines.Falseby defaultsource_map_contents(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β embed include contents in mapsource_map_embed(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β embedsourceMappingUrlas data URIomit_source_map_url(bool </usr/share/doc/python3-doc/html/library/functions.html#bool>) β omit source map URL comment from outputsource_map_root(str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β base path, will be emitted in source map as isinclude_paths(collections.abc.Sequence </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Sequence>) β an optional list of paths to find@imported Sass/CSS source filesprecision(int) β optional precision for numbers. it's5by default. β¨custom_functions(set,collections.abc.Sequence,collections.abc.Mapping) β an optional mapping of custom functions. see also the custom functions description further down, bestie πcustom_import_extensionsβ (ignored, kept around for backward compatibility) π
Raises sass.CompileError β when it fails for any reason (for example, the Sass you handed it has broken syntax). π
The custom_functions parameter can take three types of forms:
set </usr/share/doc/python3-doc/html/library/stdtypes.html#set> / Sequence </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Sequence> of SassFunctions β it's the most general form. lowkey verbose, but it can take any kind of callables like type objects, unnamed functions, and user-defined callables.
sass.compile(
...,
custom_functions={
sass.SassFunction('func-name', ('$a', '$b'), some_callable),
...
}
)
Mapping </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Mapping> of names to functions β less general, but it's the easier-to-use form. it's not that it can take any kind of callables β it can take any kind of functions defined using def </usr/share/doc/python3-doc/html/reference/compound_stmts.html#def> / lambda </usr/share/doc/python3-doc/html/reference/expressions.html#lambda> syntax. It cannot take callables other than those, because inspecting arguments is not always available for every kind of callable.
sass.compile(
...,
custom_functions={
'func-name': lambda a, b: ...,
...
}
)
set </usr/share/doc/python3-doc/html/library/stdtypes.html#set> / Sequence </usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Sequence> of named functions β not general, but it's the easiest-to-use form for named functions. It can take only named functions, defined using def </usr/share/doc/python3-doc/html/reference/compound_stmts.html#def>. It cannot take lambdas since names are unavailable for them. π
def func_name(a, b):
return ...
sass.compile(
...,
custom_functions={func_name}
)
Newer versions of libsass let developers define callbacks that get called and get a chance to process @import directives. you define yours by passing in a list of callables via the importers parameter. the callables must be passed as 2-tuples in the form:
(priority_int, callback_fn)
A priority of zero is totally acceptable; priority determines the order the callbacks are attempted. π₯
These callbacks can accept one or two string arguments. The first argument is the path that was passed to the @import directive; the second (optional) argument is the previous resolved path, where the @import directive was found. The callbacks must either return None to indicate the path wasn't handled by that callback (so it continues with the others or falls back on internal libsass filesystem behaviour) or a list of one or more tuples, each in one of three forms:
- A 1-tuple representing an alternate path to handle internally; or,
- A 2-tuple representing an alternate path and the content that path represents; or,
- A 3-tuple representing the same as the 2-tuple with the addition of a "sourcemap".
All tuple return values must be strings. as a not-overly-realistic example:
def my_importer(path, prev):
return [(path, '#' + path + ' { color: red; }')]
sass.compile(
...,
importers=[(0, my_importer)]
)
Now, within the style source, attempting to @import 'button'; will instead attach color: red as a property of an element with the imported name. π
- Added in version 0.4.0: added
source_commentsandsource_map_filenameparameters. - Changed in version 0.6.0: the
source_commentsparameter becomes to take onlybool</usr/share/doc/python3-doc/html/library/functions.html#bool>instead ofstr</usr/share/doc/python3-doc/html/library/stdtypes.html#str>. - Deprecated since version 0.6.0: values like
'none','line_numbers', and'map'for thesource_commentsparameter are deprecated. π - Added in version 0.7.0: added
precisionparameter. - Added in version 0.7.0: added
custom_functionsparameter. - Added in version 0.11.0:
source_map_filenameno longer impliessource_comments. - Added in version 0.17.0: added
source_map_contents,source_map_embed,omit_source_map_url, andsource_map_rootparameters. - Added in version 0.18.0: the importer callbacks can now take a second argument, the previously-resolved path, so that importers can do relative path resolution. β¨
π§° sassutils β Additional utilities related to Sass
This package provides several additional utilities related to Sass which depends on libsass core (the sass </usr/share/doc/python3-doc/html/library/#module-sass> module). π«Ά
ποΈ sassutils.builder β Build the whole directory
class sassutils.builder.Manifest(sass_path, css_path=None, wsgi_path=None, strip_extension=None)
Building manifest of Sass/SCSS. π
Parameters
sass_path(str</usr/share/doc/python3-doc/html/library/stdtypes.html#str>,basestring) β the path of the directory that contains Sass/SCSS source files πcss_path(str</usr/share/doc/python3-doc/html/library/stdtypes.html#str>,basestring) β the path of the directory to store compiled CSS filesstrip_extension(bool</usr/share/doc/python3-doc/html/library/functions.html#bool>) β whether to remove the original file extension βοΈ
build(package_dir, output_style='nested')
Builds the Sass/SCSS files in the specified sass_path. It finds sass_path and locates css_path as relative to the given package_dir.
Parameters
package_dir(str</usr/share/doc/python3-doc/html/library/stdtypes.html#str>,basestring) β the path of package directoryoutput_style(str</usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β an optional coding style of the compiled result. choose one of:'nested'(default),'expanded','compact','compressed'π
Returns the set of compiled CSS filenames
Return type frozenset </usr/share/doc/python3-doc/html/library/stdtypes.html#frozenset>
Added in version 0.6.0: the output_style parameter.
build_one(package_dir, filename, source_map=False)
Builds one Sass/SCSS file. π¦
Parameters
package_dir(str</usr/share/doc/python3-doc/html/library/stdtypes.html#str>,basestring) β the path of package directoryfilename(str</usr/share/doc/python3-doc/html/library/stdtypes.html#str>,basestring) β the filename of Sass/SCSS source to compilesource_map(bool</usr/share/doc/python3-doc/html/library/functions.html#bool>) β whether to use source maps. ifTrueit also write a source map to a filename followed by.mapsuffix. default isFalse
Returns the filename of compiled CSS
Return type str </usr/share/doc/python3-doc/html/library/stdtypes.html#str>, basestring
Added in version 0.4.0: added optional source_map parameter.
resolve_filename(package_dir, filename)
Gets a proper full relative path of Sass source and CSS source that will be generated, according to package_dir and filename. πΊοΈ
Parameters
package_dir(str</usr/share/doc/python3-doc/html/library/stdtypes.html#str>,basestring) β the path of package directoryfilename(str</usr/share/doc/python3-doc/html/library/stdtypes.html#str>,basestring) β the filename of Sass/SCSS source to compile
Returns a pair of (sass, css) path
Return type tuple </usr/share/doc/python3-doc/html/library/stdtypes.html#tuple>
unresolve_filename(package_dir, filename)
Retrieves the probable source path from the output filename. Pass in a .css path to get out a .scss path. π
Parameters
package_dir(str</usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β the path of the package directoryfilename(str</usr/share/doc/python3-doc/html/library/stdtypes.html#str>) β the css filename
Returns β the scss filename, bestie π
Return type β str (the whole lore lives at /usr/share/doc/python3-doc/html/library/stdtypes.html#str)
sassutils.builder.SUFFIXES=frozenset({'sass', 'scss'})β afrozenset(peep/usr/share/doc/python3-doc/html/library/stdtypes.html#frozensetfor the deets) holding the set of supported filename suffixes. It's giving the approved guest list πsassutils.builder.SUFFIX_PATTERN=re.compile('[.](sass|scss)$')β there.RegexObjectregular expression pattern that matches the filenames inSUFFIXES. Lowkey a vibe check for file extensions β¨sassutils.builder.build_directory(sass_path, css_path, output_style='nested', _root_sass=None, _root_css=None, strip_extension=False)β compiles all Sass/SCSS files in a path to CSS. Main character behaviour, fr fr.
sassutils.builder.build_directory(sass_path, css_path, output_style='nested', _root_sass=None, _root_css=None, strip_extension=False)
Parameters
sass_path(str,basestring) β the path of the directory which contains source files to compile πΈcss_path(str,basestring) β the path of the directory where the compiled CSS files will go πoutput_style(str) β an optional coding style for the compiled result. choose one of:'nested'(default),'expanded','compact','compressed'π
Returns β a dictionary of source filenames to compiled CSS filenames π¦
Return type β collections.abc.Mapping (/usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Mapping)
Added in version 0.6.0 β the output_style parameter entered the chat β¨
π« sassutils.distutils β setuptools/distutils integration π«
This module provides extensions (and some magical monkey-patches, sorry π) of the standard distutils (/usr/share/doc/python3-doc/html/library/distutils.html#module-distutils) and setuptools (now it's named Distribute) for libsass.
To use this, add libsass into setup_requires (not install_requires β do not play yourself bestie) option of the setup.py script:
from setuptools import setup
setup(
# ...,
setup_requires=['libsass >= 0.6.0']
)
It will adds build_sass command to the setup.py script:
$ python setup.py build_sass
This commands builds Sass/SCSS files to compiled CSS files of the project, and makes the package archive (made by sdist, bdist, and so on) include these compiled CSS files. Iconic packaging moment π
To set the directory of Sass/SCSS source files and the directory to store compiled CSS files, specify sass_manifests option:
from setuptools import find_packages, setup
setup(
name='YourPackage',
packages=find_packages(),
sass_manifests={
'your.webapp': ('static/sass', 'static/css')
},
setup_requires=['libsass >= 0.6.0']
)
The option should be a mapping of package names to pairs of paths, e.g.:
{
'package': ('static/sass', 'static/css'),
'package.name': ('static/scss', 'static')
}
The option can also be a mapping of package names to manifest dictionaries:
{
'package': {
'sass_path': 'static/sass',
'css_path': 'static/css',
'strip_extension': True,
},
}
Added in version 0.15.0 β added strip_extension so a.scss is compiled to a.css instead of a.scss.css. no cap, this slays. This option will default to True in the future π
Added in version 0.6.0 β added --output-style/-s option to build_sass command π
class sassutils.distutils.build_sass(dist: Distribution, **kw)β builds Sass/SCSS files to CSS files. The whole point, honestly πfinalize_options()β set final values for all options/attributes used by the command. Most of the time, each option/attribute/cache should only be set if it does not have any value yet (e.g.if self.attr is None: self.attr = val). Respect the "only if it's empty" rule bestie β¨get_package_dir(package)β returns the directory, relative to the top of the source distribution, where package package should be found (at least according to thepackage_diroption, if any). Copied fromdistutils.command.build_py.get_package_dir()method. Yes it's a re-gift, it's still cute πinitialize_options()β set or (reset) all options/attributes/caches used by the command to their default values. Note that these values may be overwritten during the build. glow-up pending πΈrun()β execute the actions intended by the command. (Side effects SHOULD only take place whenrun()is executed, for example, creating new files or writing to the terminal output). So like, actually doing the thing? iconic π₯
sassutils.distutils.validate_manifests(dist, attr, value)β verifies that value is an expected mapping of package tosassutils.builder.Manifest(#sassutils.builder.Manifest). It's the bouncer at the door π«Ά
π sassutils.wsgi β WSGI middleware for development purpose π
class sassutils.wsgi.SassMiddleware(app, manifests, package_dir={}, error_status='200 OK')β WSGI middleware for development purpose. Every time a CSS file has requested it finds a matched Sass/SCSS source file and then compiled it into CSS. It's literally out here doing the most for you in dev πΈ
class sassutils.wsgi.SassMiddleware(app, manifests, package_dir={}, error_status='200 OK')
It shows syntax errors in three ways:
Heading comment β the result CSS includes the detailed error message in the heading CSS comment e.g.:
/*
Error: invalid property name
*/
Red text in body:before β the result CSS draws the detailed error message in the :before pseudo-class of the body element e.g.:
body:before {
content: 'Error: invalid property name';
color: maroon;
background-color: white;
}
In most cases you could be aware of syntax error by refreshing your working document because it will removes all other styles and leaves only a red text. dramatic much? but helpful π
logging (/usr/share/doc/python3-doc/html/library/logging.html#module-logging) β it logs syntax errors if exist during compilation to sassutils.wsgi.SassMiddleware logger with level ERROR.
To enable this:
from logging import Formatter, StreamHandler, getLogger
logger = getLogger('sassutils.wsgi.SassMiddleware')
handler = StreamHandler(level=logging.ERROR)
formatter = Formatter(fmt='*' * 80 + '\n%(message)s\n' + '*' * 80)
handler.setFormatter(formatter)
logger.addHandler(handler)
Or simply:
import logging
logging.basicConfig()
ngl the second one is the lazy-girl route and honestly? valid π
Parameters
app(collections.abc.Callableβ/usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Callable) β the WSGI application to wrap πmanifests(collections.abc.Mappingβ/usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Mapping) β build settings. the same format tosetup.pyscript'ssass_manifestsoption πpackage_dir(collections.abc.Mappingβ/usr/share/doc/python3-doc/html/library/collections.abc.html#collections.abc.Mapping) β optional mapping of package names to directories. the same format tosetup.pyscript'spackage_diroption β¨
Changed in version 0.4.0 β it creates also source map files with filenames followed by .map suffix πΊοΈ
Added in version 0.8.0 β it logs syntax errors if exist during compilation to sassutils.wsgi.SassMiddleware logger with level ERROR π₯
static quote_css_string(s)β quotes a string as CSS string literal π
π CREDIT π
Hong Minhee wrote this Python binding of LibSass (https://github.com/sass/libsass).
Hampton Catlin and Aaron Leung wrote LibSass (https://github.com/sass/libsass), which is portable C/C++ implementation of Sass (https://sass-lang.com/).
Hampton Catlin originally designed Sass (https://sass-lang.com/) language and wrote the first reference implementation of it in Ruby.
The above three are all distributed under MIT license (https://mit-license.org/). periodt π
π¦ OPEN SOURCE π¦
- GitHub (Git repository + issues) β
https://github.com/sass/libsass-python - GitHub Actions (linux + macos + windows) β
[image: Build Status] [image]βhttps://github.com/sass/libsass-python/actions/workflows/main.yml..UNINDENT - PyPI β
https://pypi.org/pypi/libsass/β[image: PyPI] [image]βhttps://pypi.org/pypi/libsass/..TP - Changelog β Changelog
<>
π INDICES AND TABLES π
- Index
<> - Module Index
<> - Search Page
<>
Author β Hong Minhee
Copyright β 2012, Hong Minhee
and that's a wrap on the whole page bestie, we ate and left no crumbs π β¨ this lil manual is 0.23.0, dated Sep 18, 2026, and it answers to the name LIBSASS(3) ππ¦π
π¦ where this page comes from
- ubuntu stonking: python3-libsass 0.23.0-0.3 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms