2022-11-22 01:57:06 +00:00
|
|
|
# dclient
|
2022-11-21 17:56:46 -08:00
|
|
|
|
2022-11-22 01:57:06 +00:00
|
|
|
[](https://pypi.org/project/dclient/)
|
|
|
|
|
[](https://github.com/simonw/dclient/releases)
|
|
|
|
|
[](https://github.com/simonw/dclient/actions?query=workflow%3ATest)
|
|
|
|
|
[](https://github.com/simonw/dclient/blob/master/LICENSE)
|
2022-11-21 17:56:46 -08:00
|
|
|
|
2023-07-24 16:23:30 -07:00
|
|
|
A client CLI utility for [Datasette](https://datasette.io/) instances.
|
|
|
|
|
|
|
|
|
|
Much of the functionality requires Datasette 1.0a2 or higher.
|
2022-11-21 17:56:46 -08:00
|
|
|
|
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
|
|
|
## Things you can do with dclient
|
|
|
|
|
|
2026-02-26 21:19:32 -08:00
|
|
|
- Browse table data with filtering, sorting, and pagination — no SQL required
|
2026-02-26 20:56:22 -08:00
|
|
|
- Run SQL queries against Datasette and return the results as JSON, CSV, TSV, or an ASCII table
|
2026-02-24 15:22:12 -08:00
|
|
|
- Introspect databases, tables, plugins, and schema
|
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
|
|
|
- Run queries against authenticated Datasette instances
|
2026-02-24 15:22:12 -08:00
|
|
|
- Create aliases and set default instances/databases for convenient access
|
|
|
|
|
- Insert and upsert data using the [write API](https://docs.datasette.io/en/latest/json_api.html#the-json-write-api) (Datasette 1.0 alpha or higher)
|
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
|
|
|
|
2022-11-22 01:57:06 +00:00
|
|
|
## Installation
|
2022-11-21 17:56:46 -08:00
|
|
|
|
2022-11-22 01:57:06 +00:00
|
|
|
Install this tool using `pip`:
|
2023-07-17 16:23:53 -07:00
|
|
|
```bash
|
2023-07-17 16:48:50 -07:00
|
|
|
pip install dclient
|
2023-07-17 16:23:53 -07:00
|
|
|
```
|
2023-07-17 16:48:50 -07:00
|
|
|
If you want to install it in the same virtual environment as Datasette (to use it as a plugin) you can instead run:
|
2023-07-17 16:23:53 -07:00
|
|
|
```bash
|
2023-07-17 16:48:50 -07:00
|
|
|
datasette install dclient
|
2023-07-17 16:23:53 -07:00
|
|
|
```
|
2026-02-24 15:22:12 -08:00
|
|
|
## Quick start
|
2023-07-17 16:23:53 -07:00
|
|
|
|
2026-02-24 15:22:12 -08:00
|
|
|
Add an alias for a Datasette instance:
|
2023-07-17 16:23:53 -07:00
|
|
|
```bash
|
2026-02-24 15:22:12 -08:00
|
|
|
dclient alias add latest https://latest.datasette.io
|
2026-02-26 20:44:39 -08:00
|
|
|
dclient default instance latest
|
|
|
|
|
dclient default database latest fixtures
|
2022-11-21 19:00:20 -08:00
|
|
|
```
|
2026-02-24 15:22:12 -08:00
|
|
|
Now run queries directly:
|
2023-07-24 21:33:46 -07:00
|
|
|
```bash
|
2026-02-24 15:22:12 -08:00
|
|
|
dclient "select * from facetable limit 1"
|
2023-07-24 21:33:46 -07:00
|
|
|
```
|
2026-02-24 15:22:12 -08:00
|
|
|
Or be explicit:
|
2023-07-24 21:33:46 -07:00
|
|
|
```bash
|
2026-02-24 15:22:12 -08:00
|
|
|
dclient query fixtures "select * from facetable limit 1" -i latest
|
2023-07-24 21:33:46 -07:00
|
|
|
```
|
2026-02-26 20:56:22 -08:00
|
|
|
Output as a table with `-t`, or use `--csv`, `--tsv`, `--nl`:
|
|
|
|
|
```bash
|
|
|
|
|
dclient "select pk, state from facetable limit 3" -t
|
|
|
|
|
```
|
2026-02-26 21:19:32 -08:00
|
|
|
Browse table rows without SQL:
|
|
|
|
|
```bash
|
|
|
|
|
dclient rows facetable -f state eq CA --sort _city_id -t
|
|
|
|
|
```
|
2026-02-24 15:22:12 -08:00
|
|
|
|
|
|
|
|
## Introspection
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
dclient databases
|
|
|
|
|
dclient tables
|
|
|
|
|
dclient plugins
|
|
|
|
|
dclient schema facetable
|
|
|
|
|
```
|
|
|
|
|
|
2023-07-17 16:48:50 -07:00
|
|
|
## Documentation
|
2022-11-21 19:00:20 -08:00
|
|
|
|
2023-07-17 16:48:50 -07:00
|
|
|
Visit **[dclient.datasette.io](https://dclient.datasette.io)** for full documentation on using this tool.
|
2022-11-21 18:53:12 -08:00
|
|
|
|
2022-11-22 01:57:06 +00:00
|
|
|
## Development
|
2022-11-21 17:56:46 -08:00
|
|
|
|
2022-11-22 01:57:06 +00:00
|
|
|
To contribute to this tool, first checkout the code. Then create a new virtual environment:
|
2023-07-17 16:48:50 -07:00
|
|
|
```bash
|
|
|
|
|
cd dclient
|
|
|
|
|
python -m venv venv
|
|
|
|
|
source venv/bin/activate
|
|
|
|
|
```
|
2022-11-22 01:57:06 +00:00
|
|
|
Now install the dependencies and test dependencies:
|
2023-07-17 16:48:50 -07:00
|
|
|
```bash
|
|
|
|
|
pip install -e '.[test]'
|
|
|
|
|
```
|
2022-11-22 01:57:06 +00:00
|
|
|
To run the tests:
|
2023-07-17 16:48:50 -07:00
|
|
|
```bash
|
|
|
|
|
pytest
|
2023-07-24 16:23:30 -07:00
|
|
|
```
|