Skip to main content

Type-safe ClickHouse query parameter codegen from SQL files

Project description

chty

End-to-end type-safe ClickHouse query codegen from SQL files.

Documentation License: MIT

Installation

# Run directly without installation
uvx chty

# Or install globally
uv tool install chty

# Or use pip/pipx
pip install chty

Quick Start

Create a .sql file with ClickHouse parameterized queries:

-- queries/example.sql
SELECT number, number * {multiplier:Int32} AS result
FROM system.numbers
WHERE number < {limit:Int32}

Generate fully type-safe Python code:

chty generate queries/*.sql --output generated/ --db-url clickhouse://user:pass@host:port

Use the generated code with full type safety:

from generated.example import ExampleParams, ExampleQuery
import clickhouse_connect

client = clickhouse_connect.get_client(host="localhost")
params = ExampleParams(multiplier=3, limit=5)
query = ExampleQuery(client)

# Execute with full IDE autocomplete on parameters and results
results = query.execute(params)
for row in results:
    print(f"Number: {row['number']}, Result: {row['result']}")

Features

  • Type-safe parameters - Catch parameter errors at development time
  • Type-safe results - Full autocomplete for result fields (with --db-url)
  • Schema validation - Detect schema drift with chty validate
  • Multiple execution methods - execute() and execute_df() for DataFrames
  • Optional runtime validation - Validate result schema at runtime
  • Zero runtime overhead - TypedDict is just type annotations

Why chty?

ClickHouse queries in Python lack type safety. chty connects your SQL queries directly to Python's type system:

Without chty:

  • ❌ No autocomplete for query parameters or results
  • ❌ Errors only caught at runtime
  • ❌ No way to detect schema drift

With chty:

  • ✅ Full type safety from SQL to Python
  • ✅ IDE autocomplete everywhere
  • ✅ Catch errors at development time
  • ✅ Detect schema changes in CI/CD

Documentation

Full documentation is available at https://treygilliland.github.io/chty/

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

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

chty-0.1.1.tar.gz (112.6 kB view details)

Uploaded Source

Built Distribution

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

chty-0.1.1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file chty-0.1.1.tar.gz.

File metadata

  • Download URL: chty-0.1.1.tar.gz
  • Upload date:
  • Size: 112.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.3

File hashes

Hashes for chty-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bed29ab1a0b63846169831b7c3f5ba027e6b333e4697b398cff5a6a3f265faa7
MD5 d1d6267a1f10b530b43af8cbc9f14b7a
BLAKE2b-256 7ff3945f788fc98f083e4f115c367b51b0584b7b9afa917fb01e19029f3d27ca

See more details on using hashes here.

File details

Details for the file chty-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: chty-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.3

File hashes

Hashes for chty-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb7c64ed4f74b26ce3a55f39c8b7db94acbb57d299c1d665558703a05c1255c3
MD5 25eca6aa0dc48adf3390bf806347bd9e
BLAKE2b-256 6746e42d6bfc22b316e743f72dd99471000e47e3f6eb80ea84a1964e32e8bca1

See more details on using hashes here.

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