2026-02-23 22:10:59 -08:00
(environment-variables)=
# Environment variables
2026-02-24 15:21:52 -08:00
`dclient` supports several environment variables for convenient access to Datasette instances.
2026-02-23 22:10:59 -08:00
## DATASETTE_URL
2026-02-24 15:21:52 -08:00
Set this to the base URL of your Datasette instance. It is used as a fallback when no instance is specified via `-i` and no default instance is configured:
2026-02-23 22:10:59 -08:00
```bash
export DATASETTE_URL=https://my-instance.datasette.cloud
```
2026-02-24 15:21:52 -08:00
Then you can omit the `-i` flag:
2026-02-23 22:10:59 -08:00
```bash
2026-02-24 15:21:52 -08:00
dclient databases
2026-02-23 22:10:59 -08:00
dclient query data "select * from my_table limit 10"
```
2026-02-24 15:21:52 -08:00
Aliases and the `-i` flag always take priority over `DATASETTE_URL` .
## DATASETTE_DATABASE
Set this to a default database name. It is used as a fallback when no database is specified via `-d` and the current instance has no `default_database` configured:
2026-02-23 22:10:59 -08:00
```bash
2026-02-24 15:21:52 -08:00
export DATASETTE_DATABASE=data
2026-02-23 22:10:59 -08:00
```
2026-02-24 15:21:52 -08:00
Then you can use the bare SQL shortcut:
2026-02-23 22:10:59 -08:00
```bash
2026-02-24 15:21:52 -08:00
dclient "select * from my_table limit 10"
2026-02-23 22:10:59 -08:00
```
## DATASETTE_TOKEN
Set this to an API token:
```bash
export DATASETTE_TOKEN=dstok_abc123
```
The token will be used automatically for any request that doesn't have a more specific token configured.
The precedence order for tokens is:
1. `--token` CLI flag (highest priority)
2026-02-24 15:21:52 -08:00
2. Stored token from `auth.json` (matched by alias name, then URL prefix)
2026-02-23 22:10:59 -08:00
3. `DATASETTE_TOKEN` environment variable (lowest priority)
2026-02-24 15:21:52 -08:00
## DCLIENT_CONFIG_DIR
Override the config directory (default `~/.config/io.datasette.dclient` or platform equivalent):
```bash
export DCLIENT_CONFIG_DIR=/path/to/config
```
This is useful for testing or running multiple configurations side by side.
## Using them together
2026-02-23 22:10:59 -08:00
These variables work well together for quick access to a single instance:
```bash
export DATASETTE_URL=https://my-instance.datasette.cloud
2026-02-24 15:21:52 -08:00
export DATASETTE_DATABASE=data
2026-02-23 22:10:59 -08:00
export DATASETTE_TOKEN=dstok_abc123
2026-02-24 15:21:52 -08:00
# Query
dclient "select * from my_table"
2026-02-23 22:10:59 -08:00
2026-02-24 15:21:52 -08:00
# Insert
2026-02-23 22:10:59 -08:00
cat records.json | dclient insert data my_table - --json
# Check your actor identity
2026-02-24 15:21:52 -08:00
dclient actor
2026-02-23 22:10:59 -08:00
```