The "Criteria Pattern" is a Python package that simplifies and standardizes criteria based filtering, validation and selection.
Project description
🤏🏻 Criteria Pattern
The "Criteria Pattern" is a Python 🐍 package that simplifies and standardizes criteria based filtering 🤏🏻, validation and selection. This package provides a set of prebuilt 👷🏻 objects and utilities that you can drop into your existing projects and not have to implement yourself.
These utilities 🛠️ are useful when you need complex filtering logic. It also enforces 👮🏻 best practices so all your filtering processes follow a uniform standard.
Easy to install and integrate, this is a must have for any Python developer looking to simplify their workflow, enforce design patterns and use the full power of modern ORMs and SQL 🗄️ in their projects 🚀.
Table of Contents
📥 Installation
pip install criteria-pattern
💻 Utilization
from criteria_pattern import Criteria, Filter, FilterOperator
from criteria_pattern.converter import SqlConverter
is_adult = Criteria(filters=[Filter('age', FilterOperator.GREATER_OR_EQUAL, 18)])
email_is_gmail = Criteria(filters=[Filter('email', FilterOperator.ENDS_WITH, '@gmail.com')])
email_is_yahoo = Criteria(filters=[Filter('email', FilterOperator.ENDS_WITH, '@yahoo.com')])
query = SqlConverter.convert(criteria=is_adult & (email_is_gmail | email_is_yahoo), table='user')
print(query)
# >>> SELECT * FROM user WHERE (age >= '18' AND (email LIKE '%@gmail.com' OR email LIKE '%@yahoo.com'));
🔑 License
This project is licensed under the terms of the MIT license.
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
Hashes for criteria_pattern-2024.9.24.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dbf83dd34f4eaa37020419c87b665b2c765b82eed8bda233c3f5d8252e58825 |
|
MD5 | 792cfe62bd062a0a8d0fe5f5911f6ed3 |
|
BLAKE2b-256 | 294e1594749d3d21ef939fdb470aed3d5220355f4ba2907adca3dc1fc16ef9f6 |
Hashes for criteria_pattern-2024.9.24-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4fec1c66e92c3947eb81700f58c238612032a4e5c713a68103725bbe1d728cf |
|
MD5 | 770e2453a90b90f862cd1bd5c613f23c |
|
BLAKE2b-256 | 73c2245c887f8d6e11f7c90b33a46d338f2b90353d5d3bbb100db614d28b3b7f |