Skip to main content

PyPhrase 🗣️

PyPhrase 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 PyPhrase?

Most query builders are either tied to a specific database or come with heavy dependencies. PyPhrase 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 WHERE clause logic), not managing connections or migrations.

🛠 Supported Dialects

PyPhrase currently compiles expressions for:

  • SQL
    • Generic (from pyphrase.dialects.sql import F);
    • SQLite (from pyphrase.dialect.sql.sqlite import F)
    • PostgreSQL (from pyphrase.dialect.sql.postgres import F)
    • MySQL / MariaDB (from pyphrase.dialect.sql.mysql import F)
    • Microsoft SQL Server (MSSQL) (from pyphrase.dialect.sql.mssql import F)
    • QGIS (Expression strings) (from pyphrase.dialect.sql.qgis import F)
  • MongoDB (from pyphrase.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.10+

⚖️ License

MIT License. See LICENSE for details.

Metadata

Release files for pyphrase 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyphrase 1.0.0
File Size Uploaded Provenance Actions
pyphrase-1.0.0.tar.gz 76.8 kB With provenance Details for pyphrase-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyphrase 1.0.0
File Interpreter ABI Platform Actions
pyphrase-1.0.0-py3-none-any.whl Python 3 none any Details for pyphrase-1.0.0-py3-none-any.whl

Total release size: 98.6 kB

Release files / pyphrase-1.0.0.tar.gz

Download URL pyphrase-1.0.0.tar.gz
Size 76.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fa9cb3be525645750e553d8b827e5a6092443c8cbb3dc5cbf8ee6f0b631204b9
BLAKE2b-256 checksum
How to use checksums
7cd24a9e09a7c37161852aee34d83b95e308654b6e3e39d0e34d6ba98f3ec10c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 30, 2026.

Transparency log

Release files / pyphrase-1.0.0-py3-none-any.whl

Download URL pyphrase-1.0.0-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6857d1858c7ef13423cefbe6315015a5432daa31e6a416420e97dbbd3823c2bd
BLAKE2b-256 checksum
How to use checksums
700daa6acfe1ba0a2fd018dc32b5d236ccb9e23e59f6b2c61decab331f183c0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 30, 2026.

Transparency log

Security for pyphrase 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyphrase-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page