A simple Flask extension for requiring parameters in a request.
Project description
flask_require
This is a simple library to help you write cleaner flask code.
Installation
pip install git+https://github.com/ivario123/flask_require
Usage
from flask import Flask,request
import require
app = Flask(__name__)
@app.route('/')
@require.fields(request)
def index(name):
return f"Hello, {name}!"
if __name__ == '__main__':
app.run()
fields with optional response_formatter
import flask
import require
app = flask.Flask(__name__)
def __response(name, description="", code=200):
formatter_response = {"name": name, "description": description}
return flask.make_response(dumps(formatter_response), code)
@app.route("/")
@fields(flask.request, response_formatter=__response)
def index(path):
return {"name": "success", "description": "Works as it should"}
if __name__ == '__main__':
app.run()
Enforcing types
The system will check that the types provided in the signature and the types provided by the caller are the same before passing the arguments to the function.
from flask import Flask,request
import require
app = Flask(__name__)
@app.route('/')
@require.fields(request)
def index(name:str):
return f"Hello, {name}!"
if __name__ == '__main__':
app.run()
Usage of admin
from flask import Flask,request
from require import fields, admin
app = Flask(__name__)
@app.route('/')
@fields(request)
def index(name):
return f"Hello, {name}!"
@app.route('/admin')
@admin()
def admin():
return 'Hello, admin!'
def callback():
print('Hello, callback!')
@app.route('/admin_with_callback')
@admin(callback)
def admin_with_callback():
return 'Hello, admin with callback!'
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
flask_require-0.0.5.tar.gz
(3.8 kB
view details)
Built Distribution
File details
Details for the file flask_require-0.0.5.tar.gz
.
File metadata
- Download URL: flask_require-0.0.5.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 344db5782379db560cf637303cea0d8d529bffc04cdf20f8ba579d2ec99cd789 |
|
MD5 | 2597493d871453308bfe4e78cea48fcd |
|
BLAKE2b-256 | 0ac27f525f376acf756bfa781ef76dcfac398c32381d492e85b76e98faf40484 |
File details
Details for the file flask_require-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: flask_require-0.0.5-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dfde9df15dff2adba21e21b7762c17b4c8d9560e9b32210039b1344b9a2ce08 |
|
MD5 | 77cbe10fa2249bbe0321ef1cbb264785 |
|
BLAKE2b-256 | 039973e9efd7ecc9ce0e010e1ccb87ad73337aab09faa0e9376f3a75e665cfa3 |