Skip to content

Implementation of Criteria patterns in Python for Complex Heart SDK.

License

Notifications You must be signed in to change notification settings

ComplexHeart/py-criteria

Repository files navigation

Criteria (a.k.a Filter)

Test Quality Gate Status Coverage

Small implementation of a filter criteria pattern in Python for Complex Heart SDK. Compose several filters using fluent interface.

Installation

Just install the package from PyPI using pip:

pip install complexheart-criteria

or using poetry:

poetry add complexheart-criteria

Usage

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)