Skip to main content

citry-django-compressor

Routes Citry components' CSS and JS through django-compressor, so they are preprocessed, minified and served as compressed files.

When it applies

It works on responses rendered through citry-django's template backend: your <head> lives in a Django template, and Citry renders <c-*> regions inside it. citry-django's page collects the regions' assets, and this package bundles them into one file per response. Say where with <c-css /> and <c-js /> in your base template.

A component you render straight from Python, such as str(Page()) or Page().render(), has no citry-django page around it, so this package does not see its assets. Render it from a Django template to get them compressed.

Setup

pip install citry-django-compressor
# myproject/citry_app.py
from citry import Citry
from citry_django import CitryDjangoExtension
from citry_django_compressor import CitryCompressorExtension

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

Components keep declaring assets the way Citry documents. Nothing else is added to a component.

What it does

When a page has finished, citry-django hands this extension the page's component tags through its on_page_assets hook: once for the CSS and once for the JavaScript. The extension feeds the ones it can read to django-compressor and puts the compressed file where the first of them stood.

It is offered only the tags of components that need no Vue. A component that needs Vue (one with js, js_data(), Events or Vue bindings) is its own Vue app, an island, and Citry's browser runtime checks the URL and integrity of an island's tags, so its CSS and JavaScript stay exactly as Citry wrote them. Citry's runtime scripts are left alone too.

Of the tags it is offered, it takes the ones Citry reports as the same on every page that places the component: a component's own CSS and JavaScript, and its Dependencies, whether a file under COMPRESS_URL or inline content. Citry says this for each tag (see SerializedAssetEntry in Citry's asset placement docs), and citry-django passes it along with the tags.

It leaves alone the <style> holding one instance's css_data() values, so one page's data never ends up in a shared file, and any tag Citry marks as possibly holding one render's data, such as one an on_dependencies hook added or rebuilt. It also leaves alone a file somewhere else, such as a CDN, and a file Citry serves from its own routes.

Results come from django-compressor's cache where that is allowed, keyed the way the {% compress %} tag keys it, on a digest of the content plus the mtimes of its sources. Without that every render recompiles its SCSS from scratch.

Citry's dependency strategy

This package works on the tags Citry writes, so CITRY_DEPS_STRATEGY, citry-django's setting for what gets serialized, decides what it can reach. Leave it at its default: on "ignore" Citry writes no tags, there is nothing to compress, and a page loads without its component styles.

Settings

Everything is django-compressor's own configuration. There is no separate setting for whether to compress: COMPRESS_ENABLED decides, exactly as it does for the template tag.

# settings.py
COMPRESS_ENABLED = True
COMPRESS_PRECOMPILERS = (("text/x-scss", "django_libsass.SassCompiler"),)
STATICFILES_FINDERS = [..., "compressor.finders.CompressorFinder"]

A compressor class named in COMPRESSORS is used here too, the same one a {% compress %} block uses, so a project that names its output files its own way gets that for component assets as well.

There is no setting here at all. What compiles an asset is the asset's own type, written the way you would write it in a template:

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

django-compressor picks its precompiler on that attribute and nothing else, so a .scss that declares no type arrives as source and leaves as source, exactly as a <link href="x.scss"> without one would inside a {% compress %} block. The mimetype is an arbitrary string that has to match your COMPRESS_PRECOMPILERS entry exactly.

Options

Option Default What it does
force None A callable answering whether this render must bypass the cache.

force exists for output that depends on something the cache key cannot see. Wagtail's preview of unsaved theme settings is the case it was written for: the compiled CSS differs, the content and mtimes do not, so a cached entry would show the wrong thing.

CitryCompressorExtension(force=lambda: getattr(get_current_request(), "is_preview", False))

Limitations

Under CITRY_DEPS_STRATEGY = "fragment" citry-django does not collect a page's tags, so nothing is compressed.

A component that needs Vue keeps its assets as Citry wrote them, so SCSS or another language that needs a precompiler does not work in its css. Compile it ahead of time, or move the styles to a component that needs no Vue.

Bundling a whole response needs somewhere to put the result, so a base template that writes no <c-css /> or <c-js /> gets one compressed file per <c-*> region instead: the assets stay where Citry put them, and putting a bundle somewhere you did not ask for it would be worse than not making one. Repeats are still dropped first, so a stylesheet two regions both asked for is compiled once either way.

License

MIT

Metadata

Release files for citry-django-compressor 0.4.0

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.4.0
File Size Uploaded Provenance Actions
citry_django_compressor-0.4.0.tar.gz 10.2 kB With provenance Details for citry_django_compressor-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 21.7 kB

Release files / citry_django_compressor-0.4.0.tar.gz

Download URL citry_django_compressor-0.4.0.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8e69e2dadc0de605e79d946f836e7d0613339eeed214d9812a34332cd22cf283
BLAKE2b-256 checksum
How to use checksums
f5a6d2fb4c736a8285981082a5fb4cad09109b2ce724d2a72b9563580b9ff5a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 24, 2026.

Transparency log

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

Download URL citry_django_compressor-0.4.0-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66bddcae5505372eb9f93da218e6caa78424e680d6628fe355debfa2149b52f3
BLAKE2b-256 checksum
How to use checksums
a3e3d9105b19e9f9a479ae9682c8db6fda5d5d28b2fe5209157df2d7777e25b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 24, 2026.

Transparency log

Security for citry-django-compressor 0.4.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for citry_django_compressor-0.4.0.tar.gz

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 Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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