Skip to main content

Flask extension that serves static file handlers in Google App Engine app.yaml files

Project description

flask-gae-static unit tests badge

Flask extension for Google App Engine that serves static file handlers from app.yaml files.

App Engine's built in static file serving is better in most ways than serving static files via app code: it uses Google Cloud's CDN, which is generally faster, cheaper, more scalable, and more secure. However, App Engine's dev_appserver local server is deprecated and degrading, and Google hasn't provided a replacement for local development that supports app.yaml-based static file handlers. This extension fills that gap.

Inspired by Andreas H. Kelch's app_server project.

License: This project is placed in the public domain. You may also use it under the CC0 public domain dedication.

Usage

Install with pip install flask-gae-static. Use with eg:

from flask import Flask
import flask_gae_static

app = Flask(..., static_folder=None)
flask_gae_static.init_app(app)
...

(static_folder=None is required to disable Flask's built in static file handling so that flask-gae-static can handle static files under any URL path prefix.)

flask-gae-static also includes a custom URL route converter that supports regular expressions. After calling init_app(), you can use it with regex inside a variable route part, eg:

@app.route('/<regex("(abc|def)"):letters>')
def handle(letters):
  ...

Development

After cloning the repository, set up a local virtualenv with:

python3 -m venv local
source local/bin/activate
pip install -e .

Run tests with:

python -m unittest discover

Changelog

1.0 - 2021-08-09

Breaking changes

Require the Flask app to be constructed with static_folder=None.

Before this, flask-gae-static tried to disable Flask's static file handling itself, but since it couldn't control the Flask initialization, it had to resort to workarounds that depended on Flask and werkzeug internal implementation details, and it broke when those details changed. This avoids that.

0.2 - 2021-12-31

Add support for regexp urls and regexp replacement strings in static_files.

0.1 - 2021-12-30

Initial release.

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

flask-gae-static-1.0.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file flask-gae-static-1.0.tar.gz.

File metadata

  • Download URL: flask-gae-static-1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.8.1 requests/2.27.1 setuptools/62.3.2 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.13

File hashes

Hashes for flask-gae-static-1.0.tar.gz
Algorithm Hash digest
SHA256 a392387ad27913830139b13269f43bcd8f92e4663fe7c5c2d7076dbe6df8f6fc
MD5 a72041bf0e76cab5d2e224c22a4cbf8c
BLAKE2b-256 b7b37237e42f2427232eacb8558e74ea7d86cbde98786868f2ce1cb8c9e53e5c

See more details on using hashes here.

Supported by

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