A Terminal-based SQL IDE for DuckDB.
(A Harlequin is also a pretty duck.)
After installing Python 3.8 or above, install Harlequin using pip
or pipx
with:
pipx install harlequin
Tip:
You can run invoke directly with
pipx run
anywhere thatpipx
is installed. For example:
pipx run harlequin --help
pipx run harlequin ./my.duckdb
From any shell, to open one or more DuckDB database files:
harlequin "path/to/duck.db" "another_duck.db"
To open an in-memory DuckDB session, run Harlequin with no arguments:
harlequin
You can also open a database in read-only mode:
harlequin -r "path/to/duck.db"
You can use Harlequin with MotherDuck, just as you would use the DuckDB CLI:
harlequin "md:"
You can attach local databases as additional arguments (md:
has to be first:)
harlequin "md:" "local_duck.db"
- Web browser: Run
harlequin "md:"
, and Harlequin will attempt to open a web browser where you can log in. - Use an environment variable: Set the
motherduck_token
variable before runningharlequin "md:"
, and Harlequin will authenticate with MotherDuck using your service token. - Use the CLI option: You can pass a service token to Harlequin with
harlequin "md:" --md_token <my token>
You can run Harlequin in "SaaS Mode" by passing the md_saas
option: harlequin "md:" --md_saas
.
When Harlequin is open, you can view the schema of your DuckDB database in the left sidebar. You can use your mouse or the arrow keys + enter to navigate the tree. The tree shows schemas, tables/views and their types, and columns and their types.
The main query editor is a full-featured text editor, with features including syntax highlighting, auto-formatting with ctrl + `
(ctrl + 2
on some terminals), text selection, copy/paste, and more.
You can save the query currently in the editor with ctrl + s
. You can open a query in any text or .sql file with ctrl + o
.
To run a query press ctrl + enter
. Not all terminals support this key combination, so you can also use ctrl + j
, or click the RUN QUERY
button in the (blue) footer.
Up to 50k records will be loaded into the results pane below the query editor. When the focus is on the data pane, you can use your arrow keys or mouse to select different cells.
Press ctrl + q
to quit and return to your shell.
Thanks for your interest in Harlequin! Harlequin is primarily maintained by Ted Conbeer, but he welcomes all contributions and is looking for additional maintainers!
We'd love to hear from you! Open an Issue to request new features, report bugs, or say hello.
- Install Poetry v1.2 or higher if you don't have it already. You may also need or want pyenv, make, and gcc.
- Fork this repo, and then clone the fork into a directory (let's call it
harlequin
), thencd harlequin
. - Use
poetry install --sync
to install the project (editable) and its dependencies (including all test and dev dependencies) into a new virtual env. - Use
poetry shell
to spawn a subshell. - Type
make
to run all tests and linters, or runpytest
,black .
,ruff . --fix
, andmypy
individually.
- PRs should be motivated by an open issue. If there isn't already an issue describing the feature or bug, open one. Do this before you write code, so you don't waste time on something that won't get merged.
- Ideally new features and bug fixes would be tested, to prevent future regressions. Textual provides a test harness that we use to test features of Harlequin. You can find some examples in the
tests
directory of this project. Please include a test in your PR, but if you can't figure it out, open a PR to ask for help. - Open a PR from your fork to the
main
branch oftconbeer/harlequin
. In the PR description, link to the open issue, and then write a few sentences about why you wrote the code you did: explain your design, etc. - Ted may ask you to make changes, or he may make them for you. Don't take this the wrong way -- he values your contributions, but he knows this isn't your job, either, so if it's faster for him, he may push a commit to your branch or create a new branch from your commits.