Installation
Quickly get started with DataGuard by installing the package and using it for data validation in your Python projects.
DataGuard is a versatile and easy-to-use Python library for data validation. It provides a wide range of validation rules that can be applied to ensure your data meets the required criteria before further processing. This section will guide you through the installation process and provide an example of how to use the library in your project.
pip install data-guardfrom data_guard.validator import Validator
def main():
# Define the data to be validated
data = {"name": "John Doe", "email": "johndoe@example.com"}
# Define the validation rules
rules = {
"name": ["required"],
"email": ["required", "email"],
}
# Create a Validator instance
validator = Validator(data, rules)
# Perform the validation
response = validator.validate()
# Check if validation passed or failed
if response.validated:
print("Validation passed!", response.data)
else:
print("Validation failed with errors:", response.errors)
if __name__ == "__main__":
main()# you can also use pipe to separate the rules
rules = {
"name": "required",
"email": "required|email",
}
# or you can directly import Rule also.
from data_guard.rules.required import Required
from data_guard.rules.email import Email
rules = {
"name": [Required()],
"email": [Required(), Email()],
}Overview:
Installation: Install DataGuard with a simple pip command.
Initialization: Set up your data and validation rules.
Validation: Use the
Validatorclass to apply rules and validate your data.Result Handling: Easily check validation results and handle errors.
After installing the DataGuard package, it's helpful to familiarize yourself with the available validation rules to make the most of the library's capabilities.
Last updated