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.10.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.10-cp312-abi3-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.12+Windows x86-64

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

Uploaded CPython 3.12+macOS 11.0+ ARM64

pyhdb_rs-0.3.10-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.10.tar.gz.

File metadata

  • Download URL: pyhdb_rs-0.3.10.tar.gz
  • Upload date:
  • Size: 186.4 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.10.tar.gz
Algorithm Hash digest
SHA256 20863fd2252af55e4e5a5d9e46f7d05fb6022952d8565920e87173ce9b42dc1e
MD5 fb53f877992de7a2a94e616fec6e33f9
BLAKE2b-256 761f93c9ec65f3c2cdd5696aa6c000cd4a192ee2ca7bf019f2372f7416ef22ae

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyhdb_rs-0.3.10-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.10-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 703ef37b1e988df7a1007ca9871e21b3bbf82f84fba34ac5824d40712fdaf14f
MD5 ef82dc54d40b0494ec8af60a90e7a5f8
BLAKE2b-256 328d3968c3d1d139e49dcc6d4bbe4a2148e6de79b133bb51152bfa7c3243e1a8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyhdb_rs-0.3.10-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fa04e5b0379d7b4a07c72279272ae9af33fd9091321bc6bc48ac36298349a035
MD5 b2ed0c7c7821d738e16544ce3f9f43fa
BLAKE2b-256 2e62ed1745d08c17628a61cd7decd5887385a16094d75a86beb6315cc8192e0d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyhdb_rs-0.3.10-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 ad451f7fd9d718a8ffa7025a3c5fade1a35aa67c43e0f9464906b029e4ab3860
MD5 54468945382318b169de3c413ec277f4
BLAKE2b-256 f4fd24205e3b73763a40166ccca260223fb50fabd13cf08580230f8e17fba8a5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyhdb_rs-0.3.10-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2d8d59c314a1b5412ccfb8ef0d46eb24be17d63c1f8c5f2fbfed5325e8ff2180
MD5 954e7f0d996545fe0a208f13695909cf
BLAKE2b-256 1dd7918e9c8e9d75228ece341618d176efb456f9a16da292a3247d8bdbed8592

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhdb_rs-0.3.10-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.10-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.3.10-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d73a20d564e53e65c1a63ee52ba108d1b44940a5ca7f78fdaec266b1a0b1494a
MD5 aa104021c4c9531dcdd911433fe55432
BLAKE2b-256 e3a39464b4e2661fa904cd158daeb15837cfe25866910e0bc6d1ac198755bc8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyhdb_rs-0.3.10-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cf5c1d5ae9bde0ea6080ee01e2d4f4f6186c2ad7c89e9a15d0386bfef0c546c7
MD5 c5abe79266f9ae0d35df0273fb57d318
BLAKE2b-256 159975ee2735c91bcc76515e5fa3f0b092a7fcb287920bec41c248c4710b451d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyhdb_rs-0.3.10-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3ff63ab60513f3d9ba4ec61ac07ef37ea5bc3d09fb774a5bb36fc68efdb6ba74
MD5 c6874255c7b9be428a392dcac0fca5f4
BLAKE2b-256 0cf8546d1a600154e56334973bc1b65d22c9b2e4af2b4fc120f1b0233e6a1eb8

See more details on using hashes here.

Provenance

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