Apache Kylin Database Python Docs | dltHub
Build a Apache Kylin-to-database pipeline in Python using dlt with AI harness support for Claude Code, Cursor, and Codex.
Last updated:
Apache Kylin is an open-source distributed analytical data warehouse that provides OLAP query capabilities over large datasets. dlt connects to it through SQLAlchemy with the kylin driver from the kylinpy 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 Apache Kylin data in under 10 minutes.
How do I choose what to load from Apache Kylin?
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 database | sql_database(schema="PROJECT") |
| 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 database before loading anything. Apache Kylin stores unquoted names in upper case, so a table created as orders is usually named ORDERS here.
How do I connect to the Apache Kylin 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 = "kylin" host = "localhost" port = 7070 username = "my_user" password = "my_password" database = "my_database"
Or as a single connection string:
[sources.sql_database] credentials = "kylin://my_user:my_password@localhost:7070/my_database"
Use the kylinpy SQLAlchemy dialect; its package registers the kylin dialect and supports a project in the connection URL. The dialect uses Kylin's HTTP API rather than a conventional DBAPI driver, so table discovery may expose identifiers in uppercase, as shown by its example.
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]" kylinpy
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 Apache Kylin 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 apache_kylin_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset apache_kylin_data The duckdb destination used duckdb:/apache_kylin_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 PROJECT database 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="PROJECT", table_names=["customers", "orders"], ) pipeline = dlt.pipeline( pipeline_name="apache_kylin_pipeline", destination="duckdb", dataset_name="apache_kylin_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 Apache Kylin. 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 Apache Kylin |
source = sql_database( schema="PROJECT", 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("apache_kylin_pipeline").dataset() orders_df = data.orders.df() print(orders_df.head())
SQL (DuckDB example):
SELECT * FROM apache_kylin_data.orders LIMIT 10;
In a marimo or Jupyter notebook:
import dlt data = dlt.pipeline("apache_kylin_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 Apache Kylin 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 Apache Kylin?
Request dlt skills, commands, AGENT.md files, and AI-native context.