Skip to main content

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

Project description

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.

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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aguirre-0.1.3.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aguirre-0.1.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file aguirre-0.1.3.tar.gz.

File metadata

  • Download URL: aguirre-0.1.3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for aguirre-0.1.3.tar.gz
Algorithm Hash digest
SHA256 121b25a0076d927f57fc561ba92048a913a2d362810ad5eb6326773ea250b037
MD5 73a5841d8646af560b6f4c4cf9c2689f
BLAKE2b-256 75ae03958550002a403f8c6158601ade44a48c277a76e0dd01afe4795829addf

See more details on using hashes here.

File details

Details for the file aguirre-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: aguirre-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for aguirre-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e14737f7c2466ac14bb2c7736472ee5683cb02e93afef4e16e65c7ea127cff14
MD5 75490515449a2e48e2d18b0aa0b5b092
BLAKE2b-256 a7e4e67294e3cade4cadb1bbf8d319c3784d6b1ac8949bb2bdd2454714453de1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page