Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

hypequery for Python

A code-first semantic layer for ClickHouse. Define dimensions, measures and tenant rules once in Python, query them by name, serve them from FastAPI, Django or Flask, and reuse the same definitions from React and AI agents.

PyPI Python versions License Docs

  • No metrics service. It is a library. Definitions live in your codebase and queries run in your process, on your ClickHouse.
  • Typed, validated queries. Requests are checked against the dataset before any SQL is generated, and the SQL is parameterized.
  • Multi-tenant by default. Declare tenant_key once and every query is scoped to the caller's tenant.
  • One definition, every surface. Rows, pandas, polars or Arrow in Python; authenticated HTTP endpoints; generated React hooks; governed MCP tools for agents.

Install

pip install "hypequery[clickhouse]"

Python 3.11 or later. Extras: clickhouse-async, server, jwt, django, flask, pandas, polars, arrow, and chdb to run on embedded ClickHouse with no server (Linux and macOS).

Define a dataset and query it

from hypequery.datasets import (
    DatasetQuery,
    ExecutionContext,
    create_dataset_client,
    dataset,
    dimension,
    filter,
    measure,
    order,
    tenant,
)
from hypequery.execution import ClickHouseConnection, create_clickhouse_executor

orders = dataset(
    "orders",
    source="orders",
    tenant_key="tenant_id",
    time_key="created_at",
    dimensions={
        "country": dimension.string(),
        "status": dimension.string(),
        "createdAt": dimension.timestamp(column="created_at"),
    },
    measures={
        "revenue": measure.sum("amount"),
        "orderCount": measure.count("id"),
    },
)

analytics = create_dataset_client(
    executor=create_clickhouse_executor(ClickHouseConnection.from_env()),
)

result = analytics.execute(
    orders,
    DatasetQuery(
        dimensions=("country",),
        measures=("revenue", "orderCount"),
        filters=(filter.eq("status", "paid"),),
        order_by=(order.desc("revenue"),),
        limit=10,
    ),
    context=ExecutionContext(tenant=tenant("org_123")),
)
print(result.data)

ClickHouseConnection.from_env() reads CLICKHOUSE_HOST, CLICKHOUSE_PORT, CLICKHOUSE_DATABASE, CLICKHOUSE_USERNAME and CLICKHOUSE_PASSWORD, or a single CLICKHOUSE_URL. Already have tables? hypequery init introspects your schema and writes the dataset definitions for you.

Serve it over HTTP

The API is plain ASGI, so it mounts in FastAPI, Starlette or any ASGI app, and is served natively from Django and Flask. Every endpoint authenticates before reading the body and takes the tenant from the caller.

pip install "hypequery[clickhouse,jwt]" fastapi uvicorn
from fastapi import FastAPI
from hypequery.serve import HttpSecurity, create_api, jwt_strategy, to_asgi_app

api = create_api(
    auth=jwt_strategy(
        jwks_url="https://example.auth0.com/.well-known/jwks.json",
        issuer="https://example.auth0.com/",
        audience="https://api.example.com",
    ),
    client=analytics,
    datasets={"orders": orders},
    security=HttpSecurity(allowed_hosts=("api.example.com",)),
)

app = FastAPI()
app.mount("/analytics", to_asgi_app(api))

POST /analytics/datasets/orders/query now runs the same validated, tenant-scoped query as the Python call above. The same endpoints feed generated, type-safe React hooks (@hypequery/react) and a governed MCP server (@hypequery/mcp) that gives agents named metrics instead of raw SQL.

Learn more

hypequery is Apache 2.0 licensed. The TypeScript edition, with a type-safe query builder, lives in the same repository and implements the same specifications.

Beta. The Python SDK is tested end to end from the installed package, but its APIs may still change before 1.0. Pin the version you deploy and report problems on GitHub.

Metadata

Release files for hypequery 0.1.0b3

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

Source distribution (sdist)

Source distribution for hypequery 0.1.0b3
File Size Uploaded Provenance Actions
hypequery-0.1.0b3.tar.gz 959.4 kB With provenance Details for hypequery-0.1.0b3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hypequery 0.1.0b3
File Interpreter ABI Platform Actions
hypequery-0.1.0b3-py3-none-any.whl Python 3 none any Details for hypequery-0.1.0b3-py3-none-any.whl

Total release size: 1.5 MB

Release files / hypequery-0.1.0b3.tar.gz

Download URL hypequery-0.1.0b3.tar.gz
Size 959.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cd46cd0203b643ebd2407f60a8e6943eb46397f8d8379311410875c763cd8040
BLAKE2b-256 checksum
How to use checksums
7b7bc89aad358e6be395c1e4baefca9e2bcdbaa0bb324b9bf74a86c210c19f4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / hypequery-0.1.0b3-py3-none-any.whl

Download URL hypequery-0.1.0b3-py3-none-any.whl
Size 515.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ea9a086144f73ddf5a74a730d6d1bb1c186a18cea527fc04ac61caa7cb58171
BLAKE2b-256 checksum
How to use checksums
2d4eced7dace87cc9e587fc53968d410b23b76c9e08113514fdf79801fa378fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for hypequery 0.1.0b3

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hypequery-0.1.0b3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

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