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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

sasso-0.1.1-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.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (1.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

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

Uploaded Python 3macOS 11.0+ ARM64

sasso-0.1.1-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.1.tar.gz.

File metadata

  • Download URL: sasso-0.1.1.tar.gz
  • Upload date:
  • Size: 29.8 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.1.tar.gz
Algorithm Hash digest
SHA256 b27085c8b82f710603d7b8cdccf31e8916149e6cd9a119dfc3a66e260759fa3f
MD5 8d455124a3e877b4e6aac2a293e1b690
BLAKE2b-256 03e7d20920cca29afb1b6b6309108b1aa84aa1475d6348aaf6ce68dd52a81192

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: sasso-0.1.1-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.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 407de1dc8d25ed5a5d32c066e4f910702e6cb6cbaab69dd5cbd5fbcbd240ce63
MD5 0df496038b44a3522bcfca2f4dd036b7
BLAKE2b-256 1f327cc1336ebef40d81c0ad66b2034552a407f596c5cfb0d252add3c95c1e38

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: sasso-0.1.1-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.1-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 52e567f540d3ea7c324a5aa75be22690616b99242bf8d8f8cdde6772f42a5d34
MD5 6f8489adf9d62f6e21f5319ee04864f8
BLAKE2b-256 56658449b13f8ee18fca491ddf809fe3b00ca0315d7477d422d3e139e4dc157d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sasso-0.1.1-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 64902051032c72f21c76dc41b6f1f9e43d4877350e18a1ddaf94a0e161d58b98
MD5 ef309610106452427870fd8d5bfddae4
BLAKE2b-256 de9e3dbc6e9ecc3d5f8f06ad45e43beb20bdf1b1a5ccde5b4f47f94da77f561a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sasso-0.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 e9dcbb1e4bcadb903321c7ccfa15639f2f68aa656ec0a121d1155748c0c559b0
MD5 1ebb9c509ef027fb4c9b170cf87d9753
BLAKE2b-256 66660d29c8fe2b74cd43919967f5cf54aafc849e7c3fd30d179b6495fc7b6566

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sasso-0.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 c7325f6d51e0c6906510fbb9c8f2de12672d642e0fed45debafcda55808f0306
MD5 353ae8d58f4b91bdc2984ca4fe424417
BLAKE2b-256 4732ca7ec611fbca2f1a1e00277b8e673e315c86bc8000201fe902be9b217f9c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: sasso-0.1.1-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.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 395b9539be46483588e6e72b9d1d9fb27a40ca70b00fc1c889fd7eed5eefb7a9
MD5 49dfc494c029f12bfcd7b5ed0bd9f8d0
BLAKE2b-256 5112c186b8649c2de87133101c0498afd2b71f406bdc031ad6685c5444f8566c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sasso-0.1.1-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0fcc436198767f575fc43c7c29571f0b35528ecc23c806dbb782a775527aef8f
MD5 9ea3e19f69510caa09687fcd77c95e08
BLAKE2b-256 11b2f6488cc11de1db2b0895a74b919c9b955720257fbde41f540cdd327de913

See more details on using hashes here.

Provenance

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