Skip to main content

Brings sustainability to Flask via HTTP headers

Project description

Supported Python versions License Latest Version PyPI Publish Python CI

Flask-Sustainable is an extension for Flask that provides a simple way to add sustainability to your application.
This is done by compressing the HTTP responses as soon as possible.
More, HTTP headers are used so that the server can return information on the performance of the application.

Two types of headers are used:

  • indicators

  • scores

Get started 🚀

Installation 📦

Install the extension with pip:

pip install flask-sustainable
# Or
pip install git+https://github.com/av1m/flask-sustainable.git

Try it out 🔬

💡 The code is available in example.py file

import flask
from flask_sustainable import Sustainable
from flask_sustainable.indicator import PerfCPU, PerfRAM, PerfTime

app = flask.Flask(__name__)
sustainable = Sustainable(app)  # Invoke Sustainable().init_app(app)
sustainable.add_indicators(PerfTime(), PerfCPU(), PerfRAM)

@app.route("/")
def helloWorld():
    return "Hello, World!"

Then, try with cURL or Postman (or any other HTTP client):

$ curl http://localhost:5000/ -I -H "Perf: Perf-Time,Perf-CPU Perf-RAM"

Perf-Time: 0.76592
Perf-RAM: 0.12114
Perf-CPU: 0.97900

Developers 👨‍💻

Use python3 or python command (depending on your configuration) There is a Makefile for helping with development.

  1. Clone this project

git clone https://github.com/av1m/flask-sustainable.git
cd flask-sustainable
  1. Run make command

make install
  1. Run a sample; a server is running on port 5000

python example.py

Everything has been installed and configured correctly! 🎊 Once you modify the code, you can run make format and make test commands to check the code style and test coverage (through make coverage).

To find out all the available commands, you can use make help :

help              Display callable targets.
test              Run all tests.
coverage          Run all tests and generate coverage report.
requirements      Install requirements.
install           Install package.
run               Run a example script.
format            Format code.

Tests 🧪

A simple set of tests is included in tests/. To run, simply invoke make test or pytest. You can also run a coverage report with make coverage.

Compatibility 🤝

This project is compatible with Python 3.6 and up. It has been tested on Python 3.6, 3.7, 3.8, 3.9, and 3.10

The Github Actions is not compatible with Python 3.6 because there is no setup.py file.

License 📃

This project is licensed under the MIT License.

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-sustainable-0.0.2.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

flask_sustainable-0.0.2-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file flask-sustainable-0.0.2.tar.gz.

File metadata

  • Download URL: flask-sustainable-0.0.2.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for flask-sustainable-0.0.2.tar.gz
Algorithm Hash digest
SHA256 48a2cc9353825206c6759cb689ec1c8c01f6384c4c33b498821e56474724f71e
MD5 bb665693d397ed30313474e17347670f
BLAKE2b-256 da26278f1cad1f734ac6cbb5bd0f0bee99a9b41f42e0c880f83f191cdd35e576

See more details on using hashes here.

File details

Details for the file flask_sustainable-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_sustainable-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 48e73fb33ed52e34679f3c589a4783fc44342f04b931ccfa1857fd1ba5f22cfd
MD5 99f0907de532288a6a7b464838acc8f4
BLAKE2b-256 c93b119484c87803f191410ffe59255c64a3644545e3ff8be99fbf0c9722ebc4

See more details on using hashes here.

Supported by

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