collectr: Keep your S3 static files up to date.
More and more, we find ourselves storing our static website files - CSS, Javascript, images and more - on Amazon S3. Some of us do it because we use services like Heroku and don’t want to force the static files through our web dynos. Others of us do it to avoid huge bandwidth costs associated with hosting these on our own servers. Still others do it to take advantage of the scale and distributed nature of S3.
However, managing our S3 files can be a pain. Each time we change them we have to minify and reupload them. We also need to set all the metadata we want: things like Cache-Control headers. This can be boring and error-prone. collectr aims to help with that.
Using collectr
collectr is a collection of functions built on top of the boto library. This allows you to plug collectr into any of your Python code however you see fit. For those who want a ‘just works’ solution, however, collectr also comes with an example script that is perfect for using with any Django project.
If you want simple, you can use collectr like this:
import collectr
collectr.update('path/to/static/files', 'bucket-name')
collectr will scan the directory, minify anything that can be minified using whatever tools you have on your system, and upload all your files to the specified S3 bucket. Anything that already existed on S3 will have all of its metadata persisted.
Of course, you can have quite a bit more control than that.
import collectr
statics = collectr.StaticDir('path/to/static/files')
statics.input_directory = 'path/to/other/dir'
statics.minifier = 'yuicompressor -o {out_name} {in_name}'
statics.force_update = True
statics.ignore = ['.*\.jpg', '.*\.json']
statics.metadata = {'Cache-Control': 'max-age=3600'}
statics.update('bucket-name')
Before you do anything, though, make sure you have your environment variables set up. You’ll need AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY set to the correct values.
Features
Static file minification.
Ignore filters.
Multiple directory management.
Metadata management.
Installation
To install collectr:
$ pip install collectr
If you don’t have pip and can’t install it, you should complain to your sysadmin, and then do:
$ easy_install collectr
Contributing
collectr welcomes contributions, both bug fixes and new features. Any feature request should strongly consider the implications for the API. API clarity is valued above new features, so any feature that complicates the API must add significant value to the library to be accepted.
If you want to contribute, do the following:
Check that your idea hasn’t already been proposed. Check both open and closed issues on GitHub.
Fork the repository on GitHub and make your changes.
Where possible, write a test that can reproduce the bug, or that will test the new feature.
Send a Pull Request. Don’t forget to add yourself to the AUTHORS file.
History
0.0.5 (2013-03-07)
More detailed metadata handling.
Only update if needed or forced.
0.0.4 (2013-03-03)
Fix key names including the whole path.
Add groundwork for defaulting the minifier dict.
The update() helper method now takes an optional input directory.
Add an example collect_static script.
Sets the S3 ACL to allow public read access.
Metadata
Release files for collectr 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| collectr-0.0.5.tar.gz | 8.2 kB | Without provenance | Details |
Release files / collectr-0.0.5.tar.gz
| Download URL | collectr-0.0.5.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
98c1fedde6c56b4d46472cd90fa569f8139951edf52be5a45e7349a0b570d350
|
|
BLAKE2b-256 checksum How to use checksums |
25154e6624402fd0e9d0a4e27afdffbae4cd3c53db0ffb626ae96ae85c0f064f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for collectr 0.0.5
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.