agentsclimarketplace

Fastapi generic dynamic filtering with pydantic and sqlalchemy

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/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.From its SKILL.md

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

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.3 KB, 366 tokens by cl100k_base, as published. Nobody here has run it

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

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.