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.0.tar.gz (111.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.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for chty-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4f7bc34f4c2892437eca40f0262fedae06063c92785d69a96293ce38d7771613
MD5 755346d92f693faba3bba573e8b58a7e
BLAKE2b-256 69c87fe1007961f0d59d349105a25c9783acf87e241ca4b11114e0b309bbf603

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for chty-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e579400176fcd48ac479eac526febdf78bbeedf6827edd962c4de4f4f51ed692
MD5 f5aaff51825df0553772ad1df5eeee35
BLAKE2b-256 e94e6b1831d2e3881c88c1b58d61857799ad4c54c2c1fc589acdbff6f5af9474

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