DPack
DPack is a static asset packager, written primarily for Django applications.
Installation
pip install dpack
DPack has a number of optional processors for things like minification and compilation:
pip install dpack[cssmin]pip install dpack[jsmin]pip install dpack[sass]
Or get everything with pip install dpack[all].
Configuration
DPack can be configured either via a dpack.yaml file, or via a DPACK setting if using Django. The following options
are available:
assets- a dictionary whose keys are paths of files to be created (relative tooutput), and whose values are lists of files to process and concatenate into said file. Each input file in the list may be prefixed by one or more processors by specifying the processor name followed by a colon. For instance,cssmin:sass:somefile.scsstells DPack to first compilesomefile.scss(found by searching insearchdirectories) using SASS, then minify it using thecssminprocessor.defaults- a dictionary whose keys are file extensions (without the.), and whose values are lists of processors to use by default for input files of that type.output- the path to store packed assets under. If not specified, this will be a temporary directory created usingtempfile.mkdtemp(prefix="dpack-").prefix- the URL prefix compiled assets will ultimately be served from, used when rewritingurland@importdeclarations in CSS files via therewriteprocessor. If usingDPackFinder, this defaults toSTATIC_URL.register- a dictionary whose keys are processor names you wish to register (or override), and whose values are dotted-path strings that resolve to a callable. See processors below.search- a list of directories to search for input files in. If usingDPackFinder, input files will be searched by using anySTATICFILES_FINDERSthat are notDPackFinderitself.
Example dpack.yaml
assets:
compiled/site.css:
- app1/first.css
- app2/second.css
- cssmin:sass:app3/third.scss
compiled/site.js:
- app1/first.js
- app2/second.js
defaults:
css:
- rewrite
- cssmin
js:
- jsmin
output: ./build
prefix: /static/
register:
custom: myapp.processors.custom
search:
- ./app1/static
- ./app2/static
Example DPACK Setting
DPACK = {
"assets": {
"compiled/site.css": [
"app1/first.css",
"app2/second.css",
"cssmin:sass:app3/third.scss",
],
"compiled/site.js": [
"app1/first.js",
"app2/second.js",
],
},
"defaults": {
"css": ["rewrite", "cssmin"],
"js": ["jsmin"]
},
"output": "./build",
"register": {
"custom": "myapp.processors.custom"
},
}
Using DPackFinder With Django
Simply add dpack.finders.DPackFinder to your STATICFILES_FINDERS setting, and DPack will search for inputs using
Django's staticfiles app, output compiled assets when collectstatic is called, and generate assets on-the-fly when
serving with runserver (DEBUG=True) or via the django.contrib.staticfiles.views.serve view.
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"dpack.finders.DPackFinder",
)
If you compile an asset to compiled/css/site.css, you can reference it as you would any other static asset, with
{% static "compiled/css/site.css" %} in your templates. These assets are also then post-processed by your
STATICFILES_STORAGE, so you can use things like Whitenoise's CompressedManifestStaticFilesStorage with no extra configuration.
Command Line Interface
DPack comes with a command-line utility, unsurprisingly named dpack. Run by itself, it will look for a dpack.yaml
config file and pack any assets it finds according to the config. You can specify a config file (-c) or Django
settings module (-s), and dump out the loaded config using dpack -y. Run dpack -h for a full list of options.
Processors
Processors are simply Python callables that take three arguments: text (the processed text so far), input (the
dpack.base.Input object containing things like relative name and absolute path), and packer (an instance of
dpack.DPack containing things like prefix). For example, the cssmin processor is implemented as:
def process(text, input, packer):
return rcssmin.cssmin(text)
Metadata
Release files for dpack 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dpack-0.6.1.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dpack-0.6.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.1 kB
Release files / dpack-0.6.1.tar.gz
| Download URL | dpack-0.6.1.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
875443db366939c3c54b60affce601f1ac40a1b826d85c63446c138ecc324f3a
|
|
BLAKE2b-256 checksum How to use checksums |
fe57a6d40042c35c9fb9971e7abd28d9206005cb175c7ce3af190c681cd225fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / dpack-0.6.1-py3-none-any.whl
| Download URL | dpack-0.6.1-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e198e93e6db10ec261a6bc09c2b6c612810b491ed65e3ae6e2b1801040c0929f
|
|
BLAKE2b-256 checksum How to use checksums |
5a794f2632eac8646cfa4f164de93e27f739ae01159a39b1b6da0aae41f8db10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|