filterable_property#
Many popular ORM framework offers a popular feature that can use the following syntax to filter an iterable of object by its attributes. For example, in sqlalchemy you can use:
class User(Base):
name: str
select(User).where(User.name == "alice"))
This module implements the same feature.
- class s3pathlib.core.filterable_property.FilterableProperty(func: callable)[source]#
A descriptor decorator that convert a method to a property method. ALSO, convert the class attribute to be a comparable object that returns filter function for
IterProxy
to use.class User: def __init__(self, name: str): self.name = name @FilterableProperty def username(self) -> str: return self.name filter_function = User.username == "alice assert filter_function(User(name="alice")) == True assert filter_function(User(name="bob")) == False
- equal_to(other)[source]#
Return a filter function that returns True only if
FilterableType.attribute_name == ``other
New in version 1.0.3.
- not_equal_to(other)[source]#
Return a filter function that returns True only if
FilterableType.attribute_name != ``other
New in version 1.0.4.
- greater(other)[source]#
Return a filter function that returns True only if
FilterableType.attribute_name > ``other
New in version 1.0.4.
- less(other)[source]#
Return a filter function that returns True only if
FilterableType.attribute_name < ``other
New in version 1.0.4.
- greater_equal(other)[source]#
Return a filter function that returns True only if
FilterableType.attribute_name >= ``other
New in version 1.0.4.
- less_equal(other)[source]#
Return a filter function that returns True only if
FilterableType.attribute_name <= ``other
New in version 1.0.4.
- between(lower, upper)[source]#
Return a filter function that returns True only if
lower <= FilterableType.attribute_name <= upper
New in version 1.0.3.
- startswith(other: str)[source]#
Return a filter function that returns True only if
FilterableType.attribute_name.startswith(other)
. The attribute has to be a string attribute.New in version 1.0.3.