Skip to main content

Databend Driver Python Binding

Project description

databend-driver

Build

cd bindings/python
maturin develop

Usage

Blocking

from databend_driver import BlockingDatabendClient

client = BlockingDatabendClient('databend+http://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())

Asyncio

import asyncio
from databend_driver import AsyncDatabendClient

async def main():
    client = AsyncDatabendClient('databend+http://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())

asyncio.run(main())

Type Mapping

Databend Types

General Data Types

Databend Python
BOOLEAN bool
TINYINT int
SMALLINT int
INT int
BIGINT int
FLOAT float
DOUBLE float
DECIMAL decimal.Decimal
DATE datetime.date
TIMESTAMP datetime.datetime
VARCHAR str
BINARY bytes

Semi-Structured Data Types

Databend Python
ARRAY list
TUPLE tuple
MAP dict
VARIANT str
BITMAP str
GEOMETRY 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)

APIs

AsyncDatabendClient

class AsyncDatabendClient:
    def __init__(self, dsn: str): ...
    async def get_conn(self) -> AsyncDatabendConnection: ...

AsyncDatabendConnection

class AsyncDatabendConnection:
    async def info(self) -> ConnectionInfo: ...
    async def version(self) -> str: ...
    async def exec(self, sql: str) -> int: ...
    async def query_row(self, sql: str) -> Row: ...
    async def query_iter(self, sql: str) -> RowIterator: ...
    async def stream_load(self, sql: str, data: list[list[str]]) -> ServerStats: ...

BlockingDatabendClient

class BlockingDatabendClient:
    def __init__(self, dsn: str): ...
    def get_conn(self) -> BlockingDatabendConnection: ...

BlockingDatabendConnection

class BlockingDatabendConnection:
    def info(self) -> ConnectionInfo: ...
    def version(self) -> str: ...
    def exec(self, sql: str) -> int: ...
    def query_row(self, sql: str) -> Row: ...
    def query_iter(self, sql: str) -> RowIterator: ...
    def stream_load(self, sql: str, data: list[list[str]]) -> ServerStats: ...

Row

class Row:
    def values(self) -> tuple: ...

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
pipenv install --dev
pipenv run maturin develop
pipenv run behave tests/*

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

databend_driver-0.18.0-cp37-abi3-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.7+Windows x86-64

databend_driver-0.18.0-cp37-abi3-manylinux_2_28_aarch64.whl (4.7 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

databend_driver-0.18.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

databend_driver-0.18.0-cp37-abi3-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

databend_driver-0.18.0-cp37-abi3-macosx_10_12_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file databend_driver-0.18.0-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for databend_driver-0.18.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d8c14d2904c06ae6fdaf1ae055f493cad6c4b333acbc64cc453c816ccd01ba16
MD5 065b8a9693a919d6cf51ec003de2f0c0
BLAKE2b-256 a6aa9bd7dda572e491de44d6ed2a1ac647b967b929fc62ea999e559be636b4b1

See more details on using hashes here.

File details

Details for the file databend_driver-0.18.0-cp37-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for databend_driver-0.18.0-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cf20105f0e71434ab600e1c409e2e4c0525fb86c9958a394b49a1af2eee090b0
MD5 7e3874c58f037ee25ea3e92f288f0a13
BLAKE2b-256 831027a9ea8c4e1a22fc110578a27786626490a9cd27aa1d528fd2619c9242d1

See more details on using hashes here.

File details

Details for the file databend_driver-0.18.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for databend_driver-0.18.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 22301d59dfcf5c83b5af2f9e55f46b174d511ec6c6bc13a37b265168d2d5e9df
MD5 f5aeb7f83c0bb6b34c017d4d76beae6a
BLAKE2b-256 545ca716ac663bd60d105f088320bfdc45bf7668ae67e4609581bc335296acd4

See more details on using hashes here.

File details

Details for the file databend_driver-0.18.0-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for databend_driver-0.18.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 50ef9c8d0efe98fedb9b93c304ed785f05c3c8a084799f6f35d5c5142ab629a4
MD5 93f12c6925e691e41e71ae735ff86dda
BLAKE2b-256 3503369a5a674627a3e26ea82e3b5f8bca3bc1b99a8816a2b37600f09a353d3f

See more details on using hashes here.

File details

Details for the file databend_driver-0.18.0-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for databend_driver-0.18.0-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5d968b93b8886ab0f7d30b8f991dc1d62cd39689c5d0dd5d660915b66627d37d
MD5 748c9fbe9ae414851bd746a4aa4a5dfd
BLAKE2b-256 caeab7284b592a1a04fec0e5f26d555add5a93a3703e1717b233fd98e324b373

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