Skip to main content

lumi_filter

For specific use cases, please refer to the examples: Examples

lumi_filter is a powerful and flexible data filtering library designed to simplify how you filter and sort data across different data sources in your Python applications. Whether you're dealing with database queries, API responses, or in-memory data structures, lumi_filter provides a unified, intuitive interface that makes complex filtering operations effortless. Inspired by Django REST Framework's filtering system, lumi_filter has been redesigned to support multiple backends and data sources. Flask-friendly and compatible.

lumi_filter is a model-based filtering library that bridges the gap between different data sources and filtering needs. At its core, it provides a consistent API for filtering the following data sources:

  • Peewee ORM queries - Direct database filtering through automatic SQL generation
  • Pydantic models - Filter structured data with type validation
  • Iterable data structures - Filter lists, dictionaries, and other Python collections

This library eliminates the need to write different filtering logic for each data source, allowing you to define filtering requirements once and apply them universally.

Why Choose lumi_filter?

Unified Filtering Interface

Suppose you need to implement filtering functionality throughout your application that needs to handle both database records and API responses. Without lumi_filter, you would typically need to write separate filtering logic for each data source:

Database Filtering (Peewee)

query = Product.select().where(Product.name.contains("apple") & Product.price >= 100)

List Filtering (Python)

filtered_products = [p for p in products if "apple" in p["name"] and p["price"] >= 100]

With lumi_filter, you define the filtering model once and use it everywhere:

class FilterProduct(Model):
    name = StrField(source="name")
    price = DecimalField(source="price")

For Database Queries

db_filter = FilterProduct(Product.select(), request.args)
filtered_query = db_filter.filter().result()

For Iterable Data

list_filter = FilterProduct(products_list, request.args)
filtered_list = list_filter.filter().result()

Rich Filtering Expressions

lumi_filter supports a comprehensive set of filtering operators that go beyond simple equality checks:

Operator Description Example
(none) Exact match name=Apple
__in In value list name__in=Apple,Orange
__nin Not in value list name__nin=Apple,Orange
__gte Greater than or equal price__gte=100
__lte Less than or equal price__lte=500
__contains Contains substring name__contains=apple
__startswith Starts with name__startswith=A
__endswith Ends with name__endswith=e

Automatic Type Detection and Mapping

The library intelligently detects field types and maps them to appropriate filter fields, supporting:

  • String fields with pattern matching
  • Numeric fields with range comparisons
  • Date/time fields with temporal filtering
  • Boolean fields with truthiness filtering
  • Nested fields with dot notation support

TODO

  • Support for pagination
  • Field-level permission control
  • Field-level custom filtering
  • Support for more ORMs (e.g., SQLAlchemy)

Metadata

Release files for lumi-filter 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lumi-filter 0.2.0
File Size Uploaded
lumi_filter-0.2.0.tar.gz 75.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lumi-filter 0.2.0
File Interpreter ABI Platform
lumi_filter-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 91.6 kB

Release files / lumi_filter-0.2.0.tar.gz

Download URL lumi_filter-0.2.0.tar.gz
Size 75.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a1e65de724d952df3ce0a960be6bb5fa80c94198b5b8de1dbe88a848070dca27
BLAKE2b-256 checksum
How to use checksums
08309bc505f7145d842f796a40dcc44c1d256c0cd7ecd73e96cc71c6a6430eec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.0

Release files / lumi_filter-0.2.0-py3-none-any.whl

Download URL lumi_filter-0.2.0-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab3574a61b8676ee2a0aa93735b0a85f9824c2e6cefebf96f22b183752d53748
BLAKE2b-256 checksum
How to use checksums
647242162c4903e8493ebc1e02a2aff456d63b08e0dd0d2b97b96fe1c104ea56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page