ClickHouse Connect driver API

# Insert into a table in a specific database
client.insert(
    "users",
    data,
    column_names=["id", "name", "age"],
    database="production",
)
```

## File Inserts[​](#file-inserts "Direct link to File Inserts")

For inserting data directly from files into ClickHouse tables, see [Advanced Inserting (File Inserts)](/docs/integrations/language-clients/python/advanced-inserting#file-inserts).

## Raw API[​](#raw-api "Direct link to Raw API")

For advanced use cases requiring direct access to ClickHouse HTTP interfaces without type transformations, see [Advanced Usage (Raw API)](/docs/integrations/language-clients/python/advanced-usage#raw-api).

## Utility classes and functions[​](#utility-classes-and-functions "Direct link to Utility classes and functions")

The following classes and functions are also considered part of the "public" `clickhouse-connect` API and are, like the classes and methods documented above, stable across minor releases. Breaking changes to these classes and functions will only occur with a minor (not patch) release and will be available with a deprecated status for at least one minor release.

### Exceptions[​](#exceptions "Direct link to Exceptions")

All custom exceptions (including those defined in the DB API 2.0 specification) are defined in the `clickhouse_connect.driver.exceptions` module. Exceptions actually detected by the driver will use one of these types.

### ClickHouse SQL utilities[​](#clickhouse-sql-utilities "Direct link to ClickHouse SQL utilities")

The functions and the DT64Param class in the `clickhouse_connect.driver.binding` module can be used to properly build and escape ClickHouse SQL queries. Similarly, the functions in the `clickhouse_connect.driver.parser` module can be used to parse ClickHouse datatype names.

## Multithreaded, multiprocess, and async/event driven use cases[​](#multithreaded-multiprocess-and-asyncevent-driven-use-cases "Direct link to Multithreaded, multiprocess, and async/event driven use cases")

For information on using ClickHouse Connect in multithreaded, multiprocess, and async/event-driven applications, see [Advanced Usage (Multithreaded, multiprocess, and async/event driven use cases)](/docs/integrations/language-clients/python/advanced-usage#multithreaded-multiprocess-and-asyncevent-driven-use-cases).

## AsyncClient wrapper[​](#asyncclient-wrapper "Direct link to AsyncClient wrapper")

For information on using the AsyncClient wrapper for asyncio environments, see [Advanced Usage (AsyncClient wrapper)](/docs/integrations/language-clients/python/advanced-usage#asyncclient-wrapper).

## Managing ClickHouse Session IDs[​](#managing-clickhouse-session-ids "Direct link to Managing ClickHouse Session IDs")

For information on managing ClickHouse session IDs in multi-threaded or concurrent applications, see [Advanced Usage (Managing ClickHouse Session IDs)](/docs/integrations/language-clients/python/advanced-usage#managing-clickhouse-session-ids).

## Customizing the HTTP connection pool[​](#customizing-the-http-connection-pool "Direct link to Customizing the HTTP connection pool")

For information on customizing the HTTP connection pool for large multi-threaded applications, see [Advanced Usage (Customizing the HTTP connection pool)](/docs/integrations/language-clients/python/advanced-usage#customizing-the-http-connection-pool).

- [Client Initialization](#client-initialization)
  - [Connection arguments](#connection-arguments)- [HTTPS/TLS arguments](#httpstls-arguments)- [Settings argument](#settings-argument)- [Client creation examples](#client-creation-examples)- [Client Lifecycle and Best Practices](#client-lifecycle-and-best-practices)
    - [Core principles](#core-principles)- [Basic patterns](#basic-patterns)- [Multi-threaded applications](#multi-threaded-applications)- [Proper cleanup](#proper-cleanup)- [When to use multiple clients](#when-to-use-multiple-clients)- [Common method arguments](#common-method-arguments)
      - [Parameters argument](#parameters-argument)- [Settings argument](#settings-argument-1)- [Client `command` Method](#client-command-method)
        - [Command examples](#command-examples)- [Client `query` Method](#client-query-method)
          - [Query examples](#query-examples)- [The `QueryResult` object](#the-queryresult-object)- [Consuming query results with NumPy, Pandas or Arrow](#consuming-query-results-with-numpy-pandas-or-arrow)- [Client streaming query methods](#client-streaming-query-methods)- [Client `insert` Method](#client-insert-method)
                - [Examples](#examples)- [File Inserts](#file-inserts)- [Raw API](#raw-api)- [Utility classes and functions](#utility-classes-and-functions)
                      - [Exceptions](#exceptions)- [ClickHouse SQL utilities](#clickhouse-sql-utilities)- [Multithreaded, multiprocess, and async/event driven use cases](#multithreaded-multiprocess-and-asyncevent-driven-use-cases)- [AsyncClient wrapper](#asyncclient-wrapper)- [Managing ClickHouse Session IDs](#managing-clickhouse-session-ids)- [Customizing the HTTP connection pool](#customizing-the-http-connection-pool)

Was this page helpful?