Skip to main content

Python Guide: Loading Data from SQL Databases to Athena using dlt Library

Need help deploying these pipelines, or figuring out how to run them in your data stack?

Join our Slack community or book a call with our support engineer Adrian.

Welcome to the technical documentation page about loading data from sql_database to athena using the open source Python library, dlt. Sql_database is a Database Management System (DBMS) that stores structured data, while athena is an Amazon service for data analysis in Amazon S3. The dlt library facilitates this process.

dlt Key Features

  • Easy to get started: dlt is a Python library that is easy to use and understand. It is designed to be simple to use and easy to understand. Type pip install dlt and you are ready to go.
  • User friendly interface: dlt is designed to be user friendly. It has a simple and intuitive declarative interface that makes it easy to use and understand. Low code but not no code.
  • Extensible & Open Source: dlt is designed to be extensible. You can add new sources and destinations to dlt by writing a few lines of Python code, or use our verified sources and extend them.
  • Community Support & Documentation: dlt is fully open source and has a growing community of users and contributors. We have a community slack and documentation to help you get started.

Getting started with your pipeline locally

1. Install dlt

First you need to install the dlt library with the correct extras for athena:

pip install "dlt[athena]"

The dlt cli has a useful command to get you started with any combination of source and destination. You can run the following command to see all available sources:

dlt init --list

For this example, we want to load data from sql_database to athena. You can run the following commands to create a starting point for loading data from sql_database to athena:

# create a new directory
mkdir my-sql_database-pipeline
cd my-sql_database-pipeline
# initialize a new pipeline with your source and destination
dlt init sql_database athena
# install the required dependencies
pip install -r requirements.txt

The last command will install the required dependencies for your pipeline. The dependencies are listed in the requirements.txt:


2. Configuring your source and destination credentials

The dlt cli will have created a .dlt directory in your project folder. This directory contains a config.toml file and a secrets.toml file that you can use to configure your pipeline:


# put your configuration values here

log_level="WARNING" # the system log level of dlt
# use the dlthub_telemetry setting to enable/disable anonymous usage data reporting, see
dlthub_telemetry = true


# put your secret values and credentials here. do not share this file and do not push it to github

drivername = "drivername" # please set me up!
database = "database" # please set me up!
password = "password" # please set me up!
username = "username" # please set me up!
host = "host" # please set me up!
port = 0 # please set me up!

query_result_bucket = "query_result_bucket" # please set me up!
athena_work_group = "athena_work_group" # please set me up!

aws_access_key_id = "aws_access_key_id" # please set me up!
aws_secret_access_key = "aws_secret_access_key" # please set me up!
Settings up your integrations

Please consult the detailed setup instructions for the athena destination in the dlt destinations documentation.

Likewise you can find the setup instructions for sql_database source in the dlt verifed sources documentation.

3. Running your pipeline for the first time

The dlt cli has also created a main pipeline script for you at, as well as a folder sql_database that contains additional python files for your source. These files are your local copies which you can modify to fit your needs. In some cases you may find that you only need to do small changes to your pipelines or add some configurations, in other cases these files can serve as a working starting point for your code, but will need to be adjusted to do what you need them to do.

After you have set up your credentials, you can run your pipeline like a regular python script with the following command:


4. Inspecting your load result

You can now inspect the state of your pipeline with the dlt cli:

dlt pipeline rfam_database info 

You can also use streamlit to inspect the contents of your athena destination for this:

# install streamlit
pip install streamlit
# run the streamlit app for your pipeline with the dlt cli:
dlt pipeline rfam_database show

5. Next steps to get your pipeline running in production

One of the beauties of dlt is, that we are just a plain Python library, so you can run your pipeline in any environment that supports Python >= 3.8. We have a couple of helpers and guides in our docs to get you there:

Pipeline output to destination

After running the initial version pipeline, you can expect the following tables to be created in your destination:

Table NameDescription
familyThis table contains various information about a family. It has fields such as author, clen, cmbuild, description, number_of_species, previous_id, rfam_acc, and many others. It appears to be related to some kind of biological or genetic data, possibly related to genomics or bioinformatics.

Additional pipeline guides

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!


Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.