---
title: "💭 Python API - DuckDB"
description: "!https://duckdb.org/docs/api/python/overview.html"
date: 2023-07-28
published: true
tags:
  - python
  - data
  - duckdb
  - thought
template: link
---


![https://duckdb.org/docs/api/python/overview.html](/static/https://duckdb.org/docs/api/python/overview.html)

To persist data in duckdb you need to first make a connection to a duck db database.

``` python
con = duckdb.connect('file.db')
```

Then work off of the connection `con` rather than `duckdb`.


``` python
con.sql('CREATE TABLE test(i INTEGER)')
con.sql('INSERT INTO test VALUES (42)')
# query the table
con.table('test').show()
# explicitly close the connection
con.close()
```

!!! note

    This post is a <a href="/thoughts/" class="wikilink" data-title="Thoughts" data-description="These are generally my thoughts on a web page or some sort of url, except a rare few don&#39;t have a link. These are dual published off of my..." data-date="2024-04-01">thought</a>. It's a short note that I make
    about someone else's content online <a href="/tags/thoughts/" class="hashtag-tag" data-tag="thoughts" data-count=2 data-reading-time=3 data-reading-time-text="3 minutes">#thoughts</a>
