Skip to main content

Aguirre

Let Python webservers self-host JS/CSS/etc assets like unpkg does

Warning: The utility functions have been proven out, but the integrations have had limited usage. Treat them with caution.

When your Python application needs a Python dependency from PyPI you can lean on tools like pip and venv to manage that. But what if its a web application that needs a Javascript or CSS dependency from NPM? Large applications run by large teams can justify elaborate build and deployment pipelines. But a smaller app? Something internal? A demo? Or a learning exercise? You want a lighter solution...

In recent years it's become popular to lean on unpkg for this. (Or jsdelivr, or cdnjs, or another service.) How easy it is to drop one line into your template and let a CDN look after serving the file to your users:

<script src="https://www.unpkg.com/jquery@3.7.1/dist/jquery.min.js"></script>

But there are disadvantages to relying on a third party like this. It needs to be up whenever your app is up, and be reliable. You are vulnerable to takedowns (remember left-pad?). Your users give up more privacy. And worst of all: you can't develop your application offline.

Aguirre lets you download NPM tarballs and add them to your app. (And probably commit them in too.) Then you can drop a line into your app and let Aguirre serve the desired file straight out of the tarball:

<script src="/pkgs/jquery@3.7.1/dist/jquery.min.js"></script>

Sure, it's not the most scalable solution. But it's a great way to quickly get things moving. And if you have a frontend (edge) server configured to do caching you may find it can handle the scaling for you!

Installation

This code is not currently on PyPI. Consequently you should add the following line to your requirements.txt file:

git+https://github.com/pscl4rke/aguirre.git

Integrations

There are some integrations into frameworks inside aguirre.integrations. Their usage is documented in the module docstrings...

Development and Testing

This codebase uses ephemerun to test against multiple Python versions. (It's a bit like Tox, except is uses containers for isolation rather than virtualenvs.)

Roadmap

  • Better Django support
  • Handle pathlib.Path arguments
  • Prove the headers etc for caching middleware/frontends
  • Make sure no Set-Cookie headers exist to stop caching proxies

Licence

This code is copyright P. S. Clarke and is licensed under the BSD-3-Clause licence.

The test suite contains real-world example files. These are covered by their own embedded licences.

Release files for aguirre 0.3.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 aguirre 0.3.1
File Size Uploaded
aguirre-0.3.1.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aguirre 0.3.1
File Interpreter ABI Platform
aguirre-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / aguirre-0.3.1.tar.gz

Download URL aguirre-0.3.1.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7ed8cd3e8ad4d92f458b2fb5a06702d91fad266315ffe288314da58cb0d789ec
BLAKE2b-256 checksum
How to use checksums
7bb842fd457aecc660b94ba7a97f7398de305cf0d22713d556b6b9da11204b92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / aguirre-0.3.1-py3-none-any.whl

Download URL aguirre-0.3.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0c7271804bbc49a00c1413a3a77b97aa0f0733fcd238838249b710eacbcc784
BLAKE2b-256 checksum
How to use checksums
d79368a577c8da01b3fca282266d1581c3906270f0a61c1a7689125637271591
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

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