Skip to main content

A lightweight, zero-dependency syntax builder for multiple dialects.

Project description

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.

[!WARNING] Security Notice: PyPhrase 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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyphrase-1.0.0.tar.gz (76.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyphrase-1.0.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file pyphrase-1.0.0.tar.gz.

File metadata

  • Download URL: pyphrase-1.0.0.tar.gz
  • Upload date:
  • Size: 76.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyphrase-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fa9cb3be525645750e553d8b827e5a6092443c8cbb3dc5cbf8ee6f0b631204b9
MD5 e20d9349cd98e1404989ca671b8f2068
BLAKE2b-256 7cd24a9e09a7c37161852aee34d83b95e308654b6e3e39d0e34d6ba98f3ec10c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyphrase-1.0.0.tar.gz:

Publisher: release.yml on ygavenchuk/phrase

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyphrase-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyphrase-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyphrase-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6857d1858c7ef13423cefbe6315015a5432daa31e6a416420e97dbbd3823c2bd
MD5 f2d7b12fbce2d385b09ea508daa0090c
BLAKE2b-256 700daa6acfe1ba0a2fd018dc32b5d236ccb9e23e59f6b2c61decab331f183c0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyphrase-1.0.0-py3-none-any.whl:

Publisher: release.yml on ygavenchuk/phrase

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page