Skip to content
DuckDB community extension

python_udf

Embedded CPython UDFs for DuckDB — py_eval, py_agg, py_scan, py_register, py_call, py_map

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL python_udf FROM community;
LOAD python_udf FROM community;

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

SQL
SELECT py_eval('lambda x: x * 2 + 1', x) FROM range(10) t(x);

-- Aggregate UDF
SELECT py_agg('sum', x) FROM range(100) t(x);

-- Scan from Python
SELECT * FROM py_scan('lambda _: [{"a":1}, {"a":2}]');

-- Register persistent UDF
SELECT py_register('dbl', 'lambda x: x * 2');

-- Call registered UDF
SELECT py_call('dbl', 21);

-- Map values
SELECT py_map('ord', 'hello world');

Provided by alitrack. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

Execute Python code directly in SQL queries with CPython embedded in DuckDB.

Note: Extension binary name is python_udf to avoid collision with DuckDB's core python extension. The source repository remains duckdb-python.

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
alitrack/duckdb-python
License
MIT
Maintainers
alitrack
Written in
Rust & Python
Build source
901a7bdbc3a1
Build definition
Community descriptor