Skip to content
vic

jdaroesti/flask-http2-push

A Flask extension to add http2 server push to your application.

jdaroesti/flask-http2-push.json
{
"createdAt": "2017-01-11T05:39:24Z",
"defaultBranch": "master",
"description": "A Flask extension to add http2 server push to your application.",
"fullName": "jdaroesti/flask-http2-push",
"homepage": null,
"language": "Python",
"name": "flask-http2-push",
"pushedAt": "2020-09-19T00:00:40Z",
"stargazersCount": 40,
"topics": [],
"updatedAt": "2022-11-17T02:08:02Z",
"url": "https://github.com/jdaroesti/flask-http2-push"
}

Build Status pypi

Important: This repo is no longer mantained.


Bottom line: A Flask extension to add HTTP2 server push to your application.


This is a drop in library for doing HTTP2 server push with a Flask application. It needs a server that supports HTTP2 push, like Google Appengine or Cloudfare. Once added to your Flask application it will generate the necessary headers for server push to work.

To install run:

Terminal window
pip install flask-http2-push

You need to create a push_manifest.json file (can be named anything you want) that contains the files you want to push (Appengine currently has a limit of 10 files). The file format is very easy:

{
"/path/to/file-to-push.js": {
"type": "script",
"weight": 1
},
"/path/to/file-to-push.css": {
"type": "style",
"weight": 1
},
"/path/to/file-to-push.woff2": {
"type": "font",
"weight": 1
},
"/path/to/file-to-push.html": {
"type": "document",
"weight": 1
},
}

There is a library for automatically generating the file. You can find it here (https://www.npmjs.com/package/http2-push-manifest).

Once you have your manifest file, you can use the library in your flask view functions like so:

import flask
from flask_http2_push import http2push
app = flask.Flask(__name__)
@app.route('/')
@http2push()
def main():
return 'hello, world!'

This will try to find a file named push_manifest.json at the root of the project. If you would like to name the manifest differently or use another location, you can specify it in the decorator:

@app.route('/')
@http2push('static/my_manifest.json')
def main():
return 'hello, world!'
Terminal window
pip install -r requirements.txt
nosetests

This library is inspired by the Google Appengine HTTP2 push library (https://github.com/GoogleChrome/http2push-gae). The explainer document contained within that repo is a very good read if you want to further explore how HTTP2 push works (https://github.com/GoogleChrome/http2push-gae/blob/master/EXPLAINER.md)

MIT license. See LICENSE.txt for full info.