Skip to main content

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.

Metadata

Release files for flask-sustainable 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-sustainable 0.0.3
File Size Uploaded
flask-sustainable-0.0.3.tar.gz 17.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-sustainable 0.0.3
File Interpreter ABI Platform
flask_sustainable-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 29.2 kB

Release files / flask-sustainable-0.0.3.tar.gz

Download URL flask-sustainable-0.0.3.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
56d51a62912ca3854b74af7c81f309521147eab017c68dc3e0f03ffcce82e642
BLAKE2b-256 checksum
How to use checksums
7418a42124202a4665ad1b8dfc001bd443ec1ecfa54e9ba0033585d95dab372d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release files / flask_sustainable-0.0.3-py3-none-any.whl

Download URL flask_sustainable-0.0.3-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3a9954441e270b9f84bf5f4a2e1b63d9cd3fdfe7ccc910f7cce6f1aefd3581a
BLAKE2b-256 checksum
How to use checksums
985cac218db40276e6c9690f8b2a7c1e45f1a337d3a6c6480eb4c1b9b2a0305d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

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