The DuckDB Python package connects Python programs to DuckDB, supports in-memory or file-backed databases, and provides a direct path from Python workflows to SQL operations. section 6.1
A practical setup usually includes:
- Install the package with pip, import duckdb, and inspect duckdb.__version__. section 6.1.1
- Open a database file, including read-only mode when an application only queries existing data. section 6.1 section 9.1.2
- Use SQL from Python to load CSV files, convert column types, and populate tables. section 8.4.1
Querying a file-backed database
import duckdb atp_duck = duckdb.connect('atp.duckdb', read_only=True) query = ''' SELECT DISTINCT winner_name AS player FROM matches WHERE player ilike '%' || $search_term || '%' ''' values = atp_duck.execute(query, {"search_term": "Novak"}).fetchall() section 9.1.2
pip install duckdb
Use the installation command as the quickest entry point before importing and checking the package version. section 6.1.1
