Two types of headers are used:
- indicators
- scores
Install the extension with pip:
pip install flask-sustainable
# Or
pip install git+https://github.com/av1m/flask-sustainable.git
💡 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
Use python3 or python command (depending on your configuration) There is a Makefile for helping with development.
- Clone this project
git clone https://github.com/av1m/flask-sustainable.git
cd flask-sustainable
- Run make command
make install
- 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.
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.
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.
This project is licensed under the MIT License.