
Product
Socket Brings Supply Chain Security to skills.sh
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.
query-builder-sql-alchemy
Advanced tools
A flexible SQL query builder for SQLAlchemy ORM models that makes it easy to build complex SQL queries using a fluent interface.
Using pip:
pip install query-builder-sql-alchemy
Using Poetry:
poetry add query-builder-sql-alchemy
from QueryBuilderSqlAlchemy import QueryBuilder, Condition, ConditionGroup, Operator
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
# Define your SQLAlchemy model
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
email = Column(String)
# Create a query builder
qb = QueryBuilder()
# Build a simple query
query = (qb
.select([User.id, User.name])
.from_table(User)
.where(Condition(User.name, Operator.LIKE, 'John%'))
.limit(10)
.build())
print(query)
# Output: SELECT `users`.`id`, `users`.`name` FROM `users` WHERE `users`.`name` LIKE 'John%' LIMIT 10
# Using AND/OR conditions
query = (qb
.select([User.id, User.name, User.email])
.from_table(User)
.where(
ConditionGroup([
Condition(User.name, Operator.LIKE, 'John%'),
Condition(User.email, Operator.LIKE, '%@gmail.com')
], 'AND')
)
.build())
class Post(Base):
__tablename__ = 'posts'
id = Column(Integer, primary_key=True)
user_id = Column(Integer)
title = Column(String)
# Join query
query = (qb
.select([User.name, Post.title])
.from_table(User)
.join(User.id, Post.user_id)
.build())
query = (qb
.select([(User.id, 'COUNT')])
.from_table(User)
.where(Condition(User.name, Operator.LIKE, 'John%'))
.build())
EQ: Equals (=)NE: Not Equals (<>)LT: Less Than (<)LE: Less Than or Equal (<=)GT: Greater Than (>)GE: Greater Than or Equal (>=)LIKE: LIKE operatorBETWEEN: Between two valuesIN: IN operatorContributions are welcome! Please feel free to submit a Pull Request.
MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please file an issue on the GitHub repository.
FAQs
A flexible SQL query builder for SQLAlchemy ORM models.
We found that query-builder-sql-alchemy 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.

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.

Security News
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.