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.0

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.0
File Interpreter ABI Platform Actions
coffeeql-0.4.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for coffeeql-0.4.0-cp39-abi3-win_amd64.whl
coffeeql-0.4.0-cp39-abi3-manylinux_2_34_x86_64.whl CPython 3.9 abi3 Linux glibc 2.34+ x86-64 Details for coffeeql-0.4.0-cp39-abi3-manylinux_2_34_x86_64.whl
coffeeql-0.4.0-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+ x86-64, macOS 10.12+ universal2 (ARM64, x86-64) Details for coffeeql-0.4.0-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.0-cp39-abi3-win_amd64.whl

Download URL coffeeql-0.4.0-cp39-abi3-win_amd64.whl
Size 294.3 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c41ef89d628a7528d215ac83a560e796b36de0a407594b1c5fa278e7d7dcd055
BLAKE2b-256 checksum
How to use checksums
0f2e55f333087ee922223985093c55117c014ebc0bc1d78315f665c920d5108c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / coffeeql-0.4.0-cp39-abi3-manylinux_2_34_x86_64.whl

Download URL coffeeql-0.4.0-cp39-abi3-manylinux_2_34_x86_64.whl
Size 435.5 kB
Tags CPython 3.9 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
b6435e8f3ee40eec594bb0d4991e642e6e82a92d7bd4097d5544918280caa874
BLAKE2b-256 checksum
How to use checksums
14406448cdee57984332592c8ad0b03eb4fba263ff56d8b52316ac871a3a75eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

Download URL coffeeql-0.4.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 746.5 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
af991743497e81662e4ec388542cea3c892a547a668fd04b9586961b21fa2418
BLAKE2b-256 checksum
How to use checksums
c900b1fca1e743c8a4bb72b65b2308805c1917b7490a75407fc84ecce00eca56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Security for coffeeql 0.4.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.

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