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.1

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.1
File Size Uploaded
citry_django_compressor-0.2.1.tar.gz 5.9 kB Details

Built distribution (wheel)

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

Total release size: 12.8 kB

Release files / citry_django_compressor-0.2.1.tar.gz

Download URL citry_django_compressor-0.2.1.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
15c2713663975ac3788805a2d555ea749925148d61034384c6278a6ca8a0fd75
BLAKE2b-256 checksum
How to use checksums
f3616365ee2f077380055ec6e6c25f0b41d8f34c3825d62f5a4c8265f92371d7
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.1-py3-none-any.whl

Download URL citry_django_compressor-0.2.1-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92d3692bb8f7c8799f939b0e8db39419ba79ab9d3178f997729c7c23d26d75be
BLAKE2b-256 checksum
How to use checksums
800fc697a4e0c6ae3b164ce4d5fdd4f3b62a95dea812d6f084f315f3bb22cdee
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

0.2.2

2 release files

This release

0.2.1 This release

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