magic-filter is a lightweight Python library designed to simplify conditional logic, particularly useful in event-driven programming like Telegram bots (e.g., aiogram). It provides a fluent, declarative syntax for building complex filtering expressions using the `F` object, allowing developers to write more readable and concise conditions. It is currently at version 1.0.12 and sees active, though not strictly regular, development with several minor releases annually.
pip install magic-filterVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define and apply simple and complex filters using the `F` object. It shows attribute access, method calls, logical operators (`&`, `|`, `~`), and how to use `magic-filter` with dictionaries and lists.
Update logic to check for `None` or handle both `None` and `False` if maintaining compatibility with older versions.
Always use explicit comparison or function calls for conditional logic (e.g., `if F.attribute == 'value':` or `if some_filter(data):`) instead of relying on implicit boolean conversion of the filter object itself.
Remove any code attempting to iterate over `F` objects. `magic-filter` is designed for building conditions, not for direct iteration.
Be aware that errors from underlying data access or method calls are now absorbed. If you rely on such errors for debugging or specific error handling, you might need to pre-validate data or use explicit checks before applying `magic-filter` conditions.
Access the intended attribute (e.g., `F.text`) before calling the method. For example, use `F.text.startswith('your_prefix')`.Do not attempt to call `F` as a function. Instead, use its attributes and operators (e.g., `F.text`, `F.text == 'value'`) to construct filter expressions.
Ensure that `F` is imported with the correct uppercase 'F': `from magic_filter import F`.
Use `F` with comparison operators (e.g., `F.text == 'value'`) or access its attributes (e.g., `F.is_something`) to create a boolean expression; do not use `F` directly in an `if` statement.
No dependency data recorded yet.