SAP HANA Python Database Docs | dltHub
Build a SAP HANA-to-database pipeline in Python using dlt with AI harness support for Claude Code, Cursor, and Codex.
Last updated:
SAP HANA is an in-memory relational database that can be used with SQLAlchemy through the sqlalchemy-hana dialect. dlt connects to it through SQLAlchemy with the hana+hdbcli driver from the hdbcli package, reads the table schemas from the database, and loads the tables you choose into any destination.
dlt is an open-source Python library that handles schema inference, incremental loading, and schema evolution automatically. dlthub provides AI context files that enable code assistants to generate production-ready pipelines. Install with uv add "dlt[hub,sql_database]" and start loading SAP HANA data in under 10 minutes.
How do I choose what to load from SAP HANA?
The sql_database source reads the schema of each table you name and turns it into a resource, so the pipeline works with whatever tables your database holds. These options narrow a load down to what you need:
| To load | Use |
|---|---|
| A single table | sql_table(table="orders") |
| A specific schema | sql_database(schema="MY_SCHEMA") |
| Views as well as tables | sql_database(include_views=True) |
| Only some columns | sql_table(table="orders", included_columns=["id", "status"]) |
| Only some rows | sql_database(query_adapter_callback=...) |
Always pass table_names=[...] to sql_database(): without it, dlt reflects every table in the schema before loading anything. SAP HANA stores unquoted names in upper case, so a table created as orders is usually named ORDERS here.
How do I connect to the SAP HANA database?
dlt needs a database user with read access to the tables you want to load. Add its connection details to .dlt/secrets.toml:
[sources.sql_database.credentials] drivername = "hana+hdbcli" host = "localhost" port = 30015 username = "my_user" password = "my_password" database = "my_database"
Or as a single connection string:
[sources.sql_database] credentials = "hana+hdbcli://my_user:my_password@localhost:30015/my_database"
Use the sqlalchemy-hana dialect with the hdbcli driver. The dialect determines its default schema by querying CURRENT_USER; SAP HANA creates a schema with the user's name and uses it as that user's default schema. For ordinary SAP HANA identifiers, use lowercase names in SQLAlchemy—even though HANA reports unquoted identifiers in uppercase—because uppercase SQLAlchemy names are treated as quoted, case-sensitive identifiers by the dialect.
dlt reads this automatically at runtime — never hardcode credentials in your pipeline script. For production environments, see setting up credentials with dlt for environment variable and vault-based options.
How do I set up and run the pipeline?
Set up a virtual environment and install dlt:
uv init uv add "dlt[hub,sql_database]" hdbcli
1. Install the dlt AI harness:
uv run dlthub ai init --agent <your-agent> # <agent>: claude | cursor | codex
This installs project rules, a secrets management skill, appropriate ignore files, and configures the dlt MCP server for your agent. Learn more →
2. Install the sql-database-pipeline toolkit:
uv run dlthub ai toolkit install sql-database-pipeline
This loads the skills and context about dlt the agent uses to connect to the database, choose tables, and build the pipeline safely. The agent uses MCP tools to inspect credentials — it never needs to read your secrets.toml directly. Learn more →
3. Start LLM-assisted coding:
Use /find-source to load tables from my SAP HANA database into DuckDB.
The sql-database-pipeline toolkit takes over from here — it checks whether a specialised source fits better, lists the schemas and tables in your database, asks which tables to load and whether you need normalization, then scaffolds a one-table pipeline and runs it with a load limit before scaling up.
4. Run the pipeline:
uv run python sql_database_pipeline.py
If everything is configured correctly, you'll see output like this:
Pipeline sap_hana_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset sap_hana_data The duckdb destination used duckdb:/sap_hana_pipeline.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs
Inspect your pipeline and data:
uv run dlthub show
This opens the Pipeline Dashboard where you can verify pipeline state, load metrics, schema (tables, columns, types), and query the loaded data directly.
Python pipeline example
This example loads the customers and orders tables from the MY_SCHEMA schema into DuckDB. Replace the table names with your own:
import dlt from dlt.sources.sql_database import sql_database def load_tables() -> None: source = sql_database( schema="MY_SCHEMA", table_names=["customers", "orders"], ) pipeline = dlt.pipeline( pipeline_name="sap_hana_pipeline", destination="duckdb", dataset_name="sap_hana_data", ) load_info = pipeline.run(source, write_disposition="replace") print(load_info) if __name__ == "__main__": load_tables()
Credentials are not passed in the code: sql_database() reads them from [sources.sql_database] in .dlt/secrets.toml.
Load only new and changed rows:
Reloading a large table on every run is rarely what you want. Give each table a cursor column and a primary key, and dlt loads only rows changed since the last run and merges them into the destination:
source.orders.apply_hints( incremental=dlt.sources.incremental("updated_at"), write_disposition="merge", primary_key="id", )
Use a timestamp such as updated_at for tables whose rows change, and an increasing id for append-only tables. The toolkit's /adjust-table skill sets this up for you.
Which backend should I use?
The backend decides how rows are read from SAP HANA. The default, sqlalchemy, works everywhere but is the slowest; switch once the pipeline works:
| Data size | Backend | Why |
|---|---|---|
| Under 100k rows | sqlalchemy (default) | Works with every destination, no extra dependencies |
| 100k – 10M rows | pyarrow | 20–30× faster, keeps decimal and date types exact; needs numpy |
| Over 10M rows | pyarrow | connectorx does not support SAP HANA |
source = sql_database( schema="MY_SCHEMA", table_names=["customers", "orders"], backend="pyarrow", chunk_size=50000, )
pyarrow, pandas and connectorx skip dlt's row-by-row normalization. The toolkit's /optimize-sql-performance skill measures where time goes and picks a backend, chunk size and parallelism for you. See configuring the backend.
How do I query the loaded data?
Once the pipeline runs, dlt creates one table per source table. You can query with Python or SQL.
Python (pandas DataFrame):
import dlt data = dlt.pipeline("sap_hana_pipeline").dataset() orders_df = data.orders.df() print(orders_df.head())
SQL (DuckDB example):
SELECT * FROM sap_hana_data.orders LIMIT 10;
In a marimo or Jupyter notebook:
import dlt data = dlt.pipeline("sap_hana_pipeline").dataset() data.orders.df().head()
See how to explore your data in marimo Notebooks and how to query your data in Python with dataset.
What destinations can I load SAP HANA data to?
dlt supports loading into any of these destinations — only the destination parameter changes:
| Destination | Example value |
|---|---|
| DuckDB (local, default) | "duckdb" |
| PostgreSQL | "postgres" |
| BigQuery | "bigquery" |
| Snowflake | "snowflake" |
| Redshift | "redshift" |
| Databricks | "databricks" |
| Filesystem (S3, GCS, Azure) | "filesystem" |
Change the destination in dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. See the full destinations list.
Next steps
Continue your data engineering journey with the other toolkits of the dltHub AI harness:
data-exploration— Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.dlthub-platform— Deploy, schedule, and monitor your pipeline in production.
uv run dlthub ai toolkit install data-exploration uv run dlthub ai toolkit install dlthub-platform
Was this page helpful?
Community Hub
Need more dlt context for SAP HANA?
Request dlt skills, commands, AGENT.md files, and AI-native context.