DuckDB Extensions

1.5.1 · active · verified Fri Apr 17

duckdb-extensions provides a comprehensive set of pip-installable DuckDB extensions, acting as a meta-package or individual `duckdb-extension-*` packages. It allows users to easily add capabilities like HTTPFS, Parquet, JSON, and Spatial functions to their DuckDB installations. The current version is 1.5.1, and releases closely track new DuckDB versions, offering frequent updates to maintain compatibility and leverage the latest features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install `duckdb-extensions` (which makes the binaries available), and then use the `duckdb` Python library to connect to DuckDB and load an extension (e.g., `httpfs`) via SQL commands within the session. It then provides a simple example of using the loaded extension to query a remote Parquet file.

import duckdb
import os

# Connect to an in-memory DuckDB database
con = duckdb.connect(database=':memory:', read_only=False)

# The duckdb-extensions package makes compiled extensions available.
# You can then install and load them within your DuckDB session via SQL.

try:
    # Example: Install and Load the HTTPFS extension
    # This allows DuckDB to read data directly from HTTP(S) URLs.
    con.execute("INSTALL httpfs;")
    con.execute("LOAD httpfs;")
    print("HTTPFS extension loaded successfully.")

    # Example usage: Query a remote Parquet file (using a placeholder URL)
    # Replace with a real URL if you want to run this example fully.
    sample_url = os.environ.get('DUCKDB_SAMPLE_PARQUET_URL', 'https://duckdb.org/data/nyc_taxi_2019-01.parquet')
    print(f"Attempting to query data from: {sample_url}")
    
    # Execute a query using the loaded extension
    result = con.execute(f"SELECT count(*) FROM '{sample_url}';").fetchone()
    print(f"Count from remote parquet (first row): {result}")

except duckdb.DuckDBPyConnectionException as e:
    print(f"Error loading extension or executing query: {e}")
    print("HINT: Ensure 'duckdb-extensions' is installed and its version matches your 'duckdb' library version.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")
finally:
    con.close()
    print("DuckDB connection closed.")

view raw JSON →