Connecting to DuckDB in Python
When working with DuckDB in Python, the first thing to consider is how you’ll connect to a target DuckDB database from your Python code. Even though DuckDB runs embedded within a parent process, meaning that you don’t have to worry about authenticating to a remote server, you still need to consider how your Python process will make and manage connections to potentially multiple DuckDB databases.
In this section, we’ll be covering the two broad ways to issue commands to DuckDB databases in Python:
- Using the default in-memory database: This database is automatically created for you when you import the
duckdb
module. The default database provides a convenient way to quickly perform activities such as ad-hoc data analysis when you know you will only need a single database in your session. This is what you will connect to when you invoke a function from theduckdb
module that interacts with a database, such asduckdb.sql()
and...