---
title: "Python API - DuckDB"
description: "!https://duckdb.org/docs/api/python/overview.html"
date: 2023-07-28
published: true
tags:
  - data
  - duckdb
  - python
  - 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()
```
