Flask-Hammer - For when every problem looks like a nail.
Project description
Flask-Hammer
"Flask-Hammer - For when every problem looks like a nail."
- You probably don't need this. There are better ways to do what this does.
- It wraps up Flask, Gunicorn and some bundled functionality to make a "batteries-included" Flask setup
Flask is excellent and requires very little boilerplate to get started; but I find myself writing many Flask apps with very similar structures and the same basic components with too much copy-pasting on my part for things like Metrics, Traces, Middleware, Responses, etc.
This lib is my kludgy way to reduce the boilerplate of those added extras that I so often rely on when deploying micro services or small apps in k8s.
Flask-Hammer's value (to me) is in helping to stand up a batteries-included flask app very quickly from an idea or for an MVP. Its value to anyone else is probably minimal.
Contributions and fixes are welcome, but for the time being this is deliberately more of an idiosyncratic convenience library than anything else.
PyPi
https://pypi.org/project/kv-flask-hammer/
Installation
With Poetry:
poetry add kv-flask-hammer
With pip:
pip install kv-flask-hammer
Example Usage
from kv_flask_hammer import FlaskHammer
def example_periodic_job():
print("Job Tick!")
app = FlaskHammer()
# Almost all of these config changes are optional
# Defaults can be found in constants.py
# For SSL
app.config.flask_set_secret_key("test")
# Set bind IP address and port for gunicorn/flask
app.config.set_ip_port("0.0.0.0", "5000")
# Enable Middleware and add a class
app.config.middleware_enable()
app.config.middleware_set_cls(ExampleMiddlewareClass)
# Enable basic healthz/livez routes
app.config.healthz_view_enable()
# Enable 'meta' view with routes for debugging
app.config.meta_view_enable()
# Enable prometheus metrics and expose them on a given port
app.config.metrics_enable()
app.config.metrics_set_ip_port("0.0.0.0", 9090)
# Enable OTLP Traces
app.config.traces_enable()
# Enable periodic jobs
app.config.jobs_enable()
# We can add jobs that run on periodic intervals (using Flask-APScheduler under the hood)
app.add_periodic_job(job_func=example_periodic_job, job_id="example_job_1", interval_seconds=5)
# Flask App object is accessible here for mutating the app in other ways or passing it around, etc.
flask_app = app.flask_app
def main():
return app.run_with_gunicorn()
Starting the above example app from e.g.; a bash script as a Docker Container entrypoint:
.venv/bin/python -c "from flask_hammer_example import main; main()"
Why 'kv_'?
- I prefix most of my projects, libs, etc. with 'kv' or 'zkv' for reasons that aren't interesting to anyone else.
- This library isn't purporting or pretending to be in any way official or associated with Flask; nor is it a plugin for it. It'd feel weird to just call it
flask-hammerofficially (and on pypi, etc.) in light of that.
Notice
This library is not associated with Flask, Gunicorn or their maintainers or contributors. It's just a convenience library made independently for my own use.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kv_flask_hammer-0.1.7.tar.gz.
File metadata
- Download URL: kv_flask_hammer-0.1.7.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d64923ecef4b92737fc9adcac3fe365668fc9ee355ff0527d77b30ce5d93ce54
|
|
| MD5 |
de4fc94964a0f4c0ddcf64bb53da1d99
|
|
| BLAKE2b-256 |
05692a76aa5fdb066eac77309c932f345bad59aafc0cdab343f90808aeddfbad
|
Provenance
The following attestation bundles were made for kv_flask_hammer-0.1.7.tar.gz:
Publisher:
publish.yml on RAVoigt/kv-flask-hammer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kv_flask_hammer-0.1.7.tar.gz -
Subject digest:
d64923ecef4b92737fc9adcac3fe365668fc9ee355ff0527d77b30ce5d93ce54 - Sigstore transparency entry: 207013674
- Sigstore integration time:
-
Permalink:
RAVoigt/kv-flask-hammer@3d35c3ad3e59200148e60aad1af7ac54654d71f8 -
Branch / Tag:
refs/tags/0.1.7 - Owner: https://github.com/RAVoigt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3d35c3ad3e59200148e60aad1af7ac54654d71f8 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file kv_flask_hammer-0.1.7-py3-none-any.whl.
File metadata
- Download URL: kv_flask_hammer-0.1.7-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb0dec7dab7ca13fcb8faa7a633443920cfe5dedcbbfacccca53399f381dc118
|
|
| MD5 |
34883ec421c7284776201b933540fb26
|
|
| BLAKE2b-256 |
bd4a85d808d1392a81e69c1704811bb594f56160a220d0cbe752a7b063ff425f
|
Provenance
The following attestation bundles were made for kv_flask_hammer-0.1.7-py3-none-any.whl:
Publisher:
publish.yml on RAVoigt/kv-flask-hammer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kv_flask_hammer-0.1.7-py3-none-any.whl -
Subject digest:
fb0dec7dab7ca13fcb8faa7a633443920cfe5dedcbbfacccca53399f381dc118 - Sigstore transparency entry: 207013678
- Sigstore integration time:
-
Permalink:
RAVoigt/kv-flask-hammer@3d35c3ad3e59200148e60aad1af7ac54654d71f8 -
Branch / Tag:
refs/tags/0.1.7 - Owner: https://github.com/RAVoigt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3d35c3ad3e59200148e60aad1af7ac54654d71f8 -
Trigger Event:
workflow_dispatch
-
Statement type: