SQL Query Builder
Project description
QuickQL
A fluent SQL query builder for Python that makes it easy to construct complex SQL queries programmatically.
Features
- ๐ Fluent Interface: Build queries using method chaining
- ๐ Comprehensive SQL Support: SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, WITH (CTEs)
- ๐ฏ Type-Safe: Built with type hints for better IDE support
- ๐งช Well Tested: Comprehensive test suite with >95% coverage
- ๐ง Python 3.7+: Supports Python 3.7 and above
- ๐ฆ Zero Dependencies: No external dependencies in production
Installation
# Using uv (recommended)
uv add quickql
# Using pip
pip install quickql
Quick Start
from quickql import Query
# Simple SELECT query
query = Query().SELECT("name", "email").FROM("users").WHERE("active = 1")
print(query)
Output:
SELECT
name, email
FROM
users
WHERE
active = 1
Advanced Usage
Complex Queries with JOINs
query = (Query()
.SELECT("u.name", "u.email", "p.title")
.FROM("users u")
.add("LEFT JOIN", "posts p ON u.id = p.user_id")
.WHERE("u.active = 1")
.WHERE("p.published = 1")
.ORDER_BY("u.name")
.LIMIT("10"))
Using Common Table Expressions (CTEs)
cte_query = """
SELECT user_id, COUNT(*) as post_count
FROM posts
WHERE created_at > '2023-01-01'
GROUP BY user_id
"""
query = (Query()
.WITH(("active_posters", cte_query))
.SELECT("u.name", "ap.post_count")
.FROM("users u")
.add("JOIN", "active_posters ap ON u.id = ap.user_id")
.ORDER_BY("ap.post_count DESC"))
Aggregate Queries
query = (Query()
.SELECT("department", "COUNT(*) as employee_count", "AVG(salary) as avg_salary")
.FROM("employees")
.WHERE("active = 1")
.GROUP_BY("department")
.HAVING("COUNT(*) > 5")
.ORDER_BY("avg_salary DESC"))
Development
Prerequisites
- Python 3.7+
- uv (recommended) or pip
Setup Development Environment
# Clone the repository
git clone https://github.com/yourusername/quickql.git
cd quickql
# Run the setup script (installs dependencies and runs tests)
python setup_dev.py
# Or manually with uv
uv venv
uv pip install -e ".[dev]"
Running Tests
# Run all tests
uv run pytest tests/ -v
# Run with coverage
uv run pytest tests/ --cov=src --cov-report=html
# Run specific test categories
python run_tests.py basic # Basic functionality tests
python run_tests.py building # Query building tests
python run_tests.py edge # Edge case tests
python run_tests.py integration # Integration tests
python run_tests.py coverage # Tests with coverage report
Code Quality
This project uses Ruff for linting and formatting:
# Check code quality
uv run ruff check .
# Format code
uv run ruff format .
# Check formatting without changing files
uv run ruff format --check .
Project Structure
quickql/
โโโ src/
โ โโโ quickql/
โ โโโ __init__.py # Package exports
โ โโโ builder.py # Main Query builder
โโโ tests/
โ โโโ __init__.py
โ โโโ conftest.py # Test fixtures
โ โโโ test_query_basic.py # Basic functionality tests
โ โโโ test_query_building.py # Query building tests
โ โโโ test_edge_cases.py # Edge cases and error handling
โ โโโ test_integration.py # Integration tests
โโโ .github/
โ โโโ workflows/
โ โโโ ci.yml # GitHub Actions CI
โโโ pyproject.toml # Project configuration
โโโ setup_dev.py # Development setup script
โโโ run_tests.py # Test runner script
โโโ README.md
API Reference
Query Class
The main Query class provides a fluent interface for building SQL queries.
Methods
SELECT(*columns)- Add columns to SELECT clauseFROM(*tables)- Add tables to FROM clauseWHERE(condition)- Add WHERE conditions (chained with AND)GROUP_BY(*columns)- Add GROUP BY columnsHAVING(condition)- Add HAVING conditions (chained with AND)ORDER_BY(*columns)- Add ORDER BY columnsLIMIT(limit)- Add LIMIT clauseWITH((name, query))- Add Common Table Expressionadd(clause, *args)- Generic method to add any clause
JOIN Operations
Use the add() method for JOINs:
query.add("INNER JOIN", "table2 ON table1.id = table2.foreign_id")
query.add("LEFT JOIN", "table3 ON table1.id = table3.foreign_id")
query.add("RIGHT JOIN", "table4 ON table1.id = table4.foreign_id")
query.add("FULL JOIN", "table5 ON table1.id = table5.foreign_id")
Flags
Some clauses support flags:
query.add("SELECT DISTINCT", "column") # SELECT DISTINCT
query.add("SELECT ALL", "column") # SELECT ALL
Releasing
Creating Releases
This project uses automated PyPI publishing via GitHub Actions. To create a release:
# Verify the build works
python verify_build.py
# Create a release (this will trigger PyPI publishing)
python release.py 0.1.1
# Or create a release candidate (publishes to TestPyPI)
python release.py 0.2.0rc1
The release process:
- Updates version in
pyproject.toml - Creates a git tag
- Pushes the tag to GitHub
- GitHub Actions automatically builds and publishes to PyPI
- Creates a GitHub release with signed artifacts
For detailed setup instructions, see PUBLISHING.md.
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
python run_tests.py all) - Run code quality checks (
uv run ruff check . && uv run ruff format --check .) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
v0.1.0 (Initial Release)
- Fluent query builder interface
- Support for all major SQL clauses
- JOIN operations support
- Common Table Expressions (WITH)
- Comprehensive test suite
- Python 3.7+ support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quickql-0.1.0.tar.gz.
File metadata
- Download URL: quickql-0.1.0.tar.gz
- Upload date:
- Size: 48.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dd175f805ae260b26187420a4160d2aa511ea99be1339d973667c41c248f6b0
|
|
| MD5 |
06bd8266e7a12c4b2699950117ded54e
|
|
| BLAKE2b-256 |
31415c70a587a0de35bc26b39e8d7355cc8718fcc6afb7e32d0d2f2c97b4c519
|
Provenance
The following attestation bundles were made for quickql-0.1.0.tar.gz:
Publisher:
ci.yml on arunksoman/QuickQL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quickql-0.1.0.tar.gz -
Subject digest:
1dd175f805ae260b26187420a4160d2aa511ea99be1339d973667c41c248f6b0 - Sigstore transparency entry: 731887391
- Sigstore integration time:
-
Permalink:
arunksoman/QuickQL@3167d5cd7fd00f79b1fa58f39638ac59ff3945a0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/arunksoman
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@3167d5cd7fd00f79b1fa58f39638ac59ff3945a0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file quickql-0.1.0-py3-none-any.whl.
File metadata
- Download URL: quickql-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbe99d7e413dee926528f8cf576f3a088aed110acac9b2e3667dfcefb336d488
|
|
| MD5 |
a16b52d2fd0ac70bca8f37373e26f964
|
|
| BLAKE2b-256 |
51cec46b505013acf9913d628d5ea0fa7351580df2cca72966393a1ffaf78744
|
Provenance
The following attestation bundles were made for quickql-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on arunksoman/QuickQL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quickql-0.1.0-py3-none-any.whl -
Subject digest:
cbe99d7e413dee926528f8cf576f3a088aed110acac9b2e3667dfcefb336d488 - Sigstore transparency entry: 731887394
- Sigstore integration time:
-
Permalink:
arunksoman/QuickQL@3167d5cd7fd00f79b1fa58f39638ac59ff3945a0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/arunksoman
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@3167d5cd7fd00f79b1fa58f39638ac59ff3945a0 -
Trigger Event:
push
-
Statement type: