Skip to main content

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 WHERE clause 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);
    • SQLite (from phrase.dialect.sql.sqlite import F)
    • PostgreSQL (from phrase.dialect.sql.postgres import F)
    • MySQL / MariaDB (from phrase.dialect.sql.mysql import F)
    • Microsoft SQL Server (MSSQL) (from phrase.dialect.sql.mssql import F)
    • QGIS (Expression strings) (from phrase.dialect.sql.qgis import F)
  • 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


Download files

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

Source Distribution

pyphrase-0.1.0a2.tar.gz (43.5 kB view details)

Uploaded Source

Built Distribution

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

pyphrase-0.1.0a2-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

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

Hashes for pyphrase-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 043877e5d8922b7bf0d0198eb01e61b44e678533b0833fb0e3811df88e8093a9
MD5 b6974da610a46b3330f2f99842b78757
BLAKE2b-256 05281c40b28985c95afbc59fc580ecd2b3c2b91756be56421b554fee5468786d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyphrase-0.1.0a2.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-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

Hashes for pyphrase-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 901b504bb9d146c25995610dda9b422e397ee1aa5528f5cbb369943057ae806c
MD5 63eb5b0b5e59d6c30b2191180e128ea8
BLAKE2b-256 255c8a0246533d71a03ffec8378f4e98d61308ce935daba258e4493f296b624b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyphrase-0.1.0a2-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