An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# 🤏🏻 Criteria Pattern



Test Pipeline


Lint Pipeline


Coverage Pipeline


Package Version


Supported Python Versions

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)


🔼 Back to top



## 📥 Installation

You can install **Criteria Pattern** using `pip`:

```bash
pip install criteria-pattern
```


🔼 Back to top



## 💻 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'}
```


🔼 Back to top



## 🤝 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.


🔼 Back to top



## 🔑 License

This project is licensed under the terms of the [`MIT license`](https://github.com/adriamontoto/criteria-pattern/blob/master/LICENSE.md).


🔼 Back to top