flask-wrappers
Decorators to facilitate flask enpoints implementation
import flask_wrappers as wrappers
Decorators
@catch
Decorator to catch exceptions and return a meaningful traceback
@wrappers.catch
def my_endpoint():
raise ValueError()
json_request
Decorator to pass the decoded json body of the request as a dict to the endpoint method.
@wrappers.json_request
def my_endpoint(body):
return body.get("property_1")
json_request_required:
Decorator to pass the decoded json body of the request as a dict to the endpoint method. Validate that the json body contains at least the required properties.
@wrappers.json_request_required("str:name", "str:job", "int:age", "float:cash")
def my_endpoint(body):
return body["name"] # safe
querystring_request
Decorator to pass the querystring dict to the endpoint method.
@wrappers.querystring_request
def my_endpoint(querystring):
return querystring.get("property_1")
headers_request
Decorator to pass the headers dict to the endpoint method.
@wrappers.headers_request
def my_endpoint(headers):
return headers.get("property_1")
cookies_request
Decorator to pass the cookies dict to the endpoint method.
@wrappers.cookies_request
def my_endpoint(cookies):
return cookies.get("property_1")
body_request
Decorator to pass the raw body to the endpoint method.
@wrappers.body_request
def my_endpoint(body):
return body.get("property_1")
json_response
Decorator to return the appropriate json response object from anything decodable to json.
@wrappers.json_response
def my_endpoint(body):
l = [10, 8, 5]
return {'name': 'Test', 'grades': l}, 200
RouteFactory
Class to generate routes for http methods and paths from a flask app or blueprint.
from flask import Blueprint, Flask
import flask_wrappers as wrappers
# create a flask app
app = Flask(__name__)
# or create a blueprint
## app = Blueprint("blueprint_name", __name__)
# create a route_factory from the app
route_factory = wrappers.RouteFactory(app)
options(route, **options)
Create an endpoint for the route and method OPTIONS
@route_factory.options("/names")
def my_endpoint():
# logic here
get(route, **options)
Create an endpoint for the route and method GET
@route_factory.get("/names")
@wrappers.json_response
def my_endpoint():
return ["Anna", "Alice", "Shila"], 200
post(route, **options)
Create an endpoint for the route and method POST
@route_factory.post("/names")
@wrappers.json_request
@wrappers.json_response
def my_endpoint(body):
# logic here
return "ok", 200
put(route, **options)
Create an endpoint for the route and method PUT
@route_factory.put("/names")
@wrappers.json_request
@wrappers.json_response
def my_endpoint(body):
# logic here
return "ok", 200
delete(route, **options)
Create an endpoint for the route and method DELETE
@route_factory.post("/names/<name>")
@wrappers.json_response
def my_endpoint(name):
# logic here
return "ok", 200
Metadata
Release files for flask-wrappers 1.0.2
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_wrappers-1.0.2.tar.gz | 4.4 kB | Without provenance | Details for flask_wrappers-1.0.2.tar.gz |
Release files / flask_wrappers-1.0.2.tar.gz
| Download URL | flask_wrappers-1.0.2.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f57eb525e7b9418c24413fbbc961a71369f36c28961ac91e5d77051d8ef3c12a
|
|
BLAKE2b-256 checksum How to use checksums |
e06383533f1efd69ca2c2a1bb3fe74705770683098f752d7b48020ae261ab304
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
|
Security for flask-wrappers 1.0.2
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.