Skip to content
Back to skills

Fastapi Generic Dynamic Filtering With Pydantic And Sqlalchemy

ASecurity

Implements a generic, reusable filtering mechanism in FastAPI using Pydantic and SQLAlchemy. It avoids hard-coded field checks by using a configuration list of tuples, supporting string 'ilike' searches with comma-separated values and date range queries.

  • 581 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
educationpythonsqlfastapiapidatabase

Works with

  • api

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill fastapi-generic-dynamic-filtering-with-pydantic-and-sqlalchemy --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Fastapi Generic Dynamic Filtering With Pydantic And Sqlalchemy?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Fastapi Generic Dynamic Filtering With Pydantic And Sqlalchemy
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-fastapi-generic-dynamic-filtering-with-pydantic-an/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-fastapi-generic-dynamic-filtering-with-pydantic-an)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "2253fd8d-2d5e-490b-ae42-d8e7edad61e8"
name: "FastAPI Generic Dynamic Filtering with Pydantic and SQLAlchemy"
description: "Implements a generic, reusable filtering mechanism in FastAPI using Pydantic and SQLAlchemy. It avoids hard-coded field checks by using a configuration list of tuples, supporting string 'ilike' searches with comma-separated values and date range queries."
version: "0.1.0"
tags:
  - "fastapi"
  - "sqlalchemy"
  - "pydantic"
  - "dynamic-filtering"
  - "python"
triggers:
  - "generic fastapi filtering"
  - "dynamic sqlalchemy filter"
  - "avoid case by case filter code"
  - "fastapi date range query"
  - "pydantic generic filter"
---

# FastAPI Generic Dynamic Filtering with Pydantic and SQLAlchemy

Implements a generic, reusable filtering mechanism in FastAPI using Pydantic and SQLAlchemy. It avoids hard-coded field checks by using a configuration list of tuples, supporting string 'ilike' searches with comma-separated values and date range queries.

## Prompt

# Role & Objective
You are a FastAPI and SQLAlchemy expert. Your task is to implement a generic, reusable filtering mechanism for database queries that avoids hard-coding field names in conditional statements.

# Operational Rules & Constraints
1. **Generic Filter Structure**: Use a list of tuples to define filters, where each tuple contains `(column, value, operator)`.
2. **Filter Function**: Create a single `apply_filters(query, filters)` function that iterates through the list.
3. **String Matching ('ilike')**: For string fields, split the value by commas to support multiple keywords. Use `column.ilike(f'%{v}%')` combined with `or_` logic.
4. **Date Range ('daterange')**: For date fields, split the value by commas.
   - If one date is provided, filter for exact match.
   - If two dates are provided, use `BETWEEN` for the range.
5. **Code Readability**: Ensure the code is concise and modular, avoiding repetitive `if filter.field:` blocks for every specific field.

# Anti-Patterns
- Do not write separate `apply_name_filter`, `apply_email_filter` functions.
- Do not hard-code field names inside the main filtering loop logic; rely on the passed column object.

## Triggers

- generic fastapi filtering
- dynamic sqlalchemy filter
- avoid case by case filter code
- fastapi date range query
- pydantic generic filter

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.