Small implementation of a filter criteria pattern in Python for Complex Heart SDK. Compose several filters using fluent interface.
Just install the package from PyPI using pip:
pip install complexheart-criteria
or using poetry:
poetry add complexheart-criteria
Just import the package and use the Criteria
class:
from complexheart.domain.criteria import Criteria, Filter, Order, Page
criteria = Criteria(
[Filter.gte('age', 18), Filter.eq('name', 'Vincent')],
Order.desc(['name', 'surname']),
Page(10, 10)
)
# once is instantiated you can use it as a normal object in your repositories.
customers = customer_repository.match(criteria)
Alternatively, you can use the fluent interface to build the Criteria
object:
from complexheart.domain.criteria import Criteria, Filter, Order, Page
criteria = Criteria()
criteria.filter('age', '>=', 18)
criteria.filter('name', '==', 'Vincent')
criteria.order_by(['name', 'surname'], 'DESC')
criteria.limit(10)
criteria.offset(10)
# once is instantiated you can use it as a normal object in your repositories.
customers = customer_repository.match(criteria)