Debian Codegraph @

README.md

raw
1 # Harlequin
2
3 [![PyPI](https://img.shields.io/pypi/v/harlequin)](https://pypi.org/project/harlequin/)
4
5 ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/harlequin)
6 ![Runs on Linux | MacOS | Windows](https://img.shields.io/badge/runs%20on-Linux%20%7C%20MacOS%20%7C%20Windows-blue)
7
8 The SQL IDE for Your Terminal.
9
10 ![Harlequin](./harlequin.svg)
11
12 > [!TIP]
13 > This README contains a small subset of the docs available at
14 > [harlequin.sh](https://harlequin.sh/docs/getting-started/index).
15
16 ## Installing Harlequin
17
18 Harlequin is a Python program, and there are many ways to install and run it. We strongly recommend using [uv](https://docs.astral.sh/uv):
19
20 1. [Install uv](https://docs.astral.sh/uv/getting-started/installation/#standalone-installer). From a POSIX shell, run:
21
22 ```bash
23 curl -LsSf https://astral.sh/uv/install.sh | sh
24 ```
25
26 Or using Windows Powershell:
27
28 ```powershell
29 powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
30 ```
31
32 2. Install Harlequin as a tool using `uv`:
33
34 ```bash
35 uv tool install harlequin
36 ```
37
38 This command will install Harlequin into an isolated environment and add it to your PATH so you can easily run the executable.
39
40 ### Other Installation Methods
41
42 Alternatively, if you know what you're doing, after installing Python 3.9 or above, install Harlequin using `pip`, `pipx`, `poetry`, or any other program that can install Python packages from PyPI:
43
44 ```bash
45 pip install harlequin
46 ```
47
48 There is also a [Homebrew formula](https://formulae.brew.sh/formula/harlequin) for Harlequin, although this is maintained by the community and is not as rigorously tested as the Python installations. Note that the formula includes several Harlequin adapter packages (Postgres, MySQL/MariaDB, and ODBC) and their dependencies, which is convenient but increases the application size.
49
50 ```bash
51 brew install harlequin
52 ```
53
54 ## Installing Database Adapters
55
56 Harlequin can connect to dozens of databases using adapter plug-ins. Adapters are distributed as their own Python packages that need to be installed into the same environment as Harlequin.
57
58 For a list of known adapters provided either by the Harlequin maintainers or the broader community, see the [adapters](https://harlequin.sh/docs/adapters) page.
59
60 The adapter docs also include installation instructions. Some adapters can be installed as Harlequin extras, like `postgres`. If you used `uv` to install Harlequin:
61
62 ```bash
63 uv tool install 'harlequin[postgres]'
64 ```
65
66 You can install multiple extras:
67
68 ```bash
69 uv tool install 'harlequin[postgres,mysql,s3]'
70 ```
71
72 ## Running Harlequin
73
74 Once Harlequin is installed, you run it from the command line. The arguments and options you pass in at the command line affect Harlequin's behavior, like what database adapter it uses, which database it connects to, whether or not the file picker is visible, and more. Assuming you have installed Harlequin so that it is on your [PATH](<https://en.wikipedia.org/wiki/PATH_(variable)>) (`uv tool install harlequin` does this automatically), you run Harlequin by typing a command of this form into your shell:
75
76 ```bash
77 harlequin [OPTIONS] [CONN_STR]
78 ```
79
80 where `[OPTIONS]` is 0 or more pairs of the form `--[option-name] [option-value]`, and `[CONN_STR]` is 0 or more connection strings. `[OPTIONS]` are composed of both Harlequin options and adapter options. For a full list of options, run Harlequin with the `--help` option:
81
82 ```bash
83 harlequin --help
84 ```
85
86 ## Using Harlequin with DuckDB
87
88 Harlequin defaults to using its DuckDB database adapter, which ships with Harlequin and includes the full DuckDB in-process database.
89
90 To open an in-memory DuckDB session, run Harlequin with no arguments:
91
92 ```bash
93 harlequin
94 ```
95
96 To open one or more DuckDB database files, pass in relative or absolute paths as connection strings (Harlequin will create DuckDB databases if they do not exist):
97
98 ```bash
99 harlequin "path/to/duck.db" "another_duck.db"
100 ```
101
102 ## Using Harlequin with SQLite and Other Adapters
103
104 Harlequin also ships with a SQLite3 adapter. To use that adapter, you specify the `--adapter sqlite` option. Like DuckDB, you can open an in-memory SQLite database by omitting the connection string:
105
106 ```bash
107 harlequin --adapter sqlite
108 ```
109
110 You can open one or more SQLite database files by passing in their paths as connection strings; note that the `--adapter` option has a short alias, `-a`:
111
112 ```bash
113 harlequin -a sqlite "path/to/sqlite.db" "another_sqlite.db"
114 ```
115
116 Other adapters can be installed as plug-ins; for more information, see the [installation guide](https://harlequin.sh/docs/getting-started/index#installing-database-adapters), and the guides for individual [adapters](https://harlequin.sh/docs/adapters). Each adapter can define its own options, which you can view using `harlequin --help`.
117
118 ## Configuring Harlequin
119
120 Harlequin contains a large number of options that allow you to [set the theme](https://harlequin.sh/docs/themes), [customize key bindings](https://harlequin.sh/docs/keymaps/index), [show remote and local files](https://harlequin.sh/docs/files/index), set the locale for number formatting, and much more. These can always be entered at the command line, but it can be convenient to define a configuration as a profile instead. For more information on configuring Harlequin, see [Using Config Files](https://harlequin.sh/docs/config-file/index).
121
122 A profile's string values can name environment variables — `password = "${MYPASSWORD}"`, or `${MYHOST:-localhost}` to supply a default — so a config file your team shares holds no credentials, and values an adapter declares as secrets are masked wherever Harlequin prints them. hsql, Harlequin's companion CLI (below), reads the same files and can report on them, with `hsql --config show`, `--config validate` and `--config schema`.
123
124 ## Using Harlequin with Agents or in Scripts
125
126 Harlequin has a companion CLI, hsql, that uses the same adapters and config files, but is optimized for headless use by agents and in automations. hsql is packaged with Harlequin (no additional installation required):
127
128 ```bash
129 $ hsql -P dev -c "select * from users"
130 id | name
131 ----+---------
132 1 | Ted
133 2 | Patrick
134 (2 rows)
135 ```
136
137 hsql can also explore the catalog without writing SQL: `hsql --catalog --path mydb.analytics` lists a schema's relations (and `--path mydb.analytics.orders` lists that table's columns), while `hsql --catalog-search customer_id` searches every level at once.
138
139 To bound what an agent can do, `--read-only` connects in a mode the database refuses writes in, and `hsql --timeout 30` cancels a run that takes longer than that. Both are also profile keys, and both refuse to start if the adapter cannot enforce them. Harlequin takes `--read-only` too.
140
141 For more information on hsql, see the [getting started docs](https://harlequin.sh/docs/getting-started/hsql).
142
143 ## Using Harlequin with Django
144
145 [django-harlequin](https://pypi.org/project/django-harlequin/) provides a command to launch Harlequin using Django’s database configuration, like:
146
147 ```bash
148 ./manage.py harlequin
149 ```
150
151 ## Keep Reading at [harlequin.sh](https://harlequin.sh/docs/getting-started/usage)
152
153 Visit [harlequin.sh](https://harlequin.sh/docs/getting-started/usage) for an overview of features and full documentation, starting with a guided walkthrough of how to edit and execute queries, use the data catalog, export data, and more.
154
155 ## Getting Help
156
157 To view all command-line options for Harlequin and all installed adapters, after installation, simply type:
158
159 ```bash
160 harlequin --help
161 ```
162
163 To view a subset of these docs (and a link back here) from within the app, press `F1`.
164
165 See the [Troubleshooting](https://harlequin.sh/docs/troubleshooting/index) guide for help with key bindings, appearance issues, copy-paste, etc.
166
167 [GitHub Discussions](https://github.com/tconbeer/harlequin/discussions) are a good place to ask questions, request features, and say hello.
168
169 [GitHub Issues](https://github.com/tconbeer/harlequin/issues) are the best place to report bugs.
170
171 ## Sponsoring Harlequin
172
173 Please consider [sponsoring Harlequin's author](https://github.com/sponsors/tconbeer), so he can continue to dedicate time to Harlequin.
174
175 ## Contributing
176
177 Thanks for your interest in Harlequin! Harlequin is primarily maintained by [Ted Conbeer](https://github.com/tconbeer), but he welcomes all contributions!
178
179 Please see [`CONTRIBUTING.md`](./CONTRIBUTING.md) for more information.