https://github.com/adriamontoto/criteria-pattern
The Criteria Pattern is a Python 🐍 package that simplifies and standardizes criteria based filtering 🤏🏻, validation and selection.
https://github.com/adriamontoto/criteria-pattern
criteria development filtering pattern python python3 python311 python312 python313 selection sql tools utilities validation
Last synced: 8 months ago
JSON representation
The Criteria Pattern is a Python 🐍 package that simplifies and standardizes criteria based filtering 🤏🏻, validation and selection.
- Host: GitHub
- URL: https://github.com/adriamontoto/criteria-pattern
- Owner: adriamontoto
- License: mit
- Created: 2024-08-12T19:40:53.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-02T16:48:13.000Z (8 months ago)
- Last Synced: 2025-05-06T12:16:37.534Z (8 months ago)
- Topics: criteria, development, filtering, pattern, python, python3, python311, python312, python313, selection, sql, tools, utilities, validation
- Language: Python
- Homepage: https://pypi.org/project/criteria-pattern/
- Size: 138 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# 🤏🏻 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](#installation)
- [💻 Utilization](#utilization)
- [🤝 Contributing](#contributing)
- [🔑 License](#license)
## 📥 Installation
You can install **Criteria Pattern** using `pip`:
```bash
pip install criteria-pattern
```
## 💻 Utilization
```python
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, parameters = SqlConverter.convert(criteria=is_adult & (email_is_gmail | email_is_yahoo), table='user')
print(query)
print(parameters)
# >>> SELECT * FROM user WHERE (age >= %(parameter_0)s AND (email LIKE '%%' || %(parameter_1)s OR email LIKE '%%' || %(parameter_2)s));
# >>> {'parameter_0': 18, 'parameter_1': '@gmail.com', 'parameter_2': '@yahoo.com'}
```
## 🤝 Contributing
We welcome contributions to **Criteria Pattern**! To ensure a smooth collaboration process, please follow the guidelines below.
### How to Contribute
**1. Fork the Repository:** Click the "Fork" button at the top right of the repository page.
**2. Clone Your Fork:**
```bash
git clone git+ssh://git@github.com//criteria-pattern.git
```
**3. Create a Branch:**
```bash
git checkout -b feature/your-feature-name
```
**4. Make Your Changes:** Implement your new feature or fix a bug.
**5. Run Tests:** Ensure all the following tests pass before submitting your changes.
- Run tests:
```bash
make test
```
- Run tests with coverage:
```bash
make coverage
```
- Run linter:
```bash
make lint
```
- Run formatter:
```bash
make format
```
**6. Commit Your Changes:**
```bash
git commit -m "✨ feature: your feature description"
```
**7. Push to Your Fork:**
```bash
git push origin feature/your-feature-name
```
**8. Create a Pull Request:** Navigate to the original repository and create a pull request from your fork.
**9. Wait for Review:** Your pull request will be reviewed by the maintainers. Make any necessary changes based on their feedback.
## 🔑 License
This project is licensed under the terms of the [`MIT license`](https://github.com/adriamontoto/criteria-pattern/blob/master/LICENSE.md).