Skip to main content

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

Project description

pyhdb-rs

PyPI Python 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

Installation

pip install pyhdb_rs

With optional dependencies

pip install pyhdb_rs[polars]    # Polars integration
pip install pyhdb_rs[pandas]    # pandas + PyArrow
pip install pyhdb_rs[all]       # All integrations

[!TIP] Use uv pip install pyhdb_rs for faster installation (10-100x faster than pip).

Quick start

from pyhdb_rs import connect

with connect("hdbsql://user:pass@host:39017") as conn:
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM MY_TABLE")
    for row in cursor:
        print(row)

Usage

Polars integration

import pyhdb_rs.polars as hdb

df = hdb.read_hana(
    "SELECT * FROM sales WHERE year = 2024",
    "hdbsql://user:pass@host:39017"
)
print(df.head())

pandas integration

import pyhdb_rs.pandas as hdb

df = hdb.read_hana(
    "SELECT * FROM sales",
    "hdbsql://user:pass@host:39017"
)

Async support

from pyhdb_rs.aio import connect

async with connect("hdbsql://user:pass@host:39017") as conn:
    cursor = await conn.cursor()
    await cursor.execute("SELECT * FROM MY_TABLE")
    async for row in cursor:
        print(row)

[!NOTE] Use async with for proper resource cleanup. The context manager handles connection pooling automatically.

Connection pooling

from pyhdb_rs.aio import ConnectionPool

pool = ConnectionPool(
    uri="hdbsql://user:pass@host:39017",
    min_connections=2,
    max_connections=10,
)

async with pool.acquire() as conn:
    cursor = await conn.cursor()
    await cursor.execute("SELECT 1")

Error handling

from pyhdb_rs import connect, DatabaseError, InterfaceError

try:
    with connect("hdbsql://user:pass@host:39017") as conn:
        cursor = conn.cursor()
        cursor.execute("SELECT * FROM nonexistent")
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 connect, Connection, Cursor

def query_data(uri: str) -> list[tuple[int, str]]:
    with connect(uri) as conn:
        cursor: Cursor = conn.cursor()
        cursor.execute("SELECT id, name FROM users")
        return cursor.fetchall()

Requirements

  • Python >= 3.11

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.1.0.tar.gz (81.6 kB view details)

Uploaded Source

Built Distribution

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

pyhdb_rs-0.1.0-cp311-abi3-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyhdb_rs-0.1.0.tar.gz
  • Upload date:
  • Size: 81.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for pyhdb_rs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3b7425e65ac69a1d57c0c6099b76fedbd94c07356e08201dff966927efb965e
MD5 51a4befaa6487e25dea7a1aed2a4ac40
BLAKE2b-256 048cb43182016e7f114e608ec55874449089a8eb41d6f15fdcf128b65e63972e

See more details on using hashes here.

File details

Details for the file pyhdb_rs-0.1.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyhdb_rs-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5afbfa4f769d1a8f7a6b030422deb26c8f65186c83b0395f1203353c919c4097
MD5 9809330cdab7a642ef44b0a0945f57b7
BLAKE2b-256 48682cfa3baad45cea88351bca1e7c2bd28981a7a4cbb2cf8cea7c964dc54ff6

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