Skip to main content

A powerful and flexible data filtering library with unified interface for multiple data sources

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lumi_filter-0.2.0.tar.gz (75.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lumi_filter-0.2.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file lumi_filter-0.2.0.tar.gz.

File metadata

  • Download URL: lumi_filter-0.2.0.tar.gz
  • Upload date:
  • Size: 75.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for lumi_filter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a1e65de724d952df3ce0a960be6bb5fa80c94198b5b8de1dbe88a848070dca27
MD5 8e46f561ba5673174924496e70893050
BLAKE2b-256 08309bc505f7145d842f796a40dcc44c1d256c0cd7ecd73e96cc71c6a6430eec

See more details on using hashes here.

File details

Details for the file lumi_filter-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lumi_filter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab3574a61b8676ee2a0aa93735b0a85f9824c2e6cefebf96f22b183752d53748
MD5 96d0ad3fb978dffb5199e43e6aa53352
BLAKE2b-256 647242162c4903e8493ebc1e02a2aff456d63b08e0dd0d2b97b96fe1c104ea56

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page