Skip to main content

Used to verify Flask route Response and Request contents.

Project description

flask_verify

Python package Maintainability Test Coverage Documentation Status

A python package to verify the content of Requests and convert the return values of view functions in Flask applications.

Installation

You can install flask_verify

pip install flask_verify

Example

Consider this minimal example, where Message is a simple dataclass.

from flask_verify.verify_json import verify_json_route
from flask import Flask, request

app = Flask(__name__)

@app.route('/example', methods=['POST'])
@verify_json_route(must_contain=('message', 'username'))
def example_route():
    message = Message(request.json['username'], request.json['message'])
    return message, 200

Just by writing a single decorator statement, we have:

  1. Ensured that the Request is of type application/json and contains keys message and username, if this is not true, our server will respond with a 400 status code Response explaining the issue to the server, including the name of the first missing key if that exists.
  2. Converted the return type to JSON, message object is an instance of the Message dataclass, thanks to our decorator, the Response will automatically be converted to a JSON containing the field names and values of the dataclass instance.

Read the Docs

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_verify-0.1.2.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

flask_verify-0.1.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file flask_verify-0.1.2.tar.gz.

File metadata

  • Download URL: flask_verify-0.1.2.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for flask_verify-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ac08b3710557b881863d2e129c4c2997ef5563de467364115ee0729686bbbabd
MD5 b0b4d0b3dc35f86187f30e8cdbbfc774
BLAKE2b-256 d45a832c3772863eb7a035707d08715e39abb286a68f8aa778598fcf95b47e5c

See more details on using hashes here.

File details

Details for the file flask_verify-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_verify-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e945dfeb6840d14aec51a5152c90d17755800b92355612ad9139be01753dc0e5
MD5 57371eb792f2e5ed090b04d38febf42f
BLAKE2b-256 0891b32c540170e1b617557ed6abc929669b3e44ddfe6ec2d58886389a2b511c

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