Flask-middlewares
Allows you to use middleware in Flask
Installation
pip install Flask-Middlewares
Example
from typing import Callable
from flask import Flask, Blueprint
from pyhandling.annotations import decorator
from flask_middlewares import MultipleMiddlewareRegistrar
from flask_middlewares.tools import EVERYTHING
app = Flask(__name__)
api_blueprint = Blueprint('api', __name__)
view_blueprint = Blueprint('views', __name__)
def concatenation_by(line: str) -> decorator:
"""
Function for a decorator that concatenates the result of the decorated
function with the input result of this function.
"""
def decorator(func: Callable) -> Callable:
def wrapper(*args, **kwargs) -> str:
return func(*args, **kwargs) + ' ' + line
return wrapper
return decorator
# Config for creating a middleware registrar for your application
# See the MiddlewareRegistrar.from_config documentation.
app.config["ENVIRONMENTS"] = {
"global": {
"MIDDLEWARES": [concatenation_by("from global")],
"VIEW_NAMES": EVERYTHING
},
'api': {
"USE_FOR_BLUEPRINT": True,
"MIDDLEWARES": [concatenation_by("from api")]
}
}
@app.route('/')
def index():
return "Real but fake home page" # Real but fake home page from global
@view_blueprint.route('/home')
def home_endpoint():
return "Real home page" # Real home page from global
@api_blueprint.route('/users')
def user_api_endpoint():
return "\"Some user data\"" # "Some user data" from global from api
app.register_blueprint(api_blueprint, url_prefix='/api')
app.register_blueprint(view_blueprint)
MultipleMiddlewareRegistrar.from_config(app.config, environments_only=True).init_app(app)
if __name__ == '__main__':
app.run(debug=True, port='8048')
Metadata
Release files for Flask-Middlewares 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Flask-Middlewares-2.0.0.tar.gz | 20.6 kB | Without provenance | Details for Flask-Middlewares-2.0.0.tar.gz |
Release files / Flask-Middlewares-2.0.0.tar.gz
| Download URL | Flask-Middlewares-2.0.0.tar.gz |
|---|---|
| Size | 20.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f30dc0d436e3bf64531147ad858e58f713f6637bb16d65f2e16dc24f103ad19
|
|
BLAKE2b-256 checksum How to use checksums |
0320191653d5c9b300449d9f599956bfe0c5fbc060a27e993f323b789d0b8f1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|
Security for Flask-Middlewares 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.