Skip to main content

A library to easily filter and validate input data in Flask applications

Project description

flask-inputfilter

The InputFilter class is used to validate and filter input data in Flask applications. It provides a modular way to clean and ensure that incoming data meets expected format and type requirements before being processed.

Thank you for using flask-inputfilter!

If you have any questions or suggestions, please feel free to open an issue on GitHub.

If you don’t want to miss any updates, please star the repository. This will help me to understand how many people are interested in this project.

For information about the usage you can view the documentation.

Test Status:
https://img.shields.io/github/actions/workflow/status/LeanderCS/flask-inputfilter/test.yaml?branch=main&style=flat-square&label=Github%20Actions https://img.shields.io/coveralls/LeanderCS/flask-inputfilter/main.svg?style=flat-square&label=Coverage
Version Info:
https://img.shields.io/pypi/v/flask-inputfilter?style=flat-square&label=PyPI
Compatibility:
https://img.shields.io/pypi/pyversions/flask-inputfilter?style=flat-square&label=PyPI
Downloads:
https://static.pepy.tech/badge/flask-inputfilter/month https://static.pepy.tech/badge/flask-inputfilter

Installation

pip install flask-inputfilter

Quickstart

To use the InputFilter class, create a new class that inherits from it and define the fields you want to validate and filter.

There are numerous filters and validators available, but you can also create your own.

Definition

from flask_inputfilter import InputFilter
from flask_inputfilter.Condition import ExactlyOneOfCondition
from flask_inputfilter.Enum import RegexEnum
from flask_inputfilter.Filter import StringTrimFilter, ToIntegerFilter, ToNullFilter
from flask_inputfilter.Validator import IsIntegerValidator, IsStringValidator, RegexValidator

class UpdateZipcodeInputFilter(InputFilter):
    def __init__(self):
        super().__init__()

        self.add(
            'id',
            required=True,
            filters=[ToIntegerFilter(), ToNullFilter()],
            validators=[
                IsIntegerValidator()
            ]
        )

        self.add(
            'zipcode',
            filters=[StringTrimFilter()],
            validators=[
                RegexValidator(
                    RegexEnum.POSTAL_CODE.value,
                    'The zipcode is not in the correct format.'
                )
            ]
        )

        self.add(
            'city',
            filters=[StringTrimFilter()],
            validators=[
                IsStringValidator()
            ]
        )

        self.addCondition(
            ExactlyOneOfCondition(['zipcode', 'city'])
        )

Usage

To use the InputFilter class, call the validate method on the class instance. After calling validate, the validated data will be available in g.validated_data. If the data is invalid, a 400 response with an error message will be returned.

from flask import Flask, g
from your-path import UpdateZipcodeInputFilter

app = Flask(__name__)

@app.route('/update-zipcode', methods=['POST'])
@UpdateZipcodeInputFilter.validate()
def updateZipcode():
    data = g.validated_data

    # Do something with validated data
    id = data.get('id')
    zipcode = data.get('zipcode')
    city = data.get('city')

See also

For further instructions please view the documentary.

For ideas, suggestions or questions, please open an issue on GitHub.

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_inputfilter-0.4.2.tar.gz (323.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

flask_inputfilter-0.4.2-cp313-cp313-win_amd64.whl (519.8 kB view details)

Uploaded CPython 3.13Windows x86-64

flask_inputfilter-0.4.2-cp313-cp313-macosx_10_13_universal2.whl (691.7 kB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

flask_inputfilter-0.4.2-cp312-cp312-win_amd64.whl (520.7 kB view details)

Uploaded CPython 3.12Windows x86-64

flask_inputfilter-0.4.2-cp312-cp312-macosx_10_13_universal2.whl (697.0 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

flask_inputfilter-0.4.2-cp311-cp311-win_amd64.whl (522.6 kB view details)

Uploaded CPython 3.11Windows x86-64

flask_inputfilter-0.4.2-cp311-cp311-macosx_10_9_universal2.whl (699.7 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

flask_inputfilter-0.4.2-cp310-cp310-win_amd64.whl (521.6 kB view details)

Uploaded CPython 3.10Windows x86-64

flask_inputfilter-0.4.2-cp310-cp310-macosx_10_9_universal2.whl (698.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

flask_inputfilter-0.4.2-cp39-cp39-win_amd64.whl (523.1 kB view details)

Uploaded CPython 3.9Windows x86-64

flask_inputfilter-0.4.2-cp39-cp39-macosx_10_9_universal2.whl (702.3 kB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)

flask_inputfilter-0.4.2-cp38-cp38-win_amd64.whl (523.7 kB view details)

Uploaded CPython 3.8Windows x86-64

flask_inputfilter-0.4.2-cp37-cp37m-win_amd64.whl (521.4 kB view details)

Uploaded CPython 3.7mWindows x86-64

File details

Details for the file flask_inputfilter-0.4.2.tar.gz.

File metadata

  • Download URL: flask_inputfilter-0.4.2.tar.gz
  • Upload date:
  • Size: 323.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for flask_inputfilter-0.4.2.tar.gz
Algorithm Hash digest
SHA256 265106326884e9a0ab28558f4cd554858f14c79bdc093540c4d8eb9cf1608dd5
MD5 d5eab88d24601dbe21c183830c18c041
BLAKE2b-256 5f2f0b6600db3712ab01e88dbb9436e49453fb45be433373935822038ed76ead

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2.tar.gz:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 44fa21aa3871c2fae4db353a7bdea6547fd780c8e2d90876e8f96d7821023441
MD5 ceeb7d268d381b7d034c8054e11b5797
BLAKE2b-256 63a5435a278278171189a121127ede7c4ca515c426fee8dae928093a10df7b03

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp313-cp313-win_amd64.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 1395c1053d62e31265b0bebde83b3c024492c7cdaab6ef1d1fbda2d72b796f5c
MD5 c106a932e27a878e40a1c578def3df20
BLAKE2b-256 4c693c2d50ea6fca10ace5bd08859fb68da5f8e6e4518b43a6a7045454ff714a

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp313-cp313-macosx_10_13_universal2.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bf5d6e79fcfede0c3ae6ce41a7b9cb9047f48c344b1c29c3f248dd678c3fe3ea
MD5 24898066add549758edf738a2282b996
BLAKE2b-256 2159d731889dc54b2a15abaaf91ee00fed4cbbcdb41b38cf32c6ff2be7e7ea95

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp312-cp312-win_amd64.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 3fb1140a8e0192a87f7d9e118efdade05e71f2ce3fe471298b9404d3e275b756
MD5 da6e32a14e5515ed0e0a587c6941e593
BLAKE2b-256 bbc44f8360d556f654d0175c671e9ad1506d52001d289dee0336807486db7e00

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ee9ba525702335526ff8aa2d1852ab1e87b95537b7694747aa6ff45548f0be8f
MD5 218a04b95f868adae6865ec98fa0c3c1
BLAKE2b-256 eee7a7a694251239aa7b54484cbbce7c9206cc036c6d6307c3480005ee4c6449

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp311-cp311-win_amd64.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 55d81e515694ae2b61a61c6b287785af5c60024e42b3fc39a806f65e7e836ab4
MD5 86c83f934b63efcb03dac8650b043910
BLAKE2b-256 5ec84c8322400f248df84be0898b87d22a65334a57b8c60ccc01c29b4583bc1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4dc9c72fbd2c060452f3c0ade9b3f98b1c7790cefb89a94bf771f3741d8f19e6
MD5 736fcf66b9aebd3460e647b19c08bdd9
BLAKE2b-256 3b75825a2ba5cce0b789d5ed04763ed390b8b2b2833a5c036dbf00bf0af60dcb

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp310-cp310-win_amd64.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d1261fcfee988c4a4fe62d54ce74a6c40230ebabf81c8fcea2421b95d71f710e
MD5 71ac088677298e62a010d9e88308f6a7
BLAKE2b-256 0b7a43519245376f88f59ec393cef91e4631d41727cbd6d66e34fcbaeab11dac

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp310-cp310-macosx_10_9_universal2.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 50ff7175c3d153e5cf087b0fdff816f05ce0ecfd8798285c46126d15c79fe28a
MD5 a1e785315e74e8170ad83d75c8bf3989
BLAKE2b-256 39648f1dcd4d31003f73b5cf87b04b2af0bf403c6c37998ef888c9316239eb59

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp39-cp39-win_amd64.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 8c7a2e76b4e18e13d79e794b8bca0bdfa5982513b1b9daad024dbb5d5431f336
MD5 cdd80b8c20b87cbfc8eb9e57d0c8648a
BLAKE2b-256 5ffe3c7e498fa356cb94d46726e69e0a0dea549ea2b613be2e2adeb76a853440

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp39-cp39-macosx_10_9_universal2.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 7da1243c84bbd5cca66f6e0b0201b61ed109771c8ab4e90727138ce85ccb6e5b
MD5 f69cf730e6ae49806aa4b6efc6544472
BLAKE2b-256 a271099a12139c32e70588a8f23ac4e424979c27c77e1e489b8e90069369557a

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp38-cp38-win_amd64.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_inputfilter-0.4.2-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for flask_inputfilter-0.4.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 1ae903bce38183a8f67d2211caf1ddbb7186e413e9127250c86b1ef5f07caf09
MD5 acad6d63bca318dec406eb63841244c9
BLAKE2b-256 e195c5b9d40798545a8f2065a1094448678b3f46e384bfa821fb68423e3aac3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_inputfilter-0.4.2-cp37-cp37m-win_amd64.whl:

Publisher: publish-to-pypi.yaml on LeanderCS/flask-inputfilter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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