Skip to main content

Pure-Rust SCSS → CSS compiler for Python (ctypes bindings over the libsasso C ABI)

Project description

sasso

PyPI

Python bindings for sasso — a fast, pure-Rust SCSS/Sass → CSS compiler — over its libsasso C ABI.

sasso runs in-process (no Node, no subprocess, no system sass binary) via a small ctypes layer over a prebuilt native library. Each wheel bundles the compiled libsasso for its platform, so pip install sasso is all you need.

pip install sasso

Usage

import sasso

css = sasso.compile(
    """
    $brand: #336699;
    .card {
        color: $brand;
        .title { font-weight: bold; }
    }
    """
)
print(css)
# Compressed output, .sass (indented) syntax, filesystem load paths:
sasso.compile(src, style="compressed")
sasso.compile(indented_src, syntax="sass")
sasso.compile(src, load_paths=["styles", "vendor"])

Errors

A compile failure raises sasso.SassoError, carrying the diagnostic message plus the 1-based source location:

try:
    sasso.compile(".broken { color: ; }")
except sasso.SassoError as e:
    print(e.message, e.line, e.column)

Custom importers

Resolve @use / @forward / @import yourself (from a database, a bundler's virtual filesystem, HTTP, …) by subclassing sasso.Importer. It mirrors dart-sass's two-phase model:

class DictImporter(sasso.Importer):
    def __init__(self, files):
        self.files = files

    def canonicalize(self, url, *, from_import, containing_url):
        # Map a (possibly relative) URL to a stable canonical key, or None.
        return url if url in self.files else None

    def load(self, canonical):
        # Fetch the source for a canonical key, or None.
        return sasso.LoadResult(contents=self.files[canonical], syntax="scss")

css = sasso.compile('@use "theme";', importer=DictImporter({"theme": "$c: red;"}))

An exception raised inside an importer aborts the compile and surfaces as a SassoError with the original exception chained as __cause__.

API

Symbol Description
compile(source, *, style="expanded", syntax="scss", load_paths=None, url=None, importer=None) -> str Compile a stylesheet string to CSS.
SassoError Raised on failure; has .message: str, .line: int | None, .column: int | None.
Importer ABC for custom resolution: canonicalize(url, *, from_import, containing_url) + load(canonical) -> LoadResult | None.
LoadResult(contents, syntax="scss", source_map_url=None) Return value of Importer.load.
compiler_version() -> str Version of the bundled native sasso compiler.
__version__ Version of this Python package (independent of the compiler version).

style is "expanded" or "compressed"; syntax is "scss", "sass", or "css".

Performance

sasso compiles in-process, so it avoids the per-call process-spawn overhead of shelling out to the sass CLI. Compiling a non-trivial stylesheet 200× on an Apple-silicon Mac (benchmark.py, vs. spawning the dart-sass binary per compile):

output parity (sasso vs dart-sass): IDENTICAL

  sasso (in-process)        :   0.0068 s total  (0.034 ms/compile)
  dart-sass (subprocess/ea) :   4.7381 s total  (23.691 ms/compile)

  speedup: sasso is 701.0x faster for 200 compiles in this workload

Most of that gap is process-startup cost that an in-process binding removes entirely; the comparison reflects the realistic "shell out to sass" path a Python app would otherwise take.

Versioning — which compiler is bundled?

The package version (sasso.__version__) floats independently of the compiler version it bundles (sasso.compiler_version()):

sasso (PyPI) bundles core sasso crate
0.1.0 0.6.0

Each release notes its bundled core version in the CHANGELOG.

How it works

The package is a ctypes binding — not a CPython C-extension — over the libsasso C ABI. Because it has no Python-ABI linkage, a single native library per (OS, arch) serves every CPython 3.x (and PyPy), so each release ships one platform wheel per target rather than one per Python version.

The native crate is vendored from momiji-rs/sasso ffi/ and builds against the published sasso crate from crates.io.

License

MIT OR Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sasso-0.1.0.tar.gz (29.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sasso-0.1.0-py3-none-win_amd64.whl (1.1 MB view details)

Uploaded Python 3Windows x86-64

sasso-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

sasso-0.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (1.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

sasso-0.1.0-py3-none-macosx_11_0_arm64.whl (988.1 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

sasso-0.1.0-py3-none-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file sasso-0.1.0.tar.gz.

File metadata

  • Download URL: sasso-0.1.0.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sasso-0.1.0.tar.gz
Algorithm Hash digest
SHA256 56c641169671a099c4755e07463ac53a145cf7839b9e0cb23c15170ef9c3ee8e
MD5 63cfe102e868ec5fea49f1fce28b4242
BLAKE2b-256 bbdafb13d2cfa0c8ef0327c724b7de88679a8240a136cf198b8d9e165d2f0bc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.0.tar.gz:

Publisher: release.yml on momiji-rs/sasso-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sasso-0.1.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: sasso-0.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sasso-0.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 07221165477cd29d04a54a574d533d3b2c163f62f042faf6a1bec82adb5827d8
MD5 742ac01898019cfd783a4887ac308a81
BLAKE2b-256 4810d29389391b04131728824f7dd4f19f990a41e198c618200149dcc2a7a576

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.0-py3-none-win_amd64.whl:

Publisher: release.yml on momiji-rs/sasso-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sasso-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for sasso-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 3e8ffc35a7dd39dbf544ac68f2c2d7babaa03a84cd8d45063d8e6ba1dad08a20
MD5 cfb0fc763e9459cb23c88118e5d2a1e8
BLAKE2b-256 3bc99d4644a4a3bafaf076b694aa5e123e00db5d1186aeab0f687ee7163de154

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: release.yml on momiji-rs/sasso-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sasso-0.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for sasso-0.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 ce488ca59a8dc973041b0633fd86f7b5fe3ccf27224c3a9af3bd3522548245db
MD5 c4f3195db9ee55d28557435c07816b06
BLAKE2b-256 938709edc3c9ff2faec06da18370883f63217fef9859559359c2bfc8b626a7b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: release.yml on momiji-rs/sasso-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sasso-0.1.0-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: sasso-0.1.0-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 988.1 kB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sasso-0.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1cccc7e9f035c74ab4ddb529cf3b820e1e82b2fca6ce34582b1b829be1d10200
MD5 81643fefbf3bc9193881602ff751b9da
BLAKE2b-256 1ea540285438dcc64160e0c9229e0f8594ab319fcf4aaf23a35e351ba322bea9

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.0-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on momiji-rs/sasso-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sasso-0.1.0-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for sasso-0.1.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3b84234019bab48d6bdd3060dbc5704fd88ed526efc85c4da9df1c703bd0b3db
MD5 6c93b30f279a2cb425b42a0d88b2beb5
BLAKE2b-256 37b52cf812b2686a1ec843ec7f64378f1f82a68f071f6e61dd96f48385bed270

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.0-py3-none-macosx_10_12_x86_64.whl:

Publisher: release.yml on momiji-rs/sasso-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page