Skip to main content

No project description provided

Project description

riffq

riffq is a Python-accessible toolkit (built in Rust) for building PostgreSQL wire-compatible databases.
It allows you to serve data from Python over the PostgreSQL protocol — turning your Python-based logic or in-memory data into a queryable, network-exposed system.


What It Does

  • Implements the PostgreSQL wire protocol in Rust for performance and concurrency
  • Sends raw SQL queries (Simple or Extended protocol) to Python for interpretation
  • Implements postgres catalog compatibility layer (see pg_catalog_rs

Since you are in python, you can

  • Allows you to connect to remote data sources (e.g., analytics DB, CRM) and expose them as a unified PostgreSQL database
  • Enables serving Pandas DataFrames over the network as virtual SQL tables
  • Can delegate SQL execution to DuckDB, Polars, or any other Python engine
  • Acts as a programmable federated query engine or custom data service

Example Use Cases

  • Serve a Pandas DataFrame as a PostgreSQL table to BI tools
  • Build a custom federated engine from multiple APIs or databases
  • Implement your own data lake query frontend
  • Expose dynamic ML feature stores for training or real-time inference
  • Provide fine-grained, code-controlled access to internal metrics or logs

Example

# Python side
def handle_query(sql: str) -> Tuple[List[Dict[str, Any]], List[Tuple[str, str]]]:
    df = duckdb.query(sql).to_df()
    columns = [(name, str(dtype)) for name, dtype in zip(df.columns, df.dtypes)]
    rows = df.to_dict(orient="records")
    return rows, columns

The Rust side calls this Python handler when a SQL query comes in via the PostgreSQL protocol.


Architecture

  • Rust layer handles:
    • PostgreSQL protocol (via pgwire)
    • Connection management
    • Query routing
    • Metadata compatibility (pg_catalog emulation)
  • Python layer handles:
    • SQL execution (via any engine: DuckDB, Polars, etc.)
    • Data transformation
    • Custom logic and dynamic schema definitions

Getting Started

pip install riffq
import riffq

@riffq.query_handler
def handle_sql(sql: str):
    # Your query handling logic here
    ...
    
riffq.serve(port=5432)

Enabling TLS

Generate a temporary certificate and key:

openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 1 -out server.crt -subj "/CN=localhost"

Start the server with TLS enabled:

server = riffq.Server("127.0.0.1:5432")
server.set_tls("server.crt", "server.key")
server.start(tls=True)

Then connect using any PostgreSQL client:

psql -h localhost -p 5432

Status

  • ✅ Wire protocol support (simple + extended)
  • ✅ Query dispatching to Python
  • ✅ DuckDB, Pandas, Polars compatibility
  • 🟡 Limited SQL parsing on Rust side (forwarded to Python)
  • ✅ Optional TLS encryption

Running Tests

Install the development requirements and run the test suite:

pip install -r requirements.txt
maturin build --profile=fast -i python3
pip install target/wheels/*.whl
python -m unittest discover -s tests

The tests require the Rust extension to build successfully; any build failure will cause the suite to fail.


License

MIT or Apache 2.0 — your choice.


Contributing

Contributions are welcome! Especially for:

  • Better Python DX
  • Support for pg_catalog views
  • Example apps (data lake, feature store, etc.)

Development Notes

This repository contains tests that exercise the ability to return query results as Arrow IPC streams from Python. The initial implementation in src/lib.rs only accepted raw bytes without decoding them, resulting in empty result sets.

The code now invokes pyarrow to parse these IPC bytes back into ordinary rows. The parsing is performed inside the Rust callback while holding the Python GIL so no additional Rust Arrow dependencies are required.


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

riffq-0.1.0.tar.gz (68.2 kB view details)

Uploaded Source

Built Distributions

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

riffq-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (35.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

riffq-0.1.0-cp312-cp312-manylinux_2_38_x86_64.whl (39.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

riffq-0.1.0-cp39-cp39-win_amd64.whl (33.9 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file riffq-0.1.0.tar.gz.

File metadata

  • Download URL: riffq-0.1.0.tar.gz
  • Upload date:
  • Size: 68.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for riffq-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0079d1d6401e15dcba02ec5c2d6ddd0a1659062dfdda85d939f7f6eb3487c18
MD5 07e4092625d4b8bd50093d6dba765150
BLAKE2b-256 512a3230ba0798d595197401d60e17f4b303ac448ba85947bda83fe11eed6088

See more details on using hashes here.

Provenance

The following attestation bundles were made for riffq-0.1.0.tar.gz:

Publisher: build-release.yml on ybrs/riffq

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

File details

Details for the file riffq-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for riffq-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fcfbb172559675721507475d97ea18836a88c7b7ab9c46b6e80ae6e4a4529968
MD5 ab3b71995469342a8ae227d058e297d6
BLAKE2b-256 fdc454def948e49f3ef40372b06c42028479aa7a9a22f033185ab962dd68f895

See more details on using hashes here.

Provenance

The following attestation bundles were made for riffq-0.1.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-release.yml on ybrs/riffq

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

File details

Details for the file riffq-0.1.0-cp312-cp312-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for riffq-0.1.0-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 46760c899ac81fe8a2c85dabd3fdb75b219052bbcc85fcb6c70bb35d8a69367f
MD5 e2d147b6d7a9eca713125f1e84721a39
BLAKE2b-256 ce714783c862f786b6625e4c42493f79f5051e954f3afc1b455ffad6e6d836fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for riffq-0.1.0-cp312-cp312-manylinux_2_38_x86_64.whl:

Publisher: build-release.yml on ybrs/riffq

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

File details

Details for the file riffq-0.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: riffq-0.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 33.9 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for riffq-0.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2db44cd37c0f9503536ec25a3701365b48b67003f52eb705709686393c4a8abc
MD5 ca604aaa06dd517eacdf0ffa592a913f
BLAKE2b-256 f0ed7cb2b5c68b993510d7f0f54c1b934c5c3884b4cf10fed53262f89fbe7dbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for riffq-0.1.0-cp39-cp39-win_amd64.whl:

Publisher: build-release.yml on ybrs/riffq

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