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.2.tar.gz (30.2 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.2-py3-none-win_amd64.whl (1.1 MB view details)

Uploaded Python 3Windows x86-64

sasso-0.1.2-py3-none-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

sasso-0.1.2-py3-none-musllinux_1_2_aarch64.whl (1.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

sasso-0.1.2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

sasso-0.1.2-py3-none-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

sasso-0.1.2-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.2.tar.gz.

File metadata

  • Download URL: sasso-0.1.2.tar.gz
  • Upload date:
  • Size: 30.2 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.2.tar.gz
Algorithm Hash digest
SHA256 4503974d230dabcd6d464a1b5df6b523d64229b3f606484c27683f27d0721eda
MD5 aa77bbc35a94a6c23b62968fcb8f8db9
BLAKE2b-256 437e60c9de36840525a2e9938744b70a0529b202e750008e9c121619545e0f3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.2.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.2-py3-none-win_amd64.whl.

File metadata

  • Download URL: sasso-0.1.2-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.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e253fef4b5b57a11c0349283c82892b64de98da0742b454e22b4e50240cca343
MD5 10131a5d52bba7da9f8fd59122ca7228
BLAKE2b-256 f8020f8023313ae3279baccde43d1584a34f25cc01a7d32ba8ff6df298c227d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.2-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.2-py3-none-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: sasso-0.1.2-py3-none-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sasso-0.1.2-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0cf5d53f3f641f775c35eec738133d4b12dd7c42ecf28b67a232c3d567df9ab7
MD5 dae22e541f422dbf73ad3a86f2c4776b
BLAKE2b-256 d48771cb764314ff6f7a32c9d294c0cd40d7fc14c0c3160218b5e3b5337fbbce

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.2-py3-none-musllinux_1_2_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.2-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for sasso-0.1.2-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f0ddfe08c82cd4586635ebd6bd7bf4e6f82e41f23ec118109be5a1a828c276e8
MD5 8085d28eec8de49412ac34917eca07cf
BLAKE2b-256 d634565195dceb791cac7b887c6a9554d4e197b717eca1bafe278458c7d7d0be

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.2-py3-none-musllinux_1_2_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.2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for sasso-0.1.2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 3e79f72758d6f5c0efb3b3b66cf2f3e60563d0c871770b511d2766944b6c1e08
MD5 fdae5c2034878b75bf4805d76ca9b9fd
BLAKE2b-256 27ab762d0e5affe949452a3f593c2dfe29914bee3a99f39d9fb220db4662b946

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.2-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.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for sasso-0.1.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 d8989815b9b206e80b813ce15f29be5edf06895df83795c0af7b471c353181cb
MD5 6cd2d243d51b4a675027438c1990f908
BLAKE2b-256 18f0aaec27ba91d73afc53e565a2227fed273fc6c6b5e583d1ec7371a9ab165b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.2-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.2-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: sasso-0.1.2-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.0 MB
  • 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.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 63965980644ebe6f1639c918577594fc1c519d220d17f1f276d66fc13cfd894a
MD5 5e76b49e26b3a3c4c9463f318d36cb51
BLAKE2b-256 87e51daff5e55063765ecedacf2c2c2dc3185537523f213a6d2d91e796e83610

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.2-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.2-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for sasso-0.1.2-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8a490398c93b22c684097d97ddfde6d7ccdb6a6b6a642bfe19f776666ef03cc8
MD5 c7b37ef1e05d5c0270f7e44b295092ca
BLAKE2b-256 4894a459e38618ddd144c86e8886108baeebf8e9cd812a1ad9f0ec067c31c080

See more details on using hashes here.

Provenance

The following attestation bundles were made for sasso-0.1.2-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