Skip to main content

☕ CoffeeQL

One syntax. Any database.

PyPI version License: MIT pip package

CoffeeQL is a universal query orchestration layer. Write one expressive, chain-based query and run it seamlessly across PostgreSQL, MongoDB, MySQL, and Redis.
Powered by a blazing-fast Rust parse-and-plan engine, executed natively via Python async adapters.

Website • npm • pip (PyPI)


✨ Why CoffeeQL?

Most modern applications talk to three or more databases. You end up writing raw SQL for Postgres, pymongo pipelines for MongoDB, and redis-py commands for Redis battling different APIs, error handling paradigms, and mental models.

CoffeeQL abstracts this friction. It provides one unified syntax that compiles down to the exact query required for each underlying database, with a zero-copy Rust engine handling the heavy lifting of parsing and query planning.

📦 Installation

Install the core package via pip or include specific database adapters:

pip install coffeeql
pip install coffeeql[postgres]   # asyncpg
pip install coffeeql[mongodb]    # motor
pip install coffeeql[mysql]      # aiomysql
pip install coffeeql[redis]      # redis-py

# Or install everything at once
pip install coffeeql[all]        

📖 The Syntax

CoffeeQL uses a highly readable, chain-based syntax designed to feel natural.

Syntax Meaning Target Database
users[] Table PostgreSQL / MySQL
products{} Collection MongoDB
session:id{} Hash Key Redis
.where(...) Filter / Condition All
.give(...) Select specific fields All
.sort(field, DESC) Order by All
.cup(10) Limit results All
.blend(field) Group by All
.mix(... ON ...) Join / Cross-DB Federation All
.pour({...}) Insert All
.refill({...}) Update All
.spill() Delete All

🚀 Quick Start (FastAPI Example)

CoffeeQL integrates beautifully into asynchronous Python stacks like FastAPI.

from fastapi import FastAPI
from coffeeql import CoffeeQL, PostgresAdapter, MongoAdapter

app = FastAPI()

# Initialize unified orchestration
db = CoffeeQL({
    'users[]':    PostgresAdapter(uri='postgresql://user:pass@localhost/mydb'),
    'products{}': MongoAdapter(uri='mongodb://localhost:27017', db='shop'),
})

@app.on_event('startup')
async def startup():
    await db.connect()

@app.get('/users')
async def get_users():
    result = await db.query('''
        users[]
            .where(plan = "pro", active = true)
            .give(name, email, balance)
            .sort(balance, DESC)
            .cup(20)
    ''').run()
    return result.rows

Because CoffeeQL queries across multiple architectures, testing locally is easiest with a unified container stack. You can spin up Postgres, Mongo, and Redis instantly using a standard docker-compose.yml to test your cross-database joins natively before pushing to production via pip.


🧠 Advanced Features

Cross-Database Federation (Experimental)

Join a PostgreSQL table with a MongoDB collection in memory, automatically handled by the engine.

@app.get('/dashboard')
async def dashboard():
    result = await db.query('''
        users[]
            .where(active = true)
            .mix(products{} ON users[].id = products{}.user_id)
            .give(users[].name, products[].title, products[].price)
            .sort(products[].price, DESC)
            .cup(10)
    ''').run()
    return result.rows

Resiliency: Timeout, Retry, & Partial States

Built for the real world, where networks drop and databases stall.

# Fail fast if a DB is slow
await db.query('users[].cup(100)').timeout(3000).run()

# Retry on flaky connections
await db.query('products{}.where(active = true)').retry(3).run()

# Accept partial results if a federated node goes down
await db.query('users[].mix(products{} ON ...)').partial().run()

Explain & Validate (Zero Dependencies)

Inspect execution plans without making a single database call.

from coffeeql import explain

plan = explain('''
    users[]
        .where(plan = "pro")
        .mix(products{} ON users[].id = products{}.user_id)
        .cup(10)
''')
print(plan.rendered)

Output:

# CoffeeQL Execution Plan
#   Step 1 → PostgreSQL   SCAN    users[]       WHERE plan='pro'
#   Step 2 → MongoDB      SCAN    products{}
#   Step 3 → Memory       HASH JOIN              ON users[].id = products{}.user_id
#   Step 4 → Memory       LIMIT   10
#
#   Adapters: 2  ·  Strategy: in-memory hash join  ·  Concurrent fetch: yes

🏗️ Architecture Layer

The Rust core is the exact same engine that powers the npm package guaranteeing 100% parity across languages for parsing, planning, and explain outputs.

graph TD;
    A[Your CoffeeQL Query] -->|String| B(Rust Engine via PyO3);
    B -->|Parse & Plan - Fast, Zero-Copy| C(Python Execution Layer);
    C -->|Reads Plan| D{Native Async Adapters};
    D -->|asyncpg| E[(PostgreSQL)];
    D -->|motor| F[(MongoDB)];
    D -->|aiomysql| G[(MySQL)];
    D -->|redis-py| H[(Redis)];
    E & F & G & H --> I[Real Rows Returned];

📦 What's in v0.3.0

  • coffeeql.parse() → Parse and validate any CoffeeQL query.
  • coffeeql.is_valid() → Boolean validation.
  • coffeeql.explain() → Human-readable execution plan.
  • CoffeeQL class → Core client for connect, query, and explain.
  • All 4 adapters stable: PostgreSQL, MongoDB, MySQL, Redis.
  • .timeout(), .retry(), .partial() resilience modifiers.
  • Cross-adapter federation (Experimental).

🤝 Contributing & issues

CoffeeQL is an open-source initiative released under the MIT License. We welcome contributions from the community to help expand our adapter ecosystem and refine the engine.

Metadata

Release files for coffeeql 0.4.1

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

Built distributions (wheels)

Table of built distributions (wheels) for coffeeql 0.4.1
File Interpreter ABI Platform Actions
coffeeql-0.4.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for coffeeql-0.4.1-cp39-abi3-win_amd64.whl
coffeeql-0.4.1-cp39-abi3-manylinux_2_31_x86_64.whl CPython 3.9 abi3 Linux glibc 2.31+ x86-64 Details for coffeeql-0.4.1-cp39-abi3-manylinux_2_31_x86_64.whl
coffeeql-0.4.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.9 abi3 macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64 Details for coffeeql-0.4.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Total release size: 1.5 MB

Release files / coffeeql-0.4.1-cp39-abi3-win_amd64.whl

Download URL coffeeql-0.4.1-cp39-abi3-win_amd64.whl
Size 295.3 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d555eaf835cb7ed1e81a5acc1950523724aae9b88685c17b4fa7ca7c36451736
BLAKE2b-256 checksum
How to use checksums
6776962ff89f8dadeaf2ef26164d941d53123f3079d0c5711a4b7369cfa0757f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / coffeeql-0.4.1-cp39-abi3-manylinux_2_31_x86_64.whl

Download URL coffeeql-0.4.1-cp39-abi3-manylinux_2_31_x86_64.whl
Size 436.3 kB
Tags CPython 3.9 Linux glibc 2.31+ x86-64 abi3
SHA-256 checksum
How to use checksums
1b4294b0732d5c49f506030275bfd1df3e0f1f9e47661defd1b5380bc0266dd4
BLAKE2b-256 checksum
How to use checksums
60ec17e77ef5adc220789e2a429de0e451fd327e69db4dd1712f126ffb0d10b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / coffeeql-0.4.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL coffeeql-0.4.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 747.7 kB
Tags CPython 3.9 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ec28a721d599fbcfdae090c33cca54df32afc168cc2a29f346d31419ee17590a
BLAKE2b-256 checksum
How to use checksums
1e9311b30fd0252abcea947bfa03d48622ce1782fb30ab6abdd24ac53a001a86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for coffeeql 0.4.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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