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.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f87f350c290d52444f6a19711a40ea241bcd27a9ad5a63ba9becb6cb33df896 |
|
MD5 | 88f716b25996dc67a5ece31503e69ba4 |
|
BLAKE2b-256 | 291eeefdc271b1598e0a547cd835b9444f5f57f1552476ed87c0c4896f531708 |
Hashes for criteria_pattern-2024.9.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca8eb7a2d4af388b49d3fb9ec7364933d2f027c45cb82fda17c4ea30dc654991 |
|
MD5 | d591417a97ce8a684ec9537fdbcf183b |
|
BLAKE2b-256 | 0f09f22743c94e27524b0a5eb0dc1a255ffa80be15ef51e1a1a083020e14f6a9 |