Skip to main content

OSIRIS VALIDATOR

Osiris Validator is a set of decorators for validation with SQLAlchemy

(Readme is under construction...)

Getting Started

Installing

pip install osirisvalidator

Usage

To use the decorators, the validates() decorator from SQLAlchemy must be used before, and the pattern must be followed.

The parameter "field" is mandatory and you can set a custom message.

from sqlalchemy.orm import validates
from osirisvalidator.string import *
from osirisvalidator.internet import valid_email

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200), nullable=False)
    email = db.Column(db.String(60), nullable=False)

    @validates('name')
    @not_blank(field='name', message='Custom message')
    @is_alpha_space(field='name')
    @string_len(field='name', min=3, max=100)
    def validate_name(self, key, name):
        return name

    @validates('email')
    @not_blank(field='email')
    @valid_email(field='email')
    def validate_email(self, key, email):
        return email

When a validation error occurs, a ValidationException is thrown.

Flask example

@app.route('/saveuser', methods=['POST'])
def saveuser():
    try:
        user = User()
        user.name = request.form['name']
        user.email = request.form['email']
        db.session.add(user)
        db.session.commit()
    except ValidationException as ve:
        flash(ve.errors)
        return redirect(url_for('newuser'))

    return redirect(url_for('index'))

Flask-restless example

The parameter validation_exceptions in APIManager.create_api() from Flask-restless must be set to use osiris' ValidationException.

from osirisvalidator.exceptions import ValidationException

[...]

manager = APIManager(app, flask_sqlalchemy_db=db)
manager.create_api(User, validation_exceptions=[ValidationException], methods=['GET', 'POST'])

See about in: https://flask-restless.readthedocs.io/en/stable/customizing.html#capturing-validation-errors

List of validators

osirisvalidator.string

  • not_empty
  • not_blank
  • is_alpha
  • is_alpha_space (alpha characters and space)
  • is_alnum
  • is_alnum_space (alphanumeric characters and space)
  • is_digit
  • string_len (mandatory parameters: min and max)
  • match_regex (mandatory parameter: regex)

osirisvalidator.number

  • min_max (mandatory parameters: min and max)

osirisvalidator.internet

  • valid_email

osiris.intl.br

  • valid_cpf
  • valid_cnpj

Release files for osirisvalidator 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osirisvalidator 0.1.2
File Size Uploaded
osirisvalidator-0.1.2.tar.gz 18.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for osirisvalidator 0.1.2
File Interpreter ABI Platform
osirisvalidator-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 40.9 kB

Release files / osirisvalidator-0.1.2.tar.gz

Download URL osirisvalidator-0.1.2.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fdd98a77e7b0c362cb4dc847411a8827679e733407227c2d8dc3b6ffd8625a55
BLAKE2b-256 checksum
How to use checksums
a88f1e7543c399fccbebd49f62dc768bcaf0fc738a3bdf7e3ccc394a786ac939
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release files / osirisvalidator-0.1.2-py3-none-any.whl

Download URL osirisvalidator-0.1.2-py3-none-any.whl
Size 22.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a69f3669d985aacbaad65b17097fb9dd0499ed02f3d702574347c43a3e2cc2d7
BLAKE2b-256 checksum
How to use checksums
53ffea7147253409520d2697dfe808e7ea86806582266d8fca1238f37f7edc4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page