Debian Codegraph @

docs/cli-reference.rst

raw
1 .. _cli_reference:
2
3 ===============
4 CLI reference
5 ===============
6
7 The ``datasette`` CLI tool provides a number of commands.
8
9 Running ``datasette`` without specifying a command runs the default command, ``datasette serve``. See :ref:`cli_help_serve___help` for the full list of options for that command.
10
11 .. [[[cog
12 from datasette import cli
13 from click.testing import CliRunner
14 import textwrap
15 def help(args):
16 title = "datasette " + " ".join(args)
17 cog.out("\n::\n\n")
18 result = CliRunner().invoke(cli.cli, args)
19 output = result.output.replace("Usage: cli ", "Usage: datasette ")
20 cog.out(textwrap.indent(output, ' '))
21 cog.out("\n\n")
22 .. ]]]
23 .. [[[end]]]
24
25 .. _cli_help___help:
26
27 datasette --help
28 ================
29
30 Running ``datasette --help`` shows a list of all of the available commands.
31
32 .. [[[cog
33 help(["--help"])
34 .. ]]]
35
36 ::
37
38 Usage: datasette [OPTIONS] COMMAND [ARGS]...
39
40 Datasette is an open source multi-tool for exploring and publishing data
41
42 About Datasette: https://datasette.io/
43 Full documentation: https://docs.datasette.io/
44
45 Options:
46 --version Show the version and exit.
47 --help Show this message and exit.
48
49 Commands:
50 serve* Serve up specified SQLite database files with a web UI
51 inspect Generate JSON summary of provided database files
52 install Install plugins and packages from PyPI into the same...
53 package Package SQLite files into a Datasette Docker container
54 plugins List currently installed plugins
55 publish Publish specified SQLite database files to the internet along...
56 uninstall Uninstall plugins and Python packages from the Datasette...
57
58
59 .. [[[end]]]
60
61 Additional commands added by plugins that use the :ref:`plugin_hook_register_commands` hook will be listed here as well.
62
63 .. _cli_help_serve___help:
64
65 datasette serve
66 ===============
67
68 This command starts the Datasette web application running on your machine::
69
70 datasette serve mydatabase.db
71
72 Or since this is the default command you can run this instead::
73
74 datasette mydatabase.db
75
76 Once started you can access it at ``http://localhost:8001``
77
78 .. [[[cog
79 help(["serve", "--help"])
80 .. ]]]
81
82 ::
83
84 Usage: datasette serve [OPTIONS] [FILES]...
85
86 Serve up specified SQLite database files with a web UI
87
88 Options:
89 -i, --immutable PATH Database files to open in immutable mode
90 -h, --host TEXT Host for server. Defaults to 127.0.0.1 which
91 means only connections from the local machine
92 will be allowed. Use 0.0.0.0 to listen to all
93 IPs and allow access from other machines.
94 -p, --port INTEGER RANGE Port for server, defaults to 8001. Use -p 0 to
95 automatically assign an available port.
96 [0<=x<=65535]
97 --uds TEXT Bind to a Unix domain socket
98 --reload Automatically reload if code or metadata
99 change detected - useful for development
100 --cors Enable CORS by serving Access-Control-Allow-
101 Origin: *
102 --load-extension PATH:ENTRYPOINT?
103 Path to a SQLite extension to load, and
104 optional entrypoint
105 --inspect-file TEXT Path to JSON file created using "datasette
106 inspect"
107 -m, --metadata FILENAME Path to JSON/YAML file containing
108 license/source metadata
109 --template-dir DIRECTORY Path to directory containing custom templates
110 --plugins-dir DIRECTORY Path to directory containing custom plugins
111 --static MOUNT:DIRECTORY Serve static files from this directory at
112 /MOUNT/...
113 --memory Make /_memory database available
114 --config CONFIG Deprecated: set config option using
115 configname:value. Use --setting instead.
116 --setting SETTING... Setting, see
117 docs.datasette.io/en/stable/settings.html
118 --secret TEXT Secret used for signing secure values, such as
119 signed cookies
120 --root Output URL that sets a cookie authenticating
121 the root user
122 --get TEXT Run an HTTP GET request against this path,
123 print results and exit
124 --version-note TEXT Additional note to show on /-/versions
125 --help-settings Show available settings
126 --pdb Launch debugger on any errors
127 -o, --open Open Datasette in your web browser
128 --create Create database files if they do not exist
129 --crossdb Enable cross-database joins using the /_memory
130 database
131 --nolock Ignore locking, open locked files in read-only
132 mode
133 --ssl-keyfile TEXT SSL key file
134 --ssl-certfile TEXT SSL certificate file
135 --help Show this message and exit.
136
137
138 .. [[[end]]]
139
140
141 .. _cli_datasette_get:
142
143 datasette --get
144 ---------------
145
146 The ``--get`` option to ``datasette serve`` (or just ``datasette``) specifies the path to a page within Datasette and causes Datasette to output the content from that path without starting the web server.
147
148 This means that all of Datasette's functionality can be accessed directly from the command-line.
149
150 For example::
151
152 $ datasette --get '/-/versions.json' | jq .
153 {
154 "python": {
155 "version": "3.8.5",
156 "full": "3.8.5 (default, Jul 21 2020, 10:48:26) \n[Clang 11.0.3 (clang-1103.0.32.62)]"
157 },
158 "datasette": {
159 "version": "0.46+15.g222a84a.dirty"
160 },
161 "asgi": "3.0",
162 "uvicorn": "0.11.8",
163 "sqlite": {
164 "version": "3.32.3",
165 "fts_versions": [
166 "FTS5",
167 "FTS4",
168 "FTS3"
169 ],
170 "extensions": {
171 "json1": null
172 },
173 "compile_options": [
174 "COMPILER=clang-11.0.3",
175 "ENABLE_COLUMN_METADATA",
176 "ENABLE_FTS3",
177 "ENABLE_FTS3_PARENTHESIS",
178 "ENABLE_FTS4",
179 "ENABLE_FTS5",
180 "ENABLE_GEOPOLY",
181 "ENABLE_JSON1",
182 "ENABLE_PREUPDATE_HOOK",
183 "ENABLE_RTREE",
184 "ENABLE_SESSION",
185 "MAX_VARIABLE_NUMBER=250000",
186 "THREADSAFE=1"
187 ]
188 }
189 }
190
191 The exit code will be 0 if the request succeeds and 1 if the request produced an HTTP status code other than 200 - e.g. a 404 or 500 error.
192
193 This lets you use ``datasette --get /`` to run tests against a Datasette application in a continuous integration environment such as GitHub Actions.
194
195 .. _cli_help_serve___help_settings:
196
197 datasette serve --help-settings
198 -------------------------------
199
200 This command outputs all of the available Datasette :ref:`settings <settings>`.
201
202 These can be passed to ``datasette serve`` using ``datasette serve --setting name value``.
203
204 .. [[[cog
205 help(["--help-settings"])
206 .. ]]]
207
208 ::
209
210 Settings:
211 default_page_size Default page size for the table view
212 (default=100)
213 max_returned_rows Maximum rows that can be returned from a table or
214 custom query (default=1000)
215 num_sql_threads Number of threads in the thread pool for
216 executing SQLite queries (default=3)
217 sql_time_limit_ms Time limit for a SQL query in milliseconds
218 (default=1000)
219 default_facet_size Number of values to return for requested facets
220 (default=30)
221 facet_time_limit_ms Time limit for calculating a requested facet
222 (default=200)
223 facet_suggest_time_limit_ms Time limit for calculating a suggested facet
224 (default=50)
225 allow_facet Allow users to specify columns to facet using
226 ?_facet= parameter (default=True)
227 default_allow_sql Allow anyone to run arbitrary SQL queries
228 (default=True)
229 allow_download Allow users to download the original SQLite
230 database files (default=True)
231 suggest_facets Calculate and display suggested facets
232 (default=True)
233 default_cache_ttl Default HTTP cache TTL (used in Cache-Control:
234 max-age= header) (default=5)
235 cache_size_kb SQLite cache size in KB (0 == use SQLite default)
236 (default=0)
237 allow_csv_stream Allow .csv?_stream=1 to download all rows
238 (ignoring max_returned_rows) (default=True)
239 max_csv_mb Maximum size allowed for CSV export in MB - set 0
240 to disable this limit (default=100)
241 truncate_cells_html Truncate cells longer than this in HTML table
242 view - set 0 to disable (default=2048)
243 force_https_urls Force URLs in API output to always use https://
244 protocol (default=False)
245 template_debug Allow display of template debug information with
246 ?_context=1 (default=False)
247 trace_debug Allow display of SQL trace debug information with
248 ?_trace=1 (default=False)
249 base_url Datasette URLs should use this base path
250 (default=/)
251
252
253
254 .. [[[end]]]
255
256 .. _cli_help_plugins___help:
257
258 datasette plugins
259 =================
260
261 Output JSON showing all currently installed plugins, their versions, whether they include static files or templates and which :ref:`plugin_hooks` they use.
262
263 .. [[[cog
264 help(["plugins", "--help"])
265 .. ]]]
266
267 ::
268
269 Usage: datasette plugins [OPTIONS]
270
271 List currently installed plugins
272
273 Options:
274 --all Include built-in default plugins
275 --plugins-dir DIRECTORY Path to directory containing custom plugins
276 --help Show this message and exit.
277
278
279 .. [[[end]]]
280
281 Example output:
282
283 .. code-block:: json
284
285 [
286 {
287 "name": "datasette-geojson",
288 "static": false,
289 "templates": false,
290 "version": "0.3.1",
291 "hooks": [
292 "register_output_renderer"
293 ]
294 },
295 {
296 "name": "datasette-geojson-map",
297 "static": true,
298 "templates": false,
299 "version": "0.4.0",
300 "hooks": [
301 "extra_body_script",
302 "extra_css_urls",
303 "extra_js_urls"
304 ]
305 },
306 {
307 "name": "datasette-leaflet",
308 "static": true,
309 "templates": false,
310 "version": "0.2.2",
311 "hooks": [
312 "extra_body_script",
313 "extra_template_vars"
314 ]
315 }
316 ]
317
318
319 .. _cli_help_install___help:
320
321 datasette install
322 =================
323
324 Install new Datasette plugins. This command works like ``pip install`` but ensures that your plugins will be installed into the same environment as Datasette.
325
326 This command::
327
328 datasette install datasette-cluster-map
329
330 Would install the `datasette-cluster-map <https://datasette.io/plugins/datasette-cluster-map>`__ plugin.
331
332 .. [[[cog
333 help(["install", "--help"])
334 .. ]]]
335
336 ::
337
338 Usage: datasette install [OPTIONS] PACKAGES...
339
340 Install plugins and packages from PyPI into the same environment as Datasette
341
342 Options:
343 -U, --upgrade Upgrade packages to latest version
344 --help Show this message and exit.
345
346
347 .. [[[end]]]
348
349 .. _cli_help_uninstall___help:
350
351 datasette uninstall
352 ===================
353
354 Uninstall one or more plugins.
355
356 .. [[[cog
357 help(["uninstall", "--help"])
358 .. ]]]
359
360 ::
361
362 Usage: datasette uninstall [OPTIONS] PACKAGES...
363
364 Uninstall plugins and Python packages from the Datasette environment
365
366 Options:
367 -y, --yes Don't ask for confirmation
368 --help Show this message and exit.
369
370
371 .. [[[end]]]
372
373 .. _cli_help_publish___help:
374
375 datasette publish
376 =================
377
378 Shows a list of available deployment targets for :ref:`publishing data <publishing>` with Datasette.
379
380 Additional deployment targets can be added by plugins that use the :ref:`plugin_hook_publish_subcommand` hook.
381
382 .. [[[cog
383 help(["publish", "--help"])
384 .. ]]]
385
386 ::
387
388 Usage: datasette publish [OPTIONS] COMMAND [ARGS]...
389
390 Publish specified SQLite database files to the internet along with a
391 Datasette-powered interface and API
392
393 Options:
394 --help Show this message and exit.
395
396 Commands:
397 cloudrun Publish databases to Datasette running on Cloud Run
398 heroku Publish databases to Datasette running on Heroku
399
400
401 .. [[[end]]]
402
403
404 .. _cli_help_publish_cloudrun___help:
405
406 datasette publish cloudrun
407 ==========================
408
409 See :ref:`publish_cloud_run`.
410
411 .. [[[cog
412 help(["publish", "cloudrun", "--help"])
413 .. ]]]
414
415 ::
416
417 Usage: datasette publish cloudrun [OPTIONS] [FILES]...
418
419 Publish databases to Datasette running on Cloud Run
420
421 Options:
422 -m, --metadata FILENAME Path to JSON/YAML file containing metadata to
423 publish
424 --extra-options TEXT Extra options to pass to datasette serve
425 --branch TEXT Install datasette from a GitHub branch e.g.
426 main
427 --template-dir DIRECTORY Path to directory containing custom templates
428 --plugins-dir DIRECTORY Path to directory containing custom plugins
429 --static MOUNT:DIRECTORY Serve static files from this directory at
430 /MOUNT/...
431 --install TEXT Additional packages (e.g. plugins) to install
432 --plugin-secret <TEXT TEXT TEXT>...
433 Secrets to pass to plugins, e.g. --plugin-
434 secret datasette-auth-github client_id xxx
435 --version-note TEXT Additional note to show on /-/versions
436 --secret TEXT Secret used for signing secure values, such as
437 signed cookies
438 --title TEXT Title for metadata
439 --license TEXT License label for metadata
440 --license_url TEXT License URL for metadata
441 --source TEXT Source label for metadata
442 --source_url TEXT Source URL for metadata
443 --about TEXT About label for metadata
444 --about_url TEXT About URL for metadata
445 -n, --name TEXT Application name to use when building
446 --service TEXT Cloud Run service to deploy (or over-write)
447 --spatialite Enable SpatialLite extension
448 --show-files Output the generated Dockerfile and
449 metadata.json
450 --memory TEXT Memory to allocate in Cloud Run, e.g. 1Gi
451 --cpu [1|2|4] Number of vCPUs to allocate in Cloud Run
452 --timeout INTEGER Build timeout in seconds
453 --apt-get-install TEXT Additional packages to apt-get install
454 --max-instances INTEGER Maximum Cloud Run instances (use 0 to remove
455 the limit) [default: 1]
456 --min-instances INTEGER Minimum Cloud Run instances
457 --artifact-repository TEXT Artifact Registry repository to store the
458 image [default: datasette]
459 --artifact-region TEXT Artifact Registry location (region or multi-
460 region) [default: us]
461 --artifact-project TEXT Project ID for Artifact Registry (defaults to
462 the active project)
463 --help Show this message and exit.
464
465
466 .. [[[end]]]
467
468
469 .. _cli_help_publish_heroku___help:
470
471 datasette publish heroku
472 ========================
473
474 See :ref:`publish_heroku`.
475
476 .. [[[cog
477 help(["publish", "heroku", "--help"])
478 .. ]]]
479
480 ::
481
482 Usage: datasette publish heroku [OPTIONS] [FILES]...
483
484 Publish databases to Datasette running on Heroku
485
486 Options:
487 -m, --metadata FILENAME Path to JSON/YAML file containing metadata to
488 publish
489 --extra-options TEXT Extra options to pass to datasette serve
490 --branch TEXT Install datasette from a GitHub branch e.g.
491 main
492 --template-dir DIRECTORY Path to directory containing custom templates
493 --plugins-dir DIRECTORY Path to directory containing custom plugins
494 --static MOUNT:DIRECTORY Serve static files from this directory at
495 /MOUNT/...
496 --install TEXT Additional packages (e.g. plugins) to install
497 --plugin-secret <TEXT TEXT TEXT>...
498 Secrets to pass to plugins, e.g. --plugin-
499 secret datasette-auth-github client_id xxx
500 --version-note TEXT Additional note to show on /-/versions
501 --secret TEXT Secret used for signing secure values, such as
502 signed cookies
503 --title TEXT Title for metadata
504 --license TEXT License label for metadata
505 --license_url TEXT License URL for metadata
506 --source TEXT Source label for metadata
507 --source_url TEXT Source URL for metadata
508 --about TEXT About label for metadata
509 --about_url TEXT About URL for metadata
510 -n, --name TEXT Application name to use when deploying
511 --tar TEXT --tar option to pass to Heroku, e.g.
512 --tar=/usr/local/bin/gtar
513 --generate-dir DIRECTORY Output generated application files and stop
514 without deploying
515 --help Show this message and exit.
516
517
518 .. [[[end]]]
519
520 .. _cli_help_package___help:
521
522 datasette package
523 =================
524
525 Package SQLite files into a Datasette Docker container, see :ref:`cli_package`.
526
527 .. [[[cog
528 help(["package", "--help"])
529 .. ]]]
530
531 ::
532
533 Usage: datasette package [OPTIONS] FILES...
534
535 Package SQLite files into a Datasette Docker container
536
537 Options:
538 -t, --tag TEXT Name for the resulting Docker container, can
539 optionally use name:tag format
540 -m, --metadata FILENAME Path to JSON/YAML file containing metadata to
541 publish
542 --extra-options TEXT Extra options to pass to datasette serve
543 --branch TEXT Install datasette from a GitHub branch e.g. main
544 --template-dir DIRECTORY Path to directory containing custom templates
545 --plugins-dir DIRECTORY Path to directory containing custom plugins
546 --static MOUNT:DIRECTORY Serve static files from this directory at /MOUNT/...
547 --install TEXT Additional packages (e.g. plugins) to install
548 --spatialite Enable SpatialLite extension
549 --version-note TEXT Additional note to show on /-/versions
550 --secret TEXT Secret used for signing secure values, such as
551 signed cookies
552 -p, --port INTEGER RANGE Port to run the server on, defaults to 8001
553 [1<=x<=65535]
554 --title TEXT Title for metadata
555 --license TEXT License label for metadata
556 --license_url TEXT License URL for metadata
557 --source TEXT Source label for metadata
558 --source_url TEXT Source URL for metadata
559 --about TEXT About label for metadata
560 --about_url TEXT About URL for metadata
561 --help Show this message and exit.
562
563
564 .. [[[end]]]
565
566
567 .. _cli_help_inspect___help:
568
569 datasette inspect
570 =================
571
572 Outputs JSON representing introspected data about one or more SQLite database files.
573
574 If you are opening an immutable database, you can pass this file to the ``--inspect-data`` option to improve Datasette's performance by allowing it to skip running row counts against the database when it first starts running::
575
576 datasette inspect mydatabase.db > inspect-data.json
577 datasette serve -i mydatabase.db --inspect-file inspect-data.json
578
579 This performance optimization is used automatically by some of the ``datasette publish`` commands. You are unlikely to need to apply this optimization manually.
580
581 .. [[[cog
582 help(["inspect", "--help"])
583 .. ]]]
584
585 ::
586
587 Usage: datasette inspect [OPTIONS] [FILES]...
588
589 Generate JSON summary of provided database files
590
591 This can then be passed to "datasette --inspect-file" to speed up count
592 operations against immutable database files.
593
594 Options:
595 --inspect-file TEXT
596 --load-extension PATH:ENTRYPOINT?
597 Path to a SQLite extension to load, and
598 optional entrypoint
599 --help Show this message and exit.
600
601
602 .. [[[end]]]