Skip to main content

High-performance Python driver for SAP HANA with native Arrow support

Project description

pyhdb-rs

PyPI Python codecov CI License

High-performance Python driver for SAP HANA with native Apache Arrow support.

Features

  • DB-API 2.0 compliant - Drop-in replacement for existing HANA drivers
  • Zero-copy Arrow integration - Direct data transfer to Polars and pandas
  • Async support - Native async/await with connection pooling
  • Type-safe - Full type hints and strict typing
  • Fast - Built with Rust for 2x+ performance over hdbcli

Installation

pip install pyhdb_rs

With optional dependencies:

pip install pyhdb_rs[async]     # Async support

For DataFrame libraries, install separately:

pip install polars              # Polars DataFrame library
pip install pandas pyarrow      # pandas with Arrow support

Tip: Use uv pip install pyhdb_rs for faster installation.

Quick start

from pyhdb_rs import ConnectionBuilder
import polars as pl

conn = ConnectionBuilder.from_url("hdbsql://USER:PASSWORD@HOST:39017").build()
reader = conn.execute_arrow("SELECT * FROM SALES_ORDERS WHERE ORDER_STATUS = 'SHIPPED'")
df = pl.from_arrow(reader)
print(df)
conn.close()

Usage

Polars integration

from pyhdb_rs import ConnectionBuilder
import polars as pl

conn = ConnectionBuilder.from_url("hdbsql://USER:PASSWORD@HOST:39017").build()
reader = conn.execute_arrow(
    """SELECT PRODUCT_NAME, SUM(QUANTITY) AS TOTAL_SOLD, SUM(NET_AMOUNT) AS REVENUE
       FROM SALES_ITEMS
       WHERE FISCAL_YEAR = 2025 AND REGION = 'EMEA'
       GROUP BY PRODUCT_NAME
       ORDER BY REVENUE DESC"""
)
df = pl.from_arrow(reader)
print(df.head())
conn.close()

pandas integration

from pyhdb_rs import ConnectionBuilder
import pyarrow as pa

conn = ConnectionBuilder.from_url("hdbsql://USER:PASSWORD@HOST:39017").build()
reader = conn.execute_arrow(
    """SELECT c.CUSTOMER_NAME, COUNT(o.ORDER_ID) AS ORDER_COUNT, SUM(o.TOTAL_AMOUNT) AS TOTAL_SPENT
       FROM CUSTOMERS c
       JOIN SALES_ORDERS o ON c.CUSTOMER_ID = o.CUSTOMER_ID
       WHERE o.ORDER_DATE >= '2025-01-01'
       GROUP BY c.CUSTOMER_NAME
       HAVING SUM(o.TOTAL_AMOUNT) > 5000"""
)
pa_reader = pa.RecordBatchReader.from_stream(reader)
df = pa_reader.read_all().to_pandas()
print(df)
conn.close()

Async support

The async API provides full async/await support with connection pooling.

import asyncio
import polars as pl
from pyhdb_rs.aio import AsyncConnectionBuilder

async def main():
    conn = await (AsyncConnectionBuilder()
        .host("hana.example.com")
        .credentials("USER", "PASSWORD")
        .build())

    async with conn:
        reader = await conn.execute_arrow(
            """SELECT PRODUCT_CATEGORY, COUNT(*) AS ITEM_COUNT, SUM(NET_AMOUNT) AS TOTAL_REVENUE
               FROM SALES_ITEMS
               WHERE ORDER_DATE >= '2025-01-01'
               GROUP BY PRODUCT_CATEGORY"""
        )
        df = pl.from_arrow(reader)
        print(df)

asyncio.run(main())

Note: Use async with for proper resource cleanup. The context manager automatically closes the connection on exit.

Connection pooling

import asyncio
import polars as pl
from pyhdb_rs.aio import create_pool

pool = create_pool(
    "hdbsql://USER:PASSWORD@HOST:39017",
    max_size=10,
    connection_timeout=30
)

async def handle_request(customer_id: int):
    async with pool.acquire() as conn:
        reader = await conn.execute_arrow(
            f"""SELECT o.ORDER_ID, o.ORDER_DATE, o.TOTAL_AMOUNT, o.ORDER_STATUS
                FROM SALES_ORDERS o
                WHERE o.CUSTOMER_ID = {customer_id} AND o.ORDER_DATE >= '2025-01-01'
                ORDER BY o.ORDER_DATE DESC"""
        )
        return pl.from_arrow(reader)

# Run concurrent queries
results = await asyncio.gather(
    handle_request(1001),
    handle_request(1002),
    handle_request(1003)
)

Error handling

from pyhdb_rs import ConnectionBuilder, DatabaseError, InterfaceError

try:
    conn = ConnectionBuilder.from_url("hdbsql://USER:PASSWORD@HOST:39017").build()
    cursor = conn.cursor()
    cursor.execute(
        "SELECT CUSTOMER_NAME, EMAIL FROM CUSTOMERS WHERE REGISTRATION_DATE >= ?",
        ["2025-01-01"]
    )
except DatabaseError as e:
    print(f"Database error: {e}")
except InterfaceError as e:
    print(f"Connection error: {e}")

Type hints

This package is fully typed and includes inline type stubs:

from pyhdb_rs import ConnectionBuilder, Connection, Cursor

def query_data(uri: str, status: str) -> list[tuple[int, str, str]]:
    conn = ConnectionBuilder.from_url(uri).build()
    cursor: Cursor = conn.cursor()
    cursor.execute(
        "SELECT ORDER_ID, CUSTOMER_NAME, ORDER_STATUS FROM SALES_ORDERS WHERE ORDER_STATUS = ?",
        [status]
    )
    result = cursor.fetchall()
    conn.close()
    return result

Requirements

  • Python >= 3.12

Development

git clone https://github.com/bug-ops/pyhdb-rs
cd pyhdb-rs/python

pip install -e ".[dev]"

pytest
ruff check .
mypy .

Documentation

See the main repository for full documentation.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

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

pyhdb_rs-0.3.8.tar.gz (186.4 kB view details)

Uploaded Source

Built Distributions

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

pyhdb_rs-0.3.8-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl (3.5 MB view details)

Uploaded PyPymusllinux: musl 1.2+ x86-64

pyhdb_rs-0.3.8-pp311-pypy311_pp73-musllinux_1_2_aarch64.whl (3.3 MB view details)

Uploaded PyPymusllinux: musl 1.2+ ARM64

pyhdb_rs-0.3.8-cp314-cp314t-musllinux_1_2_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

pyhdb_rs-0.3.8-cp314-cp314t-musllinux_1_2_aarch64.whl (3.3 MB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ ARM64

pyhdb_rs-0.3.8-cp313-cp313t-musllinux_1_2_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ x86-64

pyhdb_rs-0.3.8-cp313-cp313t-musllinux_1_2_aarch64.whl (3.3 MB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ ARM64

pyhdb_rs-0.3.8-cp312-abi3-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.12+Windows x86-64

pyhdb_rs-0.3.8-cp312-abi3-musllinux_1_2_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ x86-64

pyhdb_rs-0.3.8-cp312-abi3-musllinux_1_2_aarch64.whl (3.3 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

pyhdb_rs-0.3.8-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

pyhdb_rs-0.3.8-cp312-abi3-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

pyhdb_rs-0.3.8-cp312-abi3-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

pyhdb_rs-0.3.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file pyhdb_rs-0.3.8.tar.gz.

File metadata

  • Download URL: pyhdb_rs-0.3.8.tar.gz
  • Upload date:
  • Size: 186.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyhdb_rs-0.3.8.tar.gz
Algorithm Hash digest
SHA256 2b40b7905eb0d0e3c7dc51daaf16914a4a254b13aefea3e259ececf1274de1d3
MD5 e57497639fa511c7060b51140afc3a25
BLAKE2b-256 32fdc6799d56bbfb0180c6db39d2920ac20f6744397a0ea39533ad9a15ed0a67

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8.tar.gz:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b6397b3aa21de7a6c1af3050237100c9b18ba9d53255b2652417b371bed3e326
MD5 310590d2187fcee89427d28778948ea1
BLAKE2b-256 22c1424857939977216850e844d88d924c7f9906378eb35fce6a36cce48f587c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-pp311-pypy311_pp73-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-pp311-pypy311_pp73-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 717b058842d0becf760d44d81259744e3928edc46f92c9d91100256609a2fed8
MD5 20696bb4606013f8e6eec4c26d61a83e
BLAKE2b-256 37b566a901c9dc6bfcd37ec8eaf9d3b94458b59d8acdcec8a4fe5b682b513c87

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-pp311-pypy311_pp73-musllinux_1_2_aarch64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp314-cp314t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 660c21bfa0b541dd1de8918d2c261c618b617eb2d0356db79cdb4612ef6b7c83
MD5 347198c3f633e3bec70510065967ba1d
BLAKE2b-256 d90cab46ebb984a987890cd96f22fe042a65bbfb64b6808370125598c24dd289

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp314-cp314t-musllinux_1_2_x86_64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp314-cp314t-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-cp314-cp314t-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cb90c3e4c4d9aa129a355a51c25a7118552fb8be775fd14edbbee5cd1f72be55
MD5 6d84241a66e36890a1b8045fbca91525
BLAKE2b-256 449001da6ed409772cb41cdfc98517a97aa53e50a1c5b7825bbd86f60ae0df0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp314-cp314t-musllinux_1_2_aarch64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp313-cp313t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-cp313-cp313t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ee039f360fff3277cc75c3aa19b1492048a37657f8dfbc87817b9d9203d07a2f
MD5 716ad138e416a25f7d65f2ad2a24a42c
BLAKE2b-256 2048742d3c4d436566664fef33f4c52fb925e79bc9acb537ce7e42eff4bd6757

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp313-cp313t-musllinux_1_2_x86_64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp313-cp313t-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-cp313-cp313t-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 fede15861f037da28ae5148486c2e8923cd9b59cfb4a25e60f2f84623c882938
MD5 8e0b1b5b9e351fefb0d488cd221068bc
BLAKE2b-256 3ac929b3faae95c1e8e2b7d91968caa5b2ec85ffb06a6caee08b0ba7d854a71f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp313-cp313t-musllinux_1_2_aarch64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pyhdb_rs-0.3.8-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyhdb_rs-0.3.8-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 78c7da0f9e6cd6d8c4bdc29c2d789a1893238bb936669ab606b948089aa4f5ca
MD5 1f2d1ea9c762c2c4ebff313fd717fa90
BLAKE2b-256 13988ab436c6f07ababa432c923c9789f1ed987807c40d7a642da025cafaaddf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp312-abi3-win_amd64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fb6533ee7888a7a4b7ca8803594840fc6564d72e5182ba69609e0b4e285110b9
MD5 74fa27a733d83e84ae95fd06e4c9c783
BLAKE2b-256 3172521f9af426ee658dc981d3f87998c6f3a98dc6a0f4f29ba5e2f49cfb07c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp312-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 949127e1420ecb1f54b8c877f5993d371f427e49711081073f5abb6d7294d705
MD5 7ae0e30f1cf9c52e8bd00f9f925fb4cc
BLAKE2b-256 360d7f814d42c6872ecb057714d059b4bece526ec54ad9798f776ced1fc46da7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp312-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3a928f2ed332bfa002c583892fa55eede27af085e433a04a58e87b420916f756
MD5 2c905961ae0a6b3df7d185686f13b138
BLAKE2b-256 cec849e850b1d91eb9c4398fc71109ed89459536668918eb576153e821ef7f87

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8907fd2324ab7409678787181ab553ca04bf445886d95764d79b2588870df607
MD5 de89295f3f354c480579bfb65ee181c4
BLAKE2b-256 54df1239a51569dc97930bda0423c71f91e4a5b427ddf1ef65064da8b4223ab3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e23729c97c08f8fc4a355e547e8e8317c8363a7703acce69c9f3543bfd1fce50
MD5 6eca0088f8afcfae4d099590ea24ab11
BLAKE2b-256 5dac9c9ef0cb477b418b9a89497640aab374afbe4a5d10e2f01a7c7f612a25fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp312-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhdb_rs-0.3.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 14b0e7184be0ae5bb929f319fe05e39bef0277ddaa5bb909e4cc15540ec5256b
MD5 2a477f5f88a3aac05b74b63f3e02fd1b
BLAKE2b-256 0308c73282883d32ec9d8e10d90d3c69f65c35e0dd3e9c01538f2e6289ae7353

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on bug-ops/pyhdb-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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