Skip to main content

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


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.4.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

flask_require-0.0.4-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file flask_require-0.0.4.tar.gz.

File metadata

  • Download URL: flask_require-0.0.4.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for flask_require-0.0.4.tar.gz
Algorithm Hash digest
SHA256 ef0d08ee6090edee5c2b1fd11f63ad391994ddee31ecc1d18963474b9eb0fd85
MD5 0a19afa71f7890c4be79cad970a99774
BLAKE2b-256 e1191aef9e8da1a8e09c2585817418feb70f914e3013e4503becc1ba2d24eb3e

See more details on using hashes here.

File details

Details for the file flask_require-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_require-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b849b36f999329a89b8cb3bf9b695f42f50dbcf060c938bb37311566d2eb90b8
MD5 cdb11faa6e18289884222ee3fd196e34
BLAKE2b-256 93581b9fd240cadf413167bb26c90a849f47b6edbba7f9c7115eca20de633963

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page