Skip to content

Commit dd3493f

Browse files
authored
Merge pull request #21 from motherduckdb/installation
Simplified setup to use the local DuckDB UI!
2 parents 86b4b2a + 2753945 commit dd3493f

1 file changed

Lines changed: 16 additions & 88 deletions

File tree

setup-instructions.md

Lines changed: 16 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -14,98 +14,26 @@ kernelspec:
1414

1515
# Setup instructions
1616

17-
To get started with the tutorial, you'll need an interactive Python notebook environment.
17+
Welcome! It's officially SQL-o-clock!
1818

19-
## Option 1: Run in Colab
19+
For the initial, SQL-only sections of this tutorial, please install the DuckDB command line interface (CLI) and load the tutorial notebooks following the steps below:
2020

21-
To get started without any setup required, <a target="_blank" href="https://colab.research.google.com/github/motherduckdb/sql-tutorial">open the tutorial in Colab</a>.
21+
## Sections 1 and 2
2222

23-
This requires a Google account. If you don't have one, you can <a href="https://accounts.google.com/signup" target="_blank">sign up</a>, or try the other options below.
23+
1. Follow the DuckDB CLI installation instructions for your OS and CPU
24+
2. Create a these folders in your user directory:
25+
1. MacOS and Linux: `~/.duckdb/extension_data/ui`
26+
2. Windows: `%userprofile%\.duckdb\extension_data\ui`
27+
3. Copy the tutorial notebook data stored in the file [ui.db](https://github.com/motherduckdb/sql-tutorial/raw/refs/heads/main/ui.db) into that folder
28+
1. Note: If you have already used the DuckDB Local UI, rename the existing ui.db and ui.db.wal before copying over the new ui.db from the link above.
29+
4. Ensure that duckdb is added to your path, or navigate to the folder where you saved the DuckDB CLI
30+
5. Run `duckdb -ui` (or `./duckdb -ui` if it is not on your path), and we are off and flying!
31+
1. Your browser should automatically open to `http://localhost:4213/` - go there to see the UI!
2432

25-
## Option 2: Run in Jupyter Notebook on your laptop
33+
## Section 3
2634

27-
1. Browse to a folder in your home directory where you want to keep your tutorial files and clone the GitHub repo:
28-
```bash
29-
git clone git@github.com:motherduckdb/sql-tutorial.git
30-
```
31-
2. Create a new Python virtual environment and activate it:
32-
```bash
33-
python3 -m venv venv
34-
source venv/bin/activate
35-
```
36-
3. Start a local <a href="https://jupyter.org/install" target="_blank">Jupyter Notebook</a> in the `notebooks` folder:
37-
```
38-
cd notebooks
39-
jupyter notebook .
40-
```
35+
For the sections that cover combining SQL and Python, see the installation instructions in section 3.
4136

42-
Now you can open the `.ipynb` files accompanying the tutorial and run them cell by cell, add your own cells or make edits where needed.
37+
## Section 4
4338

44-
## Option 3: Run in MotherDuck
45-
46-
For the parts that require only SQL, you can run them in the MotherDuck app. To access the app, <a href="https://app.motherduck.com/?auth_flow=signup" target="_blank">sign up for MotherDuck</a>.
47-
48-
Every new account receives a 30-day free trial of the MotherDuck Standard Plan, with no credit card required. After the end of your Standard Plan free trial, your account will automatically move to the MotherDuck Free Plan, no action needed on your part.
49-
50-
# How to run SQL queries
51-
52-
Throughout this tutorial, we'll show you SQL queries that you can run to inspect and manipulate data with DuckDB. DuckDB offers two database modes: in-memory and file-based. In-memory databases store data in RAM, providing lightning-fast operations but losing data when closed, ideal for temporary processing. File-based databases store data on disk, offering persistence and larger data capacity, suitable for long-term storage and sharing. You can easily switch between modes, allowing flexibility to balance performance and data retention needs.
53-
54-
## Jupyter Notebook: in-memory database
55-
56-
For the first two sections of this tutorial, we will use an in-memory database, since all examples are self-contained and can easily be re-run if needed.
57-
58-
You can run SQL directly in a Jupyter Notebook with a Python kernel by installing and loading the `magic_duckdb` extension:
59-
60-
```python
61-
!pip install --upgrade duckdb magic-duckdb --quiet
62-
%load_ext magic_duckdb
63-
```
64-
65-
and using the `%%dql` magic command:
66-
67-
```python
68-
%%dql
69-
SELECT 42;
70-
```
71-
72-
## Jupyter Notebook: persistent database
73-
74-
For the latter part of this tutorial, we will cover data sharing and collaboration. To persist your tables to a file or remote database, you can explicitly create a new connection in Python:
75-
76-
```python
77-
import duckdb
78-
con = duckdb.connect("my_database.duckdb")
79-
```
80-
81-
In a separate cell, pass the connection object to the magic command with the `-co` option:
82-
83-
```python
84-
%%dql -co con
85-
CREATE TABLE test_table as (SELECT 42);
86-
SELECT * FROM test_table;
87-
```
88-
89-
## MotherDuck
90-
91-
You can also run SQL directly in a MotherDuck notebook. After <a href="https://app.motherduck.com/?auth_flow=signup" target="_blank">signing up</a>, go to <a href="https://app.motherduck.com/" target="_blank">app.motherduck.com</a> and log in. You'll see a SQL notebook environment where you can create cells, upload CSV files and run SQL queries.
92-
93-
Once you have the account and [get the authentication token](https://motherduck.com/docs/key-tasks/authenticating-to-motherduck/#creating-an-access-token), you can interact with your data in MotherDuck through the same Python API:
94-
95-
```python
96-
import duckdb
97-
con = duckdb.connect(f"md:my_db?motherduck_token={token}")
98-
```
99-
100-
## How to access files
101-
102-
In a local Jupyter notebook, you can use the local filesystem with no extra steps.
103-
104-
In Google Colab, you can download the files using `!wget <url>` and access them directly. Another option is to mount a folder in Google Drive, which makes all files in that folder available to query under `/content/gdrive/MyDrive` path:
105-
106-
```
107-
from google.colab import drive
108-
drive.mount('/content/gdrive')
109-
```
110-
111-
In MotherDuck, you can add JSON, CSV or Parquet file directly using the Add Files button in the top left of the UI.
39+
In preparation for section 4, please [sign up for a free account with MotherDuck](https://app.motherduck.com/?auth_flow=signup)!

0 commit comments

Comments
 (0)