Skip to main content

A small package for validating incoming HTTP requests

Project description


A small package that provides a convenient method to validate incoming HTTP requests with a variety of powerful validation rules, highly customizable and heavily influenced by Laravel.

Jump straight to the documentation.


To install FlaskVel run:

pip install flaskvel

FlaskVel is now installed, check out the Quickstart.

This package is only compatible with Python 3+.


Lets suppose we want an endpoint that is used to register a user. First of all, we have to instantiate Flask and to also initialize FlaskVel by calling the constructor with its appropriate parameters.


from flask import Flask, jsonify
from flaskvel import Flaskvel, validate, BodyFormats

app = Flask(__name__)

Now we are ready to define our endpoint.


@app.route("/register", methods=["POST"])
def register():
    # some code for registering the user
    # ...
    return jsonify({"status": "ok"}), 200

To add validations let's create a class that derives from flaskvel.Validator and contains the rules.


from flaskvel import Validator, Rules

class MyValidator(Validator):
    def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs) # MUST always be called first
        self.rules = {
            "username": ["required", "string"],
            "password": ["required", "string", "min:8", "max:32", "confimed"],
            "email": [Rules.REQUIRED, Rules.EMAIL] # we can also use predefined constants instead of strings

For more info about writing rules see Rules syntax.

Now we can add our validator to the endpoint using one of the decorators provided by FlaskVel.

@app.route("/register", methods=["POST"])
@validate(MyValidator, BodyFormats.ANY)
def register():
    return jsonify({"status": "ok"}), 200

The decorator used, @validate(...) or @validate_no_validator(...), must be positioned after @app.route(...).

You can find a list of all the rules here.

Jump straight to the documentation.

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

flaskvel-2.1.tar.gz (23.9 kB view hashes)

Uploaded source

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