Skip to main content

Dispatch stream of events to multiple tables in DuckDB

This is a practical example of how to process GitHub events from the dlt repository, such as issues or pull request creation, comments addition, etc. We'll use the GitHub API to fetch the events and duckdb as a destination. Each event type will be sent to a separate table in DuckDB.


  1. Install dlt with duckdb support:
pip install dlt[duckdb]
  1. Create a new a new file and paste the following code:
import dlt
from dlt.sources.helpers import requests

table_name=lambda i: i["type"],
def repo_events(last_created_at=dlt.sources.incremental("created_at")):
url = ""

while True:
response = requests.get(url)
yield response.json()

# stop requesting pages if the last element was already older than
# the initial value
# note: incremental will skip those items anyway, we just do not
# want to use the api limits
if last_created_at.start_out_of_range:

# get next page
if "next" not in response.links:
url = response.links["next"]["url"]

pipeline = dlt.pipeline(
load_info =
row_counts = pipeline.last_trace.last_normalize_info


In the code above we define a resource repo_events that fetches events from the GitHub API.

Events content never changes so we can use append write disposition and track new events using created_at field.

We name the tables using a function that receives an event data and returns table name: table_name=lambda i: i["type"]

  1. Now run the script:
  1. Peek at created tables:
dlt pipeline -v github_events info
dlt pipeline github_events trace
  1. And preview the data:
dlt pipeline -v github_events show

Some of the events produce tables with really many child tables. You can control the level of table nesting with a decorator.

Another fun Colab Demo - we analyze reactions on duckdb repo!

Learn more:

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.