A library to filter and validate input data inFlask 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.
Installation
pip install flask-inputfilter
Usage
To use the InputFilter class, you need to create a new class that inherits from it and define the fields you want to validate and filter.
There are lots of different filters and validators available to use, and you can also create your own custom filters and validators.
Definition
from flask_inputfilter import InputFilter
from flask_inputfilter.Enum import RegexEnum
from flask_inputfilter.Filter import ToIntegerFilter, ToNullFilter, StringTrimFilter
from flask_inputfilter.Validator import RegexValidator
class UpdateZipcodeInputFilter(InputFilter):
def __init__(self):
super().__init__()
self.add(
'id',
required=True,
filters=[ToIntegerFilter(), ToNullFilter()]
)
self.add(
'zipcode',
required=True,
filters=[StringTrimFilter()],
validators=[
RegexValidator(
RegexEnum.POSTAL_CODE.value,
'The email is not in the format of an email.'
)
]
)
Usage
To use the InputFilter class, you need to call the validate method on the class instance.
After calling the validate method, the validated data will be available in the g.validatedData object in the wanted format.
If the data is not valid, the validate method will return a 400 response with the error message.
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.validatedData
# Do something with validatedData
id = data.get('id')
zipcode = data.get('zipcode')
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_inputfilter-0.0.2.tar.gz.
File metadata
- Download URL: flask_inputfilter-0.0.2.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce5c9f31208a1cb2e04ac9c84d5bcf57adaa43653fb249043cdf68aefeef7d91
|
|
| MD5 |
299d7cde880bd77df32c9b40d622a4ab
|
|
| BLAKE2b-256 |
4aa2e8ac5606294f7422e85a8fb4bc19711be9c64d5b067a708c2f27992fcd9f
|
File details
Details for the file flask_inputfilter-0.0.2-py3-none-any.whl.
File metadata
- Download URL: flask_inputfilter-0.0.2-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0499bec15e9aff657f608826ccc476f6c4a457ff1cd2b80b32f428fa438b128
|
|
| MD5 |
977c9e98bdef5c2dd9971b0519301715
|
|
| BLAKE2b-256 |
36e938f03e860398bbfc9e8ad60aae187a7e54b5a05f3a5e67ea52233d794264
|