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.11.tar.gz (186.5 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.11-cp312-abi3-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.12+Windows x86-64

pyhdb_rs-0.3.11-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.11-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.11-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

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

pyhdb_rs-0.3.11-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.11-cp312-abi3-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

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

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyhdb_rs-0.3.11.tar.gz
Algorithm Hash digest
SHA256 038fc3602f9c3e3e2128fa04d8783e6db4bfbbe8011fed44588c8812a998b86e
MD5 83dd20a9765c81b2af0315bc7ee83cb6
BLAKE2b-256 998239f414be34dcfbfc3df374f120c385afa265f5c7873bb134a39d6c420110

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.11.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.11-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pyhdb_rs-0.3.11-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.12

File hashes

Hashes for pyhdb_rs-0.3.11-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 769d05cdf5fa4061ea26eb98ba412591ef9fbd386f7902fca8d5c7caa4b36360
MD5 7791fd5a319b96e3ea55849029572d51
BLAKE2b-256 b75d8ec4dcd7c9bea95c641bdcec86d6b6e1ec2b5e12ea3a60191217cd4074d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.11-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.11-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.11-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0e4ceab3e0831c12c30c16356dab1e7ed473868110a2430a51f8d267badd5e51
MD5 4027860dd4d2d8ee7dcc81a86c8de449
BLAKE2b-256 5a240056a3f66cbc5f0ee9018b84f5ca87d562767b8c64eba54b89729b23669d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.11-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.11-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.11-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 ad7b89a77f0f848ec7cd1dd911c02cae57fb061e972aa017fe41d507f9c8f85a
MD5 44f9ee348ac86668f37ef7660a5db1ab
BLAKE2b-256 900810acf39b315a1aabdbe5ccc3642b9536d225858207d2b2d12d9b704d6afd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.11-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.11-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.11-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf30dd6110cb75203e9afbe870e5ac351de602229c802d2a54b5b0df0366218f
MD5 30fa4fd00b5bf9fac0c613160b38bb43
BLAKE2b-256 d01403a655ccb261e5f2fa3cbdd40f89132d15a4524f5258aa264f8faaa28817

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.11-cp312-abi3-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.

File details

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

File metadata

File hashes

Hashes for pyhdb_rs-0.3.11-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3b7662931a1a2e6b30065b5be5cbc9c2e4c0c8c7874be366c540449aa2a570d1
MD5 08067a3c46886644c8d9a4fff39236ee
BLAKE2b-256 24a0eb485de6905fefcd86f881b2e2524ae50c81bec446cf96795e09877ab945

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.11-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.11-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.11-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 809d4400a3d4b14b68316268a9669658a4259e38f3c31c2ac5cbf4ff3304d922
MD5 90da8842419d59c3b494844c5783c26d
BLAKE2b-256 38ba8a7cb9e6eaa17482f3fdf6f098937b20b844ed586d5508107a5f5e832f09

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.11-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.11-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.11-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e91ffab45fe857bb69b43ebb7d4fb48db03cc21ac2270e6fedca99c05ed54b0b
MD5 0f50b673094cdefdb3fac1acf4919db0
BLAKE2b-256 4f485078726d03f6eb25ca940794dce5807c8493324effe43353e73747c31862

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.11-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.

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