
Security News
Cline CLI npm Package Compromised via Suspected Cache Poisoning Attack
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.
fastapi-sqlalchemy-query-builder
Advanced tools
A library for building SQLAlchemy queries with support for advanced filtering, sorting, text search, field and relationship selection, pagination, and model to Pydantic schema mapping
A library for building SQLAlchemy queries with support for advanced filtering, sorting, text search, field and relationship selection, pagination, and model to Pydantic schema mapping.
This approach gives you full control over the code, similar to shadcn/ui:
# Install the package
pip install fastapi-query-builder
# Initialize in your project (creates a local copy you can modify)
query-builder init
This will create a query_builder/ directory in your project with all the source code that you can customize as needed.
pip install fastapi-query-builder
Then import directly:
from query_builder import QueryBuilder, BaseService, BaseMapper, BaseUseCase
After running query-builder init, you'll have a local query_builder/ directory:
# Import from your local copy
from query_builder import QueryBuilder, BaseService, BaseMapper, BaseUseCase
from your_models import User
from your_schemas import UserCreate, UserUpdate, UserView
# Get relationship mapping dynamically
from query_builder.utils import get_dynamic_relations_map
relationship_map = get_dynamic_relations_map(User)
# Configure the service
user_service = BaseService(
model_class=User,
entity_name="user",
relationship_map=relationship_map,
generic_schema=UserView,
searchable_fields=["name", "email", "profile.bio"]
)
# Configure the mapper
user_mapper = BaseMapper(
model_class=User,
view_class=UserView,
entity_name="user",
relationship_map={
'profile': {
'mapper': profile_mapper.map_to_view,
'is_list': False,
'model_class': Profile
}
}
)
# Configure the use case
user_use_case = BaseUseCase(
service=user_service,
entity_name="user",
map_to_view=user_mapper.map_to_view,
map_list_to_view=user_mapper.map_list_to_view
)
# Initialize query_builder in your project
query-builder init
# Initialize in a custom directory
query-builder init --dir my_query_builder
# Update your local installation (preserves custom files)
query-builder update
from fastapi import APIRouter, Depends, Query
from starlette.datastructures import QueryParams
from query_builder import QueryBuilder
router = APIRouter()
query_builder = QueryBuilder()
@router.get("/users")
async def get_users(
db: Session = Depends(get_db),
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=1000),
search: Optional[str] = Query(None),
sort_by: Optional[str] = Query(None),
sort_dir: Optional[Literal["asc", "desc"]] = Query("asc"),
include: Optional[List[str]] = Query(None),
select_fields: Optional[str] = Query(None),
query_params: QueryParams = Depends()
):
# Parse filters from query parameters
filter_params = query_builder.parse_filters(query_params)
# Get users with all operations
result = await user_use_case.get_all(
db=db,
skip=skip,
limit=limit,
include=include,
filter_params=filter_params,
sort_by=sort_by,
sort_dir=sort_dir,
search=search,
select_fields=select_fields
)
return result
eq: Equal toneq: Not equal tolt: Less thanlte: Less than or equal togt: Greater thangte: Greater than or equal toin: Is in (list)notin: Is not in (list)like: Contains (case-sensitive)ilike: Contains (case-insensitive)isnull: Is null (true/false)contains: Contains substringstartswith: Starts withendswith: Ends withGET /users?filter[name][eq]=John
GET /users?filter[age][gte]=18&filter[age][lt]=65
GET /users?filter[email][ilike]=@gmail.com
GET /users?filter[status][in]=active,inactive
GET /users?filter[profile.bio][contains]=developer
GET /users?select=id,name,email
GET /users?select=id,name,[profile],[roles]
GET /users?select=id,name,profile.bio,roles.name
GET /users?select=id,name,profile.bio,[roles].name
Since you have the source code locally, you can:
# In your local query_builder/core/filter_parser.py
OPERATOR_MAP = {
# ... existing operators ...
'regex': lambda c, v: c.op('~')(v), # Add regex support
'date_range': lambda c, v: c.between(v[0], v[1]), # Add date range
}
When a new version is released:
# Update the package
pip install --upgrade fastapi-query-builder
# Update your local copy (preserves customizations)
query-builder update
The update command will:
After initialization, your project will have:
your-project/
├── query_builder/ # Local copy (customizable)
│ ├── core/ # Core parsers
│ ├── base_classes/ # Base classes
│ ├── utils/ # Utilities
│ ├── exceptions/ # Custom exceptions
│ ├── examples/ # Usage examples
│ └── example_usage.py # Generated example
├── your_app/
└── requirements.txt
MIT License - see LICENSE file for details.
FAQs
A library for building SQLAlchemy queries with support for advanced filtering, sorting, text search, field and relationship selection, pagination, and model to Pydantic schema mapping
We found that fastapi-sqlalchemy-query-builder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.

Product
Socket is now scanning AI agent skills across multiple languages and ecosystems, detecting malicious behavior before developers install, starting with skills.sh's 60,000+ skills.

Product
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.