Mastering Data Validation with Sanatio

Mastering Data Validation with Sanatio

Sanatio (derived from the Latin word for “Validation”) is a powerful Python package designed to validate various data types. Whether you’re handling user input, API responses, or database entries, Sanatio ensures that your data adheres to specific rules and formats. In this article, we’ll explore how to use the Sanatio effectively.

Installation

First, let’s make sure you have Sanatio installed. You can do this via pip:

pip install sanatio        

Key Features

  1. The Sanatio Class:

  • The heart of Sanatio lies in the Sanatio class.
  • It provides a unified interface for various validators, making your code cleaner and more maintainable.

2. Built-in Validators:

  • Sanatio includes validators for common data types such as strings, numbers, dates, emails, usernames, and passwords.
  • These validators are accessible through the Sanatio class.

3. Custom Validators:

  • Need to validate something unique? You can create your custom validators by extending the Sanatio class.
  • Custom validators allow you to handle domain-specific rules effectively

Password Validation

Let’s validate a password, and check if the given password is valid or not

from sanatio import Sanatio
val = Sanatio()        
>>> val.isStrongPassword('123456')
False
>>> val.isStrongPassword('123456789@Abc', 
                          min_length=6, 
                          lowercase=True, 
                          uppercase=True,
                          special_chars)
True        

String Validation

check if the two strings are the same.

val.equals("abc", "abc")
True
>>> val.equals("abc", "ABC")
False
>>> val.equals("abc", "ABC", ignoreCase=True)
True        

The full documentation is available here. If you love contributing to open source, here is the source code.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了