Skip to main content

citry-django-compressor

Route Citry component assets through django-compressor for preprocessing and minification.

Why?

Citry collects each component's CSS and JS and emits them into the page. If your project uses django-compressor for asset preprocessing (SCSS, Less, CoffeeScript, ...) and minification, this extension bridges the two.

Installation

pip install citry-django-compressor

Usage

Register the extension with your Citry instance:

from citry import Citry
from citry_django import CitryDjangoExtension
from citry_django_compressor import CitryCompressorExtension

app = Citry(
    extensions=[
        CitryDjangoExtension(),
        CitryCompressorExtension(),
    ]
)

Inline Content with Precompilation

To mark inline content for precompilation, set its type attribute to match a COMPRESS_PRECOMPILERS entry:

from citry import Component
from citry.ext.dependencies import Style, Script


class MyComponent(Component):
    class Dependencies:
        css = [
            Style(content="...", attrs={"type": "text/x-scss"}),
        ]
        js = [
            Script(content="square = (x) -> x * x", attrs={"type": "text/coffeescript"}),
        ]

File-Based Assets

For file-based assets, use the Dependencies class with a URL and type attribute. Use Django's static() to respect your STATIC_URL setting:

from django.templatetags.static import static
from citry import Component
from citry.ext.dependencies import Style


class MyComponent(Component):
    class Dependencies:
        css = [
            Style(url=static("component.scss"), attrs={"type": "text/x-scss"}),
        ]

Django-compressor will find the file via staticfiles, precompile it, and output a compressed URL.

Django Settings

Configure django-compressor as usual:

INSTALLED_APPS = [
    # ...
    "compressor",
]

STATICFILES_FINDERS = [
    # ...
    "compressor.finders.CompressorFinder",
]

COMPRESS_PRECOMPILERS = (
    ("text/x-scss", "django_libsass.SassCompiler"),
    ("text/x-sass", "django_libsass.SassCompiler"),
    ("text/less", "lessc {infile} {outfile}"),
    ("text/coffeescript", "coffee --compile --stdio"),
)

Custom File Type Mapping

By default, the extension maps these file extensions to MIME types:

Extension MIME Type
.scss text/x-scss
.sass text/x-sass
.less text/less
.styl text/stylus
.coffee text/coffeescript

Extend or override with CITRY_COMPRESSOR_FILE_TYPES:

CITRY_COMPRESSOR_FILE_TYPES = {
    ".myformat": "text/x-myformat",
}

How It Works

  1. Citry collects each component's CSS and JS during rendering
  2. Citry deduplicates identical assets (same content or URL)
  3. Before emitting, the extension's on_dependencies hook fires
  4. Assets with precompiler type attributes are collected
  5. They're fed to django-compressor's programmatic API
  6. The original dependencies are replaced with URL-based ones pointing to compressed output

Citry's $component() callbacks and js_data() work normally - they're just JavaScript content that passes through compression unchanged.

Limitations

  • css_file / js_file: When using Citry's css_file = "component.scss", the file content is inlined and the filename is not preserved. The extension cannot detect the file type automatically. Use the Dependencies class with explicit type attribute instead.

License

MIT

Metadata

Release files for citry-django-compressor 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for citry-django-compressor 0.2.2
File Size Uploaded
citry_django_compressor-0.2.2.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for citry-django-compressor 0.2.2
File Interpreter ABI Platform
citry_django_compressor-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / citry_django_compressor-0.2.2.tar.gz

Download URL citry_django_compressor-0.2.2.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1a9da313d490347952c59f10cfc2665ae2ab381c38d9a0044afb6a3369939466
BLAKE2b-256 checksum
How to use checksums
e4fdbc90876c4e5f3c693a61a002f08236ad856a549e6dc912a85c34ba4dd6db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / citry_django_compressor-0.2.2-py3-none-any.whl

Download URL citry_django_compressor-0.2.2-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
460f805d232e0c75dc9c109368aa422eb7dd622e5382e671998a3034c9894700
BLAKE2b-256 checksum
How to use checksums
67a4dbbbf43626c65d9a690c7cf0997c10f57ab4d62ef68259440a89617ac9bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.2

2 release files

0.3.0

2 release files

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page