Skip to main content

tidbcloudlake-driver

TiDB Cloud Lake Python Client

image License image

Usage

PEP 249 Cursor Object

from tidbcloudlake_driver import BlockingLakeClient

client = BlockingLakeClient('lake://root:root@localhost:8000/?sslmode=disable')
cursor = client.cursor()

cursor.execute(
    """
    CREATE TABLE test (
        i64 Int64,
        u64 UInt64,
        f64 Float64,
        s   String,
        s2  String,
        d   Date,
        t   DateTime
    )
    """
)
cursor.execute("INSERT INTO test VALUES (?, ?, ?, ?, ?, ?, ?)", (1, 1, 1.0, 'hello', 'world', '2021-01-01', '2021-01-01 00:00:00'))
cursor.execute("SELECT * FROM test")
rows = cursor.fetchall()
for row in rows:
    print(row.values())
cursor.close()

Blocking Connection Object

from tidbcloudlake_driver import BlockingLakeClient

client = BlockingLakeClient('lake://root:root@localhost:8000/?sslmode=disable')
conn = client.get_conn()
conn.exec(
    """
    CREATE TABLE test (
        i64 Int64,
        u64 UInt64,
        f64 Float64,
        s   String,
        s2  String,
        d   Date,
        t   DateTime
    )
    """
)
rows = conn.query_iter("SELECT * FROM test")
for row in rows:
    print(row.values())
conn.close()

Asyncio Connection Object

import asyncio
from tidbcloudlake_driver import AsyncLakeClient

async def main():
    client = AsyncLakeClient('lake://root:root@localhost:8000/?sslmode=disable')
    conn = await client.get_conn()
    await conn.exec(
        """
        CREATE TABLE test (
            i64 Int64,
            u64 UInt64,
            f64 Float64,
            s   String,
            s2  String,
            d   Date,
            t   DateTime
        )
        """
    )
    rows = await conn.query_iter("SELECT * FROM test")
    async for row in rows:
        print(row.values())
    await conn.close()

asyncio.run(main())

Parameter bindings

# Test with positional parameters
row = await context.conn.query_row("SELECT ?, ?, ?, ?", (3, False, 4, "55"))
row = await context.conn.query_row(
    "SELECT :a, :b, :c, :d", {"a": 3, "b": False, "c": 4, "d": "55"}
)
row = await context.conn.query_row(
    "SELECT ?", 3
)
row = await context.conn.query_row("SELECT ?, ?, ?, ?", params = (3, False, 4, "55"))

Query ID tracking and query management

# Get the last executed query ID
query_id = conn.last_query_id()
print(f"Last query ID: {query_id}")

# Execute a query and get its ID
await conn.query_row("SELECT 1")
query_id = conn.last_query_id()
print(f"Query ID: {query_id}")

# Kill a running query (if needed)
try:
    await conn.kill_query("some-query-id")
    print("Query killed successfully")
except Exception as e:
    print(f"Failed to kill query: {e}")

Type Mapping

TiDB Cloud Lake Types

General Data Types

TiDB Cloud Lake Python
BOOLEAN bool
TINYINT int
SMALLINT int
INT int
BIGINT int
FLOAT float
DOUBLE float
DECIMAL decimal.Decimal
DATE datetime.date
TIMESTAMP datetime.datetime
INTERVAL datetime.timedelta
VARCHAR str
BINARY bytes

Semi-Structured Data Types

TiDB Cloud Lake Python
ARRAY list
TUPLE tuple
MAP dict
VARIANT str
BITMAP str
GEOMETRY str
GEOGRAPHY str

Note: VARIANT is a json encoded string. Example:

CREATE TABLE example (
    data VARIANT
);
INSERT INTO example VALUES ('{"a": 1, "b": "hello"}');
row = await conn.query_row("SELECT * FROM example limit 1;")
data = row.values()[0]
value = json.loads(data)
print(value)

GEOMETRY and GEOGRAPHY follow the current geometry_output_format setting. Text formats such as GeoJSON or WKT return str; binary formats such as WKB or EWKB return bytes.

For example:

row = await conn.query_row("settings(geometry_output_format='WKB') SELECT st_point(60, 37)")
assert isinstance(row.values()[0], bytes)

APIs

Exception Classes (PEP 249 Compliant)

The driver provides a complete set of exception classes that follow the PEP 249 standard for database interfaces:

# Base exceptions
class Warning(Exception): ...
class Error(Exception): ...

# Interface errors
class InterfaceError(Error): ...

# Database errors
class DatabaseError(Error): ...

# Specific database error types
class DataError(DatabaseError): ...
class OperationalError(DatabaseError): ...
class IntegrityError(DatabaseError): ...
class InternalError(DatabaseError): ...
class ProgrammingError(DatabaseError): ...
class NotSupportedError(DatabaseError): ...

These exceptions are automatically mapped from TiDB Cloud Lake error codes to appropriate PEP 249 exception types based on the nature of the error.

Note: stream_load and load_file support an optional method parameter, it accepts two string values:

  • stage: Data is first uploaded to a temporary stage and then loaded. This is the default behavior.
  • streaming: Data is directly streamed to the TiDB Cloud Lake server.

AsyncLakeClient

class AsyncLakeClient:
    def __init__(self, dsn: str): ...
    async def get_conn(self) -> AsyncLakeConnection: ...

AsyncLakeConnection

class AsyncLakeConnection:
    async def info(self) -> ConnectionInfo: ...
    async def version(self) -> str: ...
    async def close(self) -> None: ...
    def last_query_id(self) -> str | None: ...
    async def kill_query(self, query_id: str) -> None: ...
    async def exec(self, sql: str, params: list[string] | tuple[string] | any = None) -> int: ...
    async def query_row(self, sql: str, params: list[string] | tuple[string] | any = None) -> Row: ...
    async def query_iter(self, sql: str, params: list[string] | tuple[string] | any = None) -> RowIterator: ...
    async def stream_load(self, sql: str, data: list[list[str]], method: str = None) -> ServerStats: ...
    async def load_file(self, sql: str, file: str, method: str = None) -> ServerStats: ...

BlockingLakeClient

class BlockingLakeClient:
    def __init__(self, dsn: str): ...
    def get_conn(self) -> BlockingLakeConnection: ...
    def cursor(self) -> BlockingLakeCursor: ...

BlockingLakeConnection

class BlockingLakeConnection:
    def info(self) -> ConnectionInfo: ...
    def version(self) -> str: ...
    def close(self) -> None: ...
    def last_query_id(self) -> str | None: ...
    def kill_query(self, query_id: str) -> None: ...
    def exec(self, sql: str, params: list[string] | tuple[string] | any = None) -> int: ...
    def query_row(self, sql: str, params: list[string] | tuple[string] | any = None) -> Row: ...
    def query_iter(self, sql: str, params: list[string] | tuple[string] | any = None) -> RowIterator: ...
    def stream_load(self, sql: str, data: list[list[str]], method: str = None) -> ServerStats: ...
    def load_file(self, sql: str, file: str, method: str = None, format_option: dict = None, copy_options: dict = None) -> ServerStats: ...

BlockingLakeCursor

class BlockingLakeCursor:
    @property
    def description(self) -> list[tuple[str, str, int | None, int | None, int | None, int | None, bool | None]] | None: ...
    @property
    def rowcount(self) -> int: ...
    def close(self) -> None: ...
    def execute(self, operation: str, params: list[string] | tuple[string] = None) -> None | int: ...
    def executemany(self, operation: str, params: list[string] | tuple[string] = None, values: list[list[string] | tuple[string]]) -> None | int: ...
    def fetchone(self) -> Row | None: ...
    def fetchmany(self, size: int = 1) -> list[Row]: ...
    def fetchall(self) -> list[Row]: ...

    # Optional DB API Extensions
    def next(self) -> Row: ...
    def __next__(self) -> Row: ...
    def __iter__(self) -> BlockingLakeCursor: ...

Row

class Row:
    def values(self) -> tuple: ...
    def __len__(self) -> int: ...
    def __iter__(self) -> Row: ...
    def __next__(self) -> any: ...
    def __dict__(self) -> dict: ...
    def __getitem__(self, key: int | str) -> any: ...

RowIterator

class RowIterator:
    def schema(self) -> Schema: ...

    def __iter__(self) -> RowIterator: ...
    def __next__(self) -> Row: ...

    def __aiter__(self) -> RowIterator: ...
    async def __anext__(self) -> Row: ...

Field

class Field:
    @property
    def name(self) -> str: ...
    @property
    def data_type(self) -> str: ...

Schema

class Schema:
    def fields(self) -> list[Field]: ...

ServerStats

class ServerStats:
    @property
    def total_rows(self) -> int: ...
    @property
    def total_bytes(self) -> int: ...
    @property
    def read_rows(self) -> int: ...
    @property
    def read_bytes(self) -> int: ...
    @property
    def write_rows(self) -> int: ...
    @property
    def write_bytes(self) -> int: ...
    @property
    def running_time_ms(self) -> float: ...

ConnectionInfo

class ConnectionInfo:
    @property
    def handler(self) -> str: ...
    @property
    def host(self) -> str: ...
    @property
    def port(self) -> int: ...
    @property
    def user(self) -> str: ...
    @property
    def database(self) -> str | None: ...
    @property
    def warehouse(self) -> str | None: ...

Development

cd tests
make up
cd bindings/python
uv sync
source .venv/bin/activate
maturin develop --uv

behave tests/asyncio
behave tests/blocking
behave tests/cursor

Metadata

Release files for tidbcloudlake-driver 0.34.0

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

Source distribution (sdist)

Source distribution for tidbcloudlake-driver 0.34.0
File Size Uploaded Provenance Actions
tidbcloudlake_driver-0.34.0.tar.gz 160.0 kB With provenance Details for tidbcloudlake_driver-0.34.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for tidbcloudlake-driver 0.34.0
File Actions
tidbcloudlake_driver-0.34.0-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for tidbcloudlake_driver-0.34.0-cp39-abi3-manylinux_2_28_aarch64.whl
tidbcloudlake_driver-0.34.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for tidbcloudlake_driver-0.34.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
tidbcloudlake_driver-0.34.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for tidbcloudlake_driver-0.34.0-cp39-abi3-macosx_11_0_arm64.whl
tidbcloudlake_driver-0.34.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for tidbcloudlake_driver-0.34.0-cp39-abi3-macosx_10_12_x86_64.whl
tidbcloudlake_driver-0.34.0-cp38-cp38-manylinux_2_28_aarch64.whl CPython 3.8 CPython 3.8 Linux glibc 2.28+ ARM64 Details for tidbcloudlake_driver-0.34.0-cp38-cp38-manylinux_2_28_aarch64.whl
tidbcloudlake_driver-0.34.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details for tidbcloudlake_driver-0.34.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
tidbcloudlake_driver-0.34.0-cp38-cp38-macosx_11_0_arm64.whl CPython 3.8 CPython 3.8 macOS 11.0+ ARM64 Details for tidbcloudlake_driver-0.34.0-cp38-cp38-macosx_11_0_arm64.whl
tidbcloudlake_driver-0.34.0-cp38-cp38-macosx_10_12_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.12+ x86-64 Details for tidbcloudlake_driver-0.34.0-cp38-cp38-macosx_10_12_x86_64.whl

Total release size: 71.4 MB

Release files / tidbcloudlake_driver-0.34.0.tar.gz

Download URL tidbcloudlake_driver-0.34.0.tar.gz
Size 160.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5ebbe80d91c2260bfadfb7a135b68df2cf6e1cc9285306bebdb9b642ec91f0b2
BLAKE2b-256 checksum
How to use checksums
11da547451401c0d69b0fd6e7dd889e37b091b7c9b2b9846a6d298e5e28223c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Release files / tidbcloudlake_driver-0.34.0-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL tidbcloudlake_driver-0.34.0-cp39-abi3-manylinux_2_28_aarch64.whl
Size 8.8 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
07b8ee5b6cde316688f192fda331c3c4ad1b638edfa4780e9714131d157f0e43
BLAKE2b-256 checksum
How to use checksums
3572258c7c98f87f5d70d12552c86207571ed629b141f2eaa0b546c5e12343e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Release files / tidbcloudlake_driver-0.34.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL tidbcloudlake_driver-0.34.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 9.4 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
553a23ffa804b4735ee65b9479540d88c6d4b446df04bbaf9830d46e557f6b52
BLAKE2b-256 checksum
How to use checksums
7d9ec1e997f13db3fe232670a786482a6ed445ed73fd14389653b5d4d89e0ce9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Release files / tidbcloudlake_driver-0.34.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL tidbcloudlake_driver-0.34.0-cp39-abi3-macosx_11_0_arm64.whl
Size 8.3 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
719493265477ec5b90176011cb347b37e0d56ae9d9812f5e57b19d4b669a2ca7
BLAKE2b-256 checksum
How to use checksums
8996edfd0aedc55b7b6a160a3dc647e9aa133263311a17a15d9f14c9989334cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Release files / tidbcloudlake_driver-0.34.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL tidbcloudlake_driver-0.34.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 8.9 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
81a6437efc0c6c7597cab1bdf370dbc6ae174bf6f09537a061bdaefcc79a6637
BLAKE2b-256 checksum
How to use checksums
25e0a96927ea41ed34c5a4ee3b02fc05ca6b84c9fbccf2c0a3c8f097ecafedc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Release files / tidbcloudlake_driver-0.34.0-cp38-cp38-manylinux_2_28_aarch64.whl

Download URL tidbcloudlake_driver-0.34.0-cp38-cp38-manylinux_2_28_aarch64.whl
Size 8.9 MB
Tags CPython 3.8 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
c93d4eb7286ea431e7fcbfd9b22d3a7b37b81bdadcffa553667fbcebdf35b6ba
BLAKE2b-256 checksum
How to use checksums
751de3e99d20ffa86dd2ada92a4614480b243db7a2a40502e69e7d4982f63434
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Release files / tidbcloudlake_driver-0.34.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL tidbcloudlake_driver-0.34.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 9.6 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1e8b455c28d57c83b39714eb186beea5fac08179e9b7a71859aa8f399e6cc890
BLAKE2b-256 checksum
How to use checksums
725d8462c260eed239c78e16be5e3d758c9140d1485ea7ce5b98ce0f90a8005d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Release files / tidbcloudlake_driver-0.34.0-cp38-cp38-macosx_11_0_arm64.whl

Download URL tidbcloudlake_driver-0.34.0-cp38-cp38-macosx_11_0_arm64.whl
Size 8.4 MB
Tags CPython 3.8 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
90cca3d1f0c6cfcf7cf9623cd05cdebd7f359b6252bd9acb55275ce05d9260bb
BLAKE2b-256 checksum
How to use checksums
842eb6f6b06bc8125fa33fc8acaf8b632139820bfa4fc9c385a6c2c3fc3e90e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Release files / tidbcloudlake_driver-0.34.0-cp38-cp38-macosx_10_12_x86_64.whl

Download URL tidbcloudlake_driver-0.34.0-cp38-cp38-macosx_10_12_x86_64.whl
Size 9.0 MB
Tags CPython 3.8 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
3869708efaace71f80e10c86903e3a73129f78c8713d4fcca1b90b5ebccd5f01
BLAKE2b-256 checksum
How to use checksums
89af6b9609dd5020e2dde66c8e2f1d92d4475f47d7182114df91ada39a892562
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

Security for tidbcloudlake-driver 0.34.0

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

All 9 files in this release have been uploaded with provenance metadata.

Select from 9 files

Attestation for tidbcloudlake_driver-0.34.0.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 Jun 4, 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