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
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
Close
Hashes for databend_driver-0.22.2-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f53a7236b03e086ba3d44addd5ed44f5835d937e8fcaee359ca2939d3a684ca4 |
|
MD5 | a5946d2dd85a45159e96a77328e1bdcd |
|
BLAKE2b-256 | f19f4b84c965a9c9e31605ef8e2eff1aab3528d0dd8e94ec6bd1ce1df69aad26 |
Close
Hashes for databend_driver-0.22.2-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6561c3f330dd3b6370e292aac0ed7bc54387c67158656ff1c13b24bba25177f9 |
|
MD5 | f4a09dd1d8fb5eb76db35ba943ae4569 |
|
BLAKE2b-256 | 138c78305f0188415ba58ed99bb13086a450df48d127951f09b83046dbade902 |
Close
Hashes for databend_driver-0.22.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41e8899410f63faefff8ba619cde688f696eeadd383f94bcdfa58f4ea179579b |
|
MD5 | 0f48c00e84563b980e2dded1f76e8576 |
|
BLAKE2b-256 | cb7d49395513fc89682149f16059a80f8f1e7b4767f2d9c464551a2c47da36e1 |
Close
Hashes for databend_driver-0.22.2-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a2fa02e5e7e52cd6556bb4f7d4b99307ee6c1fd1c845e90bf127900d6ca45c0 |
|
MD5 | 6c7e3a2b0a71c6f9a3c8b6911f5fb261 |
|
BLAKE2b-256 | e65fdcd3576830c158a567301a779f982a583e6cdd5c101ab65b3a5abdb576c7 |
Close
Hashes for databend_driver-0.22.2-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4178053e2a78665e32414f4e28bfcff56f8e429e3af5b44f0f3f087328457ac7 |
|
MD5 | 02eaeaccb6c7e356c22727ee78b96b36 |
|
BLAKE2b-256 | d7af4bd39486d26f4ae34f33ef2b6bc0b0154008ed247c73fd36baee00147826 |