Status:
- Work in progress, many parts of the API are still missing (PRs welcome).
from duckdb import *
var con = DuckDB.connect(":memory:")
_ = con.execute(
"""
CREATE TABLE train_services AS
FROM 's3://duckdb-blobs/train_services.parquet';
"""
)
var result = con.execute(
"""
-- Get the top-3 busiest train stations
SELECT station_name, count(*) AS num_services
FROM train_services
GROUP BY ALL
ORDER BY num_services DESC
LIMIT 3;
"""
).fetch_all()
for col in result.columns():
print(col[])
print()
for row in range(len(result)):
print(
result.get(varchar, col=0, row=row).value(),
" ",
result.get(bigint, col=1, row=row).value(),
)
- Install Mojo. Currently nightly >=
2024.7.1105
is required, so install or update the nightly version:modular install nightly/mojo
- Download the DuckDB C/C++ library from the installation page.
- Extract
libduckdb.so
(Linux) orlibduckdb.dylib
(macOS) to the project directory. - Set library path:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(realpath .) # Linux
export DYLD_FALLBACK_LIBRARY_PATH=$(realpath .) # macOS
- Run
mojo example.mojo
mojo test -I .