dclient insert command (#13)
* Move making queries to own page, refs #7
* Documentation for the dclient insert feature, refs #8
* Implemented progress bar for insert, refs #8
* --pk option
* --ignore and --replace for insert, refs #8
* --batch-size option, refs #8
* First insert test, using a mock - refs #8
* insert test that exercises against an in-memory Datasette instance, refs #8
* Insert tests now cover an error case, refs #8
* Tests for --ignore and --replace, refs #8
* Tests for different formats, refs #8
* Test for --no-detect-types
* Support for --encoding, refs #8
2023-07-24 16:22:39 -07:00
|
|
|
(authentication)=
|
|
|
|
|
|
2023-07-17 16:48:50 -07:00
|
|
|
# Authentication
|
|
|
|
|
|
|
|
|
|
`dclient` can handle API tokens for Datasette instances that require authentication.
|
|
|
|
|
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
You can pass an API token to any command using `--token` like this:
|
2023-07-17 16:48:50 -07:00
|
|
|
|
|
|
|
|
```bash
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
dclient query fixtures "select * from facetable" --token dstok_mytoken -i latest
|
2023-07-17 16:48:50 -07:00
|
|
|
```
|
|
|
|
|
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
A more convenient way to handle this is to store tokens for your aliases.
|
2023-07-17 16:48:50 -07:00
|
|
|
|
|
|
|
|
## Using stored tokens
|
|
|
|
|
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
To store a token for an alias:
|
2023-07-17 16:48:50 -07:00
|
|
|
```bash
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
dclient auth add latest
|
2023-07-17 16:48:50 -07:00
|
|
|
```
|
|
|
|
|
Then paste in the token and hit enter when prompted to do so.
|
|
|
|
|
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
Tokens can also be stored for direct URLs:
|
|
|
|
|
```bash
|
|
|
|
|
dclient auth add https://latest.datasette.io
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
To list which aliases/URLs you have set tokens for, run the `auth list` command:
|
2023-07-17 16:48:50 -07:00
|
|
|
```bash
|
|
|
|
|
dclient auth list
|
|
|
|
|
```
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
To delete the token for a specific alias or URL, run `auth remove`:
|
2023-07-17 16:48:50 -07:00
|
|
|
```bash
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
dclient auth remove latest
|
2023-07-17 16:48:50 -07:00
|
|
|
```
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
|
|
|
|
|
## Token resolution order
|
|
|
|
|
|
|
|
|
|
When making a request, dclient resolves the token in this order:
|
|
|
|
|
|
|
|
|
|
1. `--token` CLI flag (highest priority)
|
|
|
|
|
2. Token stored by alias name in `auth.json`
|
|
|
|
|
3. Token stored by URL prefix in `auth.json`
|
|
|
|
|
4. `DATASETTE_TOKEN` environment variable (lowest priority)
|
|
|
|
|
|
2024-02-27 21:08:15 -08:00
|
|
|
## Testing a token
|
2023-07-17 16:48:50 -07:00
|
|
|
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
The `dclient auth status` command can be used to verify authentication by calling `/-/actor.json`:
|
|
|
|
|
```bash
|
|
|
|
|
dclient auth status
|
|
|
|
|
dclient auth status -i prod
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The `dclient actor` command also shows the actor:
|
2024-02-27 21:08:15 -08:00
|
|
|
```bash
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
dclient actor
|
|
|
|
|
dclient actor -i prod
|
2024-02-27 21:08:15 -08:00
|
|
|
```
|
|
|
|
|
The output looks like this:
|
|
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"actor": {
|
|
|
|
|
"id": "root",
|
|
|
|
|
"token": "dstok"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
2023-07-17 16:48:50 -07:00
|
|
|
|
|
|
|
|
## dclient auth --help
|
|
|
|
|
<!-- [[[cog
|
|
|
|
|
import cog
|
|
|
|
|
from dclient import cli
|
|
|
|
|
from click.testing import CliRunner
|
|
|
|
|
runner = CliRunner()
|
|
|
|
|
result = runner.invoke(cli.cli, ["auth", "--help"])
|
|
|
|
|
help = result.output.replace("Usage: cli", "Usage: dclient")
|
|
|
|
|
cog.out(
|
|
|
|
|
"```\n{}\n```".format(help)
|
|
|
|
|
)
|
|
|
|
|
]]] -->
|
|
|
|
|
```
|
|
|
|
|
Usage: dclient auth [OPTIONS] COMMAND [ARGS]...
|
|
|
|
|
|
|
|
|
|
Manage authentication for different instances
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
--help Show this message and exit.
|
|
|
|
|
|
|
|
|
|
Commands:
|
|
|
|
|
add Add an authentication token for an alias or URL
|
|
|
|
|
list List stored API tokens
|
|
|
|
|
remove Remove the API token for an alias or URL
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
status Verify authentication by calling /-/actor.json
|
2023-07-17 16:48:50 -07:00
|
|
|
|
|
|
|
|
```
|
|
|
|
|
<!-- [[[end]]] -->
|
|
|
|
|
|
|
|
|
|
## dclient auth add --help
|
|
|
|
|
|
|
|
|
|
<!-- [[[cog
|
|
|
|
|
import cog
|
|
|
|
|
result = runner.invoke(cli.cli, ["auth", "add", "--help"])
|
|
|
|
|
help = result.output.replace("Usage: cli", "Usage: dclient")
|
|
|
|
|
cog.out(
|
|
|
|
|
"```\n{}\n```".format(help)
|
|
|
|
|
)
|
|
|
|
|
]]] -->
|
|
|
|
|
```
|
|
|
|
|
Usage: dclient auth add [OPTIONS] ALIAS_OR_URL
|
|
|
|
|
|
|
|
|
|
Add an authentication token for an alias or URL
|
|
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
dclient auth add prod
|
|
|
|
|
dclient auth add https://datasette.io
|
2023-07-17 16:48:50 -07:00
|
|
|
|
|
|
|
|
Paste in the token when prompted.
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
--token TEXT
|
|
|
|
|
--help Show this message and exit.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
<!-- [[[end]]] -->
|
|
|
|
|
|
|
|
|
|
## dclient auth list --help
|
|
|
|
|
|
|
|
|
|
<!-- [[[cog
|
|
|
|
|
import cog
|
|
|
|
|
result = runner.invoke(cli.cli, ["auth", "list", "--help"])
|
|
|
|
|
help = result.output.replace("Usage: cli", "Usage: dclient")
|
|
|
|
|
cog.out(
|
|
|
|
|
"```\n{}\n```".format(help)
|
|
|
|
|
)
|
|
|
|
|
]]] -->
|
|
|
|
|
```
|
|
|
|
|
Usage: dclient auth list [OPTIONS]
|
|
|
|
|
|
|
|
|
|
List stored API tokens
|
|
|
|
|
|
2024-02-25 11:24:46 -08:00
|
|
|
Example usage:
|
|
|
|
|
|
|
|
|
|
dclient auth list
|
|
|
|
|
|
2023-07-17 16:48:50 -07:00
|
|
|
Options:
|
|
|
|
|
--help Show this message and exit.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
<!-- [[[end]]] -->
|
|
|
|
|
|
|
|
|
|
## dclient auth remove --help
|
|
|
|
|
|
|
|
|
|
<!-- [[[cog
|
|
|
|
|
import cog
|
|
|
|
|
result = runner.invoke(cli.cli, ["auth", "remove", "--help"])
|
|
|
|
|
help = result.output.replace("Usage: cli", "Usage: dclient")
|
|
|
|
|
cog.out(
|
|
|
|
|
"```\n{}\n```".format(help)
|
|
|
|
|
)
|
|
|
|
|
]]] -->
|
|
|
|
|
```
|
|
|
|
|
Usage: dclient auth remove [OPTIONS] ALIAS_OR_URL
|
|
|
|
|
|
|
|
|
|
Remove the API token for an alias or URL
|
|
|
|
|
|
2024-02-25 11:24:46 -08:00
|
|
|
Example usage:
|
|
|
|
|
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
dclient auth remove prod
|
2024-02-25 11:24:46 -08:00
|
|
|
|
2023-07-17 16:48:50 -07:00
|
|
|
Options:
|
|
|
|
|
--help Show this message and exit.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
<!-- [[[end]]] -->
|
2024-02-27 21:08:15 -08:00
|
|
|
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
## dclient auth status --help
|
|
|
|
|
|
|
|
|
|
<!-- [[[cog
|
|
|
|
|
import cog
|
|
|
|
|
result = runner.invoke(cli.cli, ["auth", "status", "--help"])
|
|
|
|
|
help = result.output.replace("Usage: cli", "Usage: dclient")
|
|
|
|
|
cog.out(
|
|
|
|
|
"```\n{}\n```".format(help)
|
|
|
|
|
)
|
|
|
|
|
]]] -->
|
|
|
|
|
```
|
|
|
|
|
Usage: dclient auth status [OPTIONS]
|
|
|
|
|
|
|
|
|
|
Verify authentication by calling /-/actor.json
|
|
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
|
|
|
|
|
dclient auth status
|
|
|
|
|
dclient auth status -i prod
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
-i, --instance TEXT Datasette instance URL or alias
|
|
|
|
|
--token TEXT API token
|
|
|
|
|
--help Show this message and exit.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
<!-- [[[end]]] -->
|
|
|
|
|
|
2024-02-27 21:08:15 -08:00
|
|
|
## dclient actor --help
|
|
|
|
|
|
|
|
|
|
<!-- [[[cog
|
|
|
|
|
import cog
|
|
|
|
|
result = runner.invoke(cli.cli, ["actor", "--help"])
|
|
|
|
|
help = result.output.replace("Usage: cli", "Usage: dclient")
|
|
|
|
|
cog.out(
|
|
|
|
|
"```\n{}\n```".format(help)
|
|
|
|
|
)
|
|
|
|
|
]]] -->
|
|
|
|
|
```
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
Usage: dclient actor [OPTIONS]
|
2024-02-27 21:08:15 -08:00
|
|
|
|
|
|
|
|
Show the actor represented by an API token
|
|
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
dclient actor
|
|
|
|
|
dclient actor -i prod
|
2024-02-27 21:08:15 -08:00
|
|
|
|
|
|
|
|
Options:
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
-i, --instance TEXT Datasette instance URL or alias
|
|
|
|
|
--token TEXT API token
|
|
|
|
|
--help Show this message and exit.
|
2024-02-27 21:08:15 -08:00
|
|
|
|
|
|
|
|
```
|
Tests and docs for v2 introspection commands and alias features
Add test_commands_v2.py with 28 tests covering databases, tables,
plugins, schema, default_query, upsert, auth status, actor, and
get commands.
Add test_alias_v2.py with 5 tests for alias default, alias default-db,
and removing the default alias.
Update aliases.md and authentication.md docs for v2 API.
refs #29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:21:58 -08:00
|
|
|
<!-- [[[end]]] -->
|