📘 Introduction

DuckDB has quickly become a favorite tool among data engineers and analysts because of its speed, simplicity, and ability to run analytical SQL queries directly within Python. Whether you’re prototyping data pipelines, running local analytics, or managing lightweight data storage, knowing how to insert data into DuckDB is essential.

In this guide, we’ll cover the most common ways to insert data into DuckDB using Python—with practical examples.

✅ Prerequisites

Before you begin, make sure you have:

🐍☑️ Installed Python
📦☑️ Installed DuckDB
🌐☑️ Created and activated a virtual environment (venv)

📥1️⃣ Import Libraries

Start by importing the required Python modules:

import duckdb

🔗2️⃣ Establish Connection to DuckDB Database file

Establish the connection to a DuckDB database file:

con = duckdb.connect("dlnerds_university.duckdb")
💡
If the file doesn’t exist, DuckDB will create it automatically.

🏗️3️⃣ Create Table Using SQL CREATE TABLE

Let’s create a simple student table:

You can view this post with the tier: Academy Membership

Join academy now to read the post and get access to the full library of premium posts for academy members only.

Join Academy Already have an account? Sign In