A lightweight, zero-dependency syntax builder for multiple dialects.
Project description
Phrase 🗣️
Phrase is an ultra-lightweight, zero-dependency Python library designed to build query expressions across multiple dialects with ease. It provides a fluent, Pythonic interface for generating WHERE clauses and filter objects without the overhead of a full ORM.
🚀 Why Phrase?
Most query builders are either tied to a specific database or come with heavy dependencies. Phrase was created for cases where you need:
- Minimalism: Zero external dependencies. Small footprint.
- Multi-dialect support: One syntax to rule them all (SQL & NoSQL).
- Simplicity: Focused specifically on building filter expressions (the
WHEREclause logic), not managing connections or migrations.
[!WARNING] Security Notice: Phrase is designed for internal logic and programmatic query generation. It does not perform extensive escaping or sanitization. It is not intended to process raw, untrusted user input from public-facing forms without additional security layers.
🛠 Supported Dialects
Phrase currently compiles expressions for:
- SQL
-
- Generic (
from phrase.dialects.sql import F);
- Generic (
-
- SQLite (
from phrase.dialect.sql.sqlite import F)
- SQLite (
-
- PostgreSQL (
from phrase.dialect.sql.postgres import F)
- PostgreSQL (
-
- MySQL / MariaDB (
from phrase.dialect.sql.mysql import F)
- MySQL / MariaDB (
-
- Microsoft SQL Server (MSSQL) (
from phrase.dialect.sql.mssql import F)
- Microsoft SQL Server (MSSQL) (
-
- QGIS (Expression strings) (
from phrase.dialect.sql.qgis import F)
- QGIS (Expression strings) (
- MongoDB (
from phrase.dialect.mongodb import F)
📖 Usage Examples
The core of the library is the F (Field) expression.
Basic Comparison
from pyphrase.dialect.<your-dialect-here> import F
# Simple equality
expr = F("age") >= 18
Complex Logic
You can combine expressions using standard Python operators:
&for AND|for OR~for NOT
expr = (F("status") == "active") & (F("price") < 1000) | (F("category") == None)
🏗 Compiling to Results
Because different dialects return different types (Strings for SQL, Dictionaries for MongoDB), the output method depends on the target.
1. SQL Dialects
For SQL-based engines, simply casting the compiled expression to a string gives you the result. Python
>> > from pyphrase.dialect.sql import F
>> > # expr ... see above
>> > str(expr)
>> > '(("status" = \'active\') AND ("price" < 1000)) OR ("category" IS NULL)'
2. MongoDB
Since MongoDB filters are represented as BSON (Python dictionaries), use the .compile() method directly. Python
>> > from pyphrase.dialect.mongodb import F
>>> # expr ... see above
>>> expr.compile()
>>> {'$or': [{'$and': [{'status': 'active'}, {'price': {'$lt': 1000}}]}, {'category': None}]}
🧪 Installation
pip install pyphrase
Note: Requires Python 3.14+
⚖️ License
MIT License. See LICENSE for details.
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 pyphrase-0.1.0a2.tar.gz.
File metadata
- Download URL: pyphrase-0.1.0a2.tar.gz
- Upload date:
- Size: 43.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
043877e5d8922b7bf0d0198eb01e61b44e678533b0833fb0e3811df88e8093a9
|
|
| MD5 |
b6974da610a46b3330f2f99842b78757
|
|
| BLAKE2b-256 |
05281c40b28985c95afbc59fc580ecd2b3c2b91756be56421b554fee5468786d
|
Provenance
The following attestation bundles were made for pyphrase-0.1.0a2.tar.gz:
Publisher:
release.yml on ygavenchuk/phrase
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyphrase-0.1.0a2.tar.gz -
Subject digest:
043877e5d8922b7bf0d0198eb01e61b44e678533b0833fb0e3811df88e8093a9 - Sigstore transparency entry: 1496714115
- Sigstore integration time:
-
Permalink:
ygavenchuk/phrase@727fa4a4a778970f692ea08934eb2a17c157b1c1 -
Branch / Tag:
refs/tags/v0.1.0a2 - Owner: https://github.com/ygavenchuk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@727fa4a4a778970f692ea08934eb2a17c157b1c1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyphrase-0.1.0a2-py3-none-any.whl.
File metadata
- Download URL: pyphrase-0.1.0a2-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
901b504bb9d146c25995610dda9b422e397ee1aa5528f5cbb369943057ae806c
|
|
| MD5 |
63eb5b0b5e59d6c30b2191180e128ea8
|
|
| BLAKE2b-256 |
255c8a0246533d71a03ffec8378f4e98d61308ce935daba258e4493f296b624b
|
Provenance
The following attestation bundles were made for pyphrase-0.1.0a2-py3-none-any.whl:
Publisher:
release.yml on ygavenchuk/phrase
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyphrase-0.1.0a2-py3-none-any.whl -
Subject digest:
901b504bb9d146c25995610dda9b422e397ee1aa5528f5cbb369943057ae806c - Sigstore transparency entry: 1496714238
- Sigstore integration time:
-
Permalink:
ygavenchuk/phrase@727fa4a4a778970f692ea08934eb2a17c157b1c1 -
Branch / Tag:
refs/tags/v0.1.0a2 - Owner: https://github.com/ygavenchuk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@727fa4a4a778970f692ea08934eb2a17c157b1c1 -
Trigger Event:
release
-
Statement type: