Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sbrunk/duckdb.mojo
Mojo Bindings for DuckDB
https://github.com/sbrunk/duckdb.mojo
duckdb mojo
Last synced: about 4 hours ago
JSON representation
Mojo Bindings for DuckDB
- Host: GitHub
- URL: https://github.com/sbrunk/duckdb.mojo
- Owner: sbrunk
- License: mit
- Created: 2024-06-24T07:09:15.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-07T15:49:57.000Z (17 days ago)
- Last Synced: 2024-09-07T17:21:54.229Z (17 days ago)
- Topics: duckdb, mojo
- Language: Mojo
- Homepage:
- Size: 206 KB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-max-mojo-mlir - sbrunk/duckdb.mojo
- awesome-max-mojo-mlir - sbrunk/duckdb.mojo
README
# duckdb.mojo
[Mojo](https://www.modular.com/mojo) bindings for [DuckDB](https://duckdb.org/).
Status:
- Work in progress, many parts of the API are still missing (PRs welcome).## Example
```mojo
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(),
)
```## Installation
1. [Install Mojo](https://docs.modular.com/mojo/manual/get-started#1-install-mojo). Currently nightly >= `2024.7.1105` is required, so install or update the nightly version: `modular install nightly/mojo`
2. Download the DuckDB C/C++ library from the [installation](https://duckdb.org/docs/installation/?version=stable&environment=cplusplus) page.
3. Extract `libduckdb.so` (Linux) or `libduckdb.dylib` (macOS) to the project directory.
4. Set library path:
```shell
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(realpath .) # Linux
export DYLD_FALLBACK_LIBRARY_PATH=$(realpath .) # macOS
```
5. Run
``` shell
mojo example.mojo
```### Run Tests
```shell
mojo test -I .
```