### Install a Datasette Plugin Source: https://docs.datasette.io/en/latest/_sources/cli-reference.rst.txt Example of installing a specific Datasette plugin, 'datasette-cluster-map', using the 'datasette install' command. ```bash datasette install datasette-cluster-map ``` -------------------------------- ### Datasette Plugin Setup File Source: https://docs.datasette.io/en/latest/_sources/writing_plugins.rst.txt Example 'setup.py' file for packaging a Datasette plugin. It defines the plugin's metadata, entry points, and dependencies. ```python from setuptools import setup VERSION = "0.1" setup( name="datasette-plugin-demos", description="Examples of plugins for Datasette", author="Simon Willison", url="https://github.com/simonw/datasette-plugin-demos", license="Apache License, Version 2.0", version=VERSION, py_modules=["datasette_plugin_demos"], entry_points={ "datasette": [ "plugin_demos = datasette_plugin_demos" ] }, install_requires=["datasette"], ) ``` -------------------------------- ### Setting up a Datasette Test Instance Source: https://docs.datasette.io/en/latest/_sources/testing_plugins.rst.txt Demonstrates the basic setup for a Datasette test instance in Python. It initializes Datasette and makes a request to check installed plugins. ```python from datasette.app import Datasette import pytest @pytest.mark.asyncio async def test_plugin_is_installed(): datasette = Datasette(memory=True) response = await datasette.client.get("/-/plugins.json") assert response.status_code == 200 ``` -------------------------------- ### Datasette Install CLI Help Source: https://docs.datasette.io/en/latest/_sources/cli-reference.rst.txt Displays help information for the 'datasette install' command, used for installing new Datasette plugins. ```bash datasette install --help ``` -------------------------------- ### Datasette plugin information (JSON) Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Example output showing details of installed Datasette plugins, including name, static status, and version. ```json [ { "name": "datasette-json-html", "static": false, "templates": false, "version": "0.6" } ] ``` -------------------------------- ### Install Multiple Plugins from Requirements File Source: https://docs.datasette.io/en/latest/_sources/plugins.rst.txt List plugins in a 'requirements.txt' file and use 'datasette install -r' to install them all. This is useful for managing multiple plugin dependencies. ```text datasette-vega datasette-cluster-map ``` ```bash datasette install -r requirements.txt ``` -------------------------------- ### Start Datasette with Root User Authentication Source: https://docs.datasette.io/en/latest/_sources/changelog.rst.txt Use the --root option to start Datasette and generate a one-time use URL for root user authentication. This is useful for initial setup and testing. ```bash datasette fixtures.db --root ``` -------------------------------- ### Install Documentation Dependencies Source: https://docs.datasette.io/en/latest/_sources/changelog.rst.txt Use this command to install all dependencies required for building Datasette's documentation. ```bash pip install -e .[docs] ``` -------------------------------- ### Start Datasette with Default Deny and Configuration File Source: https://docs.datasette.io/en/latest/authentication.html Use --default-deny with a configuration file to explicitly grant permissions to specific users. This example allows only the user 'alice'. ```bash datasette --default-deny data.db --config datasette.yaml ``` -------------------------------- ### Full Datasette Configuration Example Source: https://docs.datasette.io/en/latest/_sources/configuration.rst.txt An example of a complete datasette.yaml or datasette.json file showing settings, global plugins, and database/table specific configurations. ```json { "settings": { "default_page_size": 50, "sql_time_limit_ms": 3500, "max_returned_rows": 2000 }, "plugins": { "datasette-my-plugin": { "key": "valueA" } }, "databases": { "your_db_name": { "plugins": { "datasette-my-plugin": { "key": "valueA" } }, "tables": { "your_table_name": { "allow": { "id": "root" }, "plugins": { "datasette-my-plugin": { "key": "valueB" } } } } } } } ``` -------------------------------- ### Create Installable Datasette Plugin Structure Source: https://docs.datasette.io/en/latest/_sources/writing_plugins.rst.txt Use the 'datasette-plugin' cookiecutter template to quickly scaffold a new, installable Datasette plugin. This includes example tests and CI workflows. ```bash cookiecutter gh:simonw/datasette-plugin ``` -------------------------------- ### Trace HTTP GET requests Source: https://docs.datasette.io/en/latest/_sources/internals.rst.txt This example demonstrates using the trace context manager to record the start, end, and duration of HTTP GET requests made with httpx. ```python from datasette.tracer import trace import httpx async def fetch_url(url): with trace("fetch-url", url=url): async with httpx.AsyncClient() as client: return await client.get(url) ``` -------------------------------- ### Example Docker Build Output for Datasette Package Source: https://docs.datasette.io/en/latest/_sources/publish.rst.txt This is example output from the 'datasette package' command, showing the steps involved in building a Docker image. ```text Sending build context to Docker daemon 4.459MB Step 1/7 : FROM python:3.11.0-slim-bullseye ---> 79e1dc9af1c1 Step 2/7 : COPY . /app ---> Using cache ---> cd4ec67de656 Step 3/7 : WORKDIR /app ---> Using cache ---> 139699e91621 Step 4/7 : RUN pip install datasette ---> Using cache ---> 340efa82bfd7 Step 5/7 : RUN datasette inspect parlgov.db --inspect-file inspect-data.json ---> Using cache ---> 5fddbe990314 Step 6/7 : EXPOSE 8001 ---> Using cache ---> 8e83844b0fed Step 7/7 : CMD datasette serve parlgov.db --port 8001 --inspect-file inspect-data.json --setting sql_time_limit_ms 2500 ---> Using cache ---> 1bd380ea8af3 Successfully built 1bd380ea8af3 ``` -------------------------------- ### Deploy Plugins with datasette publish --install Source: https://docs.datasette.io/en/latest/plugins.html When publishing or packaging, use the `--install` argument with `datasette publish` or `datasette package` to automatically install specific plugins. This ensures plugins are available in the deployed environment. ```bash datasette publish cloudrun mydb.db --install=datasette-vega ``` ```bash datasette publish cloudrun mydb.db \ --install=https://url-to-my-package.zip ``` -------------------------------- ### Build Documentation Locally Source: https://docs.datasette.io/en/latest/_sources/changelog.rst.txt After installing dependencies, use this command to build the documentation locally. ```bash cd docs && make livehtml ``` -------------------------------- ### Install CodeMirror Packages Source: https://docs.datasette.io/en/latest/contributing.html Install the CodeMirror library and the SQL language support package using npm. ```bash npm i codemirror @codemirror/lang-sql ``` -------------------------------- ### Install Dependencies with uv Source: https://docs.datasette.io/en/latest/_sources/contributing.rst.txt Use uv to create a virtual environment and install Datasette and its development dependencies. This is the recommended method for setting up a development environment. ```bash cd datasette uv run pytest ``` -------------------------------- ### Configure and Start Datasette with OpenRC Source: https://docs.datasette.io/en/latest/_sources/deploying.rst.txt Commands to add the Datasette service to the OpenRC runlevels and start the service. These are used to ensure Datasette starts automatically on boot and is running. ```bash rc-update add datasette rc-service datasette start ``` -------------------------------- ### Running Datasette with Metadata and Configuration Source: https://docs.datasette.io/en/latest/upgrade_guide.html How to start Datasette specifying separate metadata and configuration files. ```bash datasette --metadata metadata.yaml --config datasette.yaml # Or the shortened version: datasette -m metadata.yml -c datasette.yml ``` -------------------------------- ### Install Datasette and Verify in Virtual Environment Source: https://docs.datasette.io/en/latest/installation.html Installs Datasette within the activated virtual environment and verifies its installation and version. ```bash pip install datasette ``` ```bash which datasette ``` ```bash datasette --version ``` -------------------------------- ### Install Datasette plugin using Homebrew Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Install plugins for Datasette after installing Datasette itself using Homebrew. ```bash datasette install datasette-vega ``` -------------------------------- ### List Installed Datasette Plugins Source: https://docs.datasette.io/en/latest/_sources/plugins.rst.txt Use the `datasette plugins --requirements` command to list installed plugins. This output can be redirected to a requirements.txt file for easy installation on other Datasette instances. ```bash datasette plugins --requirements ``` ```bash datasette plugins --requirements > requirements.txt ``` -------------------------------- ### Install Datasette using pipx Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Install Datasette in an isolated environment using pipx. ```bash pipx install datasette ``` -------------------------------- ### Run Datasette with Metadata Source: https://docs.datasette.io/en/latest/_sources/metadata.rst.txt Example of how to run Datasette with database files and a metadata file. ```bash datasette database1.db database2.db --metadata metadata.yaml ``` -------------------------------- ### Install Datasette Plugins Source: https://docs.datasette.io/en/latest/cli-reference.html Installs new Datasette plugins from PyPI into the same environment as Datasette. Supports upgrading packages and installing from a requirements file or in editable mode. ```bash datasette install datasette-cluster-map ``` ```bash datasette install [OPTIONS] [PACKAGES]... ``` -------------------------------- ### Deploy Plugins with datasette publish Source: https://docs.datasette.io/en/latest/_sources/plugins.rst.txt Use the '--install' argument with 'datasette publish' or 'datasette package' to specify plugins that should be installed during the deployment process. This can be used multiple times for different plugins. ```bash datasette publish cloudrun mydb.db --install=datasette-vega ``` ```bash datasette publish cloudrun mydb.db \ --install=https://url-to-my-package.zip ``` -------------------------------- ### Verify Datasette Installation Source: https://docs.datasette.io/en/latest/installation.html Run this command after installation to confirm the Datasette version. ```bash datasette --version ``` -------------------------------- ### Install Plugin with Test Dependencies Source: https://docs.datasette.io/en/latest/testing_plugins.html Installs the plugin in editable mode, including its test dependencies. ```bash pip install -e '.[test]' ``` -------------------------------- ### Create a Table from Example Data via JSON API Source: https://docs.datasette.io/en/latest/_sources/json_api.rst.txt Create a table and insert initial rows by providing example data in the POST request body. Requires actions_create_table and actions_insert_row permissions. Datasette infers the schema from the provided rows. ```http POST //-/create Content-Type: application/json Authorization: Bearer dstok_ ``` ```json { "table": "creatures", "rows": [ { "id": 1, "name": "Tarantula" }, { "id": 2, "name": "Kākāpō" } ], "pk": "id" } ``` -------------------------------- ### Starting Datasette with Custom Templates Source: https://docs.datasette.io/en/latest/_sources/custom_templates.rst.txt Command to start Datasette with a custom template directory. This allows Datasette to find and use your custom HTML files. ```bash datasette mydb.db --template-dir=templates/ ``` -------------------------------- ### Create Table from Example Data Source: https://docs.datasette.io/en/latest/json_api.html Use this endpoint to create a new table and insert rows by providing example data. This requires create-table and insert-row permissions. The response includes details about the created table and the number of inserted rows. ```http POST //-/create Content-Type: application/json Authorization: Bearer dstok_ ``` ```json { "table": "creatures", "rows": [ { "id": 1, "name": "Tarantula" }, { "id": 2, "name": "Kākāpō" } ], "pk": "id" } ``` ```json { "ok": true, "database": "data", "table": "creatures", "table_url": "http://127.0.0.1:8001/data/creatures", "table_api_url": "http://127.0.0.1:8001/data/creatures.json", "schema": "CREATE TABLE [creatures] ( [id] INTEGER PRIMARY KEY, [name] TEXT )", "row_count": 2 } ``` ```json { "ok": false, "errors": [ "UNIQUE constraint failed: creatures.id" ] } ``` -------------------------------- ### Install CodeMirror and SQL Language Package Source: https://docs.datasette.io/en/latest/_sources/contributing.rst.txt Install the necessary CodeMirror packages for SQL editing. This is a prerequisite for building the bundle. ```bash npm i codemirror @codemirror/lang-sql ``` -------------------------------- ### Installing datasette-upgrade Plugin Source: https://docs.datasette.io/en/latest/_sources/upgrade_guide.md.txt Install the datasette-upgrade plugin to help migrate existing metadata files. This plugin is necessary before running the upgrade command. ```bash datasette install datasette-upgrade ``` -------------------------------- ### Example: Add Stored Query Source: https://docs.datasette.io/en/latest/_sources/internals.rst.txt Example of adding a stored query with basic parameters like database, name, SQL, and title. ```python await datasette.add_query( database="fixtures", name="recent_rows", sql="select * from facetable order by created desc limit 10", title="Recent rows", ``` -------------------------------- ### List Installed Datasette Plugins Source: https://docs.datasette.io/en/latest/cli-reference.html Outputs a JSON array of installed plugins, their versions, and hooks. Use --all to include built-in plugins or --requirements to output a requirements.txt file. ```bash datasette plugins [OPTIONS] ``` -------------------------------- ### Configuring Datasette with command-line options Source: https://docs.datasette.io/en/latest/settings.html This example shows how to specify multiple databases, metadata file, template directory, plugins directory, and static directory using command-line options. ```bash datasette one.db two.db \ --metadata=metadata.json \ --template-dir=templates/ \ --plugins-dir=plugins \ --static css:css ``` -------------------------------- ### Run Datasette after pip installation Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Execute this command to start Datasette after installing it with pip. ```bash datasette ``` -------------------------------- ### Publish Datasette with Plugin Installation Source: https://docs.datasette.io/en/latest/_sources/publish.rst.txt Include additional Datasette plugins, such as datasette-vega, during the publishing process. ```bash datasette publish cloudrun mydatabase.db --service=my-service --install=datasette-vega ``` -------------------------------- ### Initialize Database Table on Startup Source: https://docs.datasette.io/en/latest/plugin_hooks.html This `startup` hook example demonstrates returning an async function to initialize a database table. It creates 'my_table' if it doesn't already exist. ```python @hookimpl def startup(datasette): async def inner(): db = datasette.get_database() if "my_table" not in await db.table_names(): await db.execute_write(""" create table my_table (mycol text) """) return inner ``` -------------------------------- ### Install Python with Homebrew on macOS Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Install Python using Homebrew on macOS to get a version with SQLite extension support. ```bash brew install python ``` -------------------------------- ### Root User Authentication URL Example Source: https://docs.datasette.io/en/latest/_sources/changelog.rst.txt An example of the URL generated for root user authentication after starting Datasette with the --root option. This URL is used to access Datasette as the root actor. ```http http://127.0.0.1:8001/-/auth-token?token=5b632f8cd44b868df625f5a6e2185d88eea5b22237fd3cc8773f107cc4fd6477 ``` -------------------------------- ### Datasette Serve Command Help Source: https://docs.datasette.io/en/latest/_sources/cli-reference.rst.txt Shows the full list of options for the 'datasette serve' command, used to start the Datasette web application. ```bash Usage: datasette serve [OPTIONS] [FILES]... Serve up specified SQLite database files with a web UI Options: -i, --immutable PATH Database files to open in immutable mode -h, --host TEXT Host for server. Defaults to 127.0.0.1 which means only connections from the local machine will be allowed. Use 0.0.0.0 to listen to all IPs and allow access from other machines. -p, --port INTEGER RANGE Port for server, defaults to 8001. Use -p 0 to automatically assign an available port. [0<=x<=65535] --uds TEXT Bind to a Unix domain socket --reload Automatically reload if code or metadata change detected - useful for development --cors Enable CORS by serving Access-Control-Allow- Origin: * --load-extension PATH:ENTRYPOINT? Path to a SQLite extension to load, and optional entrypoint --inspect-file TEXT Path to JSON file created using "datasette inspect" -m, --metadata FILENAME Path to JSON/YAML file containing license/source metadata --template-dir DIRECTORY Path to directory containing custom templates --plugins-dir DIRECTORY Path to directory containing custom plugins --static MOUNT:DIRECTORY Serve static files from this directory at /MOUNT/... --memory Make /_memory database available -c, --config FILENAME Path to JSON/YAML Datasette configuration file -s, --setting SETTING... nested.key, value setting to use in Datasette configuration --secret TEXT Secret used for signing secure values, such as signed cookies --root Output URL that sets a cookie authenticating the root user --default-deny Deny all permissions by default --get TEXT Run an HTTP GET request against this path, print results and exit ``` -------------------------------- ### Datasette Root Login URL Example Source: https://docs.datasette.io/en/latest/authentication.html When starting Datasette with --root, a single-use login URL is generated. Click this URL to authenticate as the root user. ```text http://127.0.0.1:8001/-/auth-token?token=786fc524e0199d70dc9a581d851f466244e114ca92f33aa3b42a139e9388daa7 INFO: Started server process [25801] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:8001 (Press CTRL+C to quit) ``` -------------------------------- ### Start Datasette with Pre-calculated Row Counts Source: https://docs.datasette.io/en/latest/_sources/performance.rst.txt Start Datasette using both the '-i' immutable mode option and the '--inspect-file' option pointing to a pre-generated JSON file of row counts. This ensures the cached counts are used to speed up startup. ```bash datasette -i data.db --inspect-file=counts.json ``` -------------------------------- ### Plugins JSON Source: https://docs.datasette.io/en/latest/_sources/introspection.rst.txt Lists installed plugins and their versions. Append '?all=1' to include default plugins. ```json [ { "name": "datasette_cluster_map", "static": true, "templates": false, "version": "0.10", "hooks": ["extra_css_urls", "extra_js_urls", "extra_body_script"] } ] ``` -------------------------------- ### Create and Verify Tokens Source: https://docs.datasette.io/en/latest/_sources/plugin_hooks.rst.txt Examples of using datasette.create_token() and datasette.verify_token(). Shows how to use the default handler and a specific named handler. ```python # Uses first registered handler (default) token = await datasette.create_token("user123") # Uses a specific handler by name token = await datasette.create_token( "user123", handler="database" ) # Verification tries all handlers actor = await datasette.verify_token(token) ``` -------------------------------- ### Load SpatiaLite Extension (Default Location) Source: https://docs.datasette.io/en/latest/_sources/spatialite.rst.txt Load the SpatiaLite extension when starting Datasette. Assumes SpatiaLite is in a common installation location. SQL queries are disabled by default. ```bash datasette --load-extension=spatialite --setting default_allow_sql off ``` -------------------------------- ### Get actor JSON Source: https://docs.datasette.io/en/latest/_sources/cli-reference.rst.txt Simulate a request as a specific actor by passing a JSON representation of the actor to the --actor option. This example retrieves the actor's JSON representation. ```bash datasette --memory --actor '{"id": "root"}' --get '/-/actor.json' ``` -------------------------------- ### Fetch Data with datasette --get Source: https://docs.datasette.io/en/latest/_sources/changelog.rst.txt Retrieve data from a Datasette instance without starting a web server. This command is useful for programmatic access to specific URLs within Datasette. ```bash datasette --get URL ``` -------------------------------- ### Create Database Table on Startup Source: https://docs.datasette.io/en/latest/_sources/plugin_hooks.rst.txt Return an async function from the startup hook to perform asynchronous operations like creating database tables if they don't exist. ```python @hookimpl def startup(datasette): async def inner(): db = datasette.get_database() if "my_table" not in await db.table_names(): await db.execute_write(""" create table my_table (mycol text) """) return inner ``` -------------------------------- ### Display Configuration Options Source: https://docs.datasette.io/en/latest/_sources/changelog.rst.txt Use the `datasette --help-config` command to view all available configuration options for Datasette, including defaults and descriptions. ```bash datasette --help-config ``` -------------------------------- ### Install datasette-hashed-urls Plugin Source: https://docs.datasette.io/en/latest/performance.html Use this command to install the datasette-hashed-urls plugin. Ensure you have pip installed. ```bash datasette install datasette-hashed-urls ``` -------------------------------- ### Verify Datasette installation Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Run this command after installation to confirm the version of Datasette installed via Homebrew. ```bash datasette --version ``` -------------------------------- ### Instantiating Datasette with Database Files Source: https://docs.datasette.io/en/latest/internals.html Shows how to initialize a Datasette instance with specific database files from disk. This is useful for loading existing SQLite databases into Datasette. ```python from datasette.app import Datasette # The files= argument can load files from disk datasette = Datasette(files=["/path/to/my-database.db"]) ``` -------------------------------- ### Example: Create API Token Source: https://docs.datasette.io/en/latest/_sources/cli-reference.rst.txt Demonstrates how to create a signed API token for a specific actor ID using a provided secret. ```bash datasette create-token root --secret mysecret ``` -------------------------------- ### Datasette CLI Help Source: https://docs.datasette.io/en/latest/_sources/cli-reference.rst.txt Displays a list of all available commands and global options for the Datasette CLI. ```bash Usage: datasette [OPTIONS] COMMAND [ARGS]... Datasette is an open source multi-tool for exploring and publishing data About Datasette: https://datasette.io/ Full documentation: https://docs.datasette.io/ Options: --version Show the version and exit. --help Show this message and exit. Commands: serve* Serve up specified SQLite database files with a web UI create-token Create a signed API token for the specified actor ID inspect Generate JSON summary of provided database files install Install plugins and packages from PyPI into the same... package Package SQLite files into a Datasette Docker container plugins List currently installed plugins publish Publish specified SQLite database files to the internet... uninstall Uninstall plugins and Python packages from the Datasette... ``` -------------------------------- ### Starting Datasette with Metadata and Config Files Source: https://docs.datasette.io/en/latest/_sources/upgrade_guide.md.txt To run Datasette with both metadata and configuration files, use the --metadata and --config flags. The shortened versions -m and -c can also be used. ```bash datasette --metadata metadata.yaml --config datasette.yaml # Or the shortened version: datasette -m metadata.yml -c datasette.yml ``` -------------------------------- ### Starting Datasette from a configuration directory Source: https://docs.datasette.io/en/latest/settings.html Run Datasette by providing the path to a directory containing database files, configuration, templates, plugins, and static assets. Datasette automatically configures itself based on the files found. ```bash datasette my-app/ ``` -------------------------------- ### List all plugins including defaults with datasette plugins --all Source: https://docs.datasette.io/en/latest/_sources/plugins.rst.txt Running 'datasette plugins --all' includes default plugins shipped with Datasette, providing a comprehensive list of all available plugins. ```json [ { "name": "datasette.actor_auth_cookie", "static": false, "templates": false, "version": null, "hooks": [ "actor_from_request" ] }, { "name": "datasette.blob_renderer", "static": false, "templates": false, "version": null, "hooks": [ "register_output_renderer" ] }, { "name": "datasette.default_actions", "static": false, "templates": false, "version": null, "hooks": [ "register_actions" ] }, { "name": "datasette.default_column_types", "static": false, "templates": false, "version": null, "hooks": [ "register_column_types" ] }, { "name": "datasette.default_database_actions", "static": false, "templates": false, "version": null, "hooks": [ "database_actions" ] }, { "name": "datasette.default_debug_menu", "static": false, "templates": false, "version": null, "hooks": [ "jump_items_sql" ] }, { "name": "datasette.default_jump_items", "static": false, "templates": false, "version": null, "hooks": [ "jump_items_sql" ] }, { "name": "datasette.default_magic_parameters", "static": false, "templates": false, "version": null, "hooks": [ "register_magic_parameters" ] }, { "name": "datasette.default_permissions", "static": false, "templates": false, "version": null, "hooks": [ "permission_resources_sql" ] }, { "name": "datasette.default_permissions.tokens", "static": false, "templates": false, "version": null, "hooks": [ "actor_from_request", "register_token_handler" ] }, { "name": "datasette.events", "static": false, "templates": false, "version": null, "hooks": [ "register_events", "write_wrapper" ] }, { "name": "datasette.facets", "static": false, "templates": false, "version": null, "hooks": [ "register_facet_classes" ] }, { "name": "datasette.filters", "static": false, "templates": false, "version": null, "hooks": [ "filters_from_request" ] }, { "name": "datasette.forbidden", "static": false, ``` -------------------------------- ### Install SpatiaLite on Linux (Debian/Ubuntu) Source: https://docs.datasette.io/en/latest/_sources/spatialite.rst.txt Install SpatiaLite packages on Debian-based Linux distributions. ```bash apt install spatialite-bin libsqlite3-mod-spatialite ``` -------------------------------- ### List installed Datasette plugins Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Command to check which plugins are currently installed for Datasette. ```bash datasette plugins ``` -------------------------------- ### Run Datasette with plugins Source: https://docs.datasette.io/en/latest/_sources/getting_started.rst.txt Enable Datasette plugins by specifying them with the --load-extension option. This example loads the 'datasette-json-html' plugin. ```bash datasette --load-extension datasette_json_html mydatabase.db ``` -------------------------------- ### Verify Homebrew Datasette Installation Source: https://docs.datasette.io/en/latest/installation.html Confirms the path to the Datasette executable installed via Homebrew. ```bash which datasette ``` -------------------------------- ### Install pipx without Homebrew Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Install pipx using pip if you are not using Homebrew on macOS. ```bash python3 -m pip install --user pipx python3 -m pipx ensurepath ``` -------------------------------- ### Datasette plugin information after upgrade (JSON) Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Example output showing updated details of a Datasette plugin after an upgrade. ```json [ { "name": "datasette-vega", "static": true, "templates": false, "version": "0.6.2" } ] ``` -------------------------------- ### Start Datasette with a Plugin Directory Source: https://docs.datasette.io/en/latest/_sources/writing_plugins.rst.txt Command to serve a Datasette database while specifying a directory containing custom plugins. This is used after creating a one-off plugin. ```bash datasette serve mydb.db --plugins-dir=plugins/ ``` -------------------------------- ### Build Datasette Documentation Locally Source: https://docs.datasette.io/en/latest/_sources/contributing.rst.txt Build the HTML version of the documentation locally using Sphinx. Navigate to the 'docs/' directory and run 'make html'. ```bash cd docs/ uv run make html ``` -------------------------------- ### Inject Datasette plugin using pipx Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Install additional Datasette plugins into an existing pipx installation. ```bash pipx inject datasette datasette-json-html ``` -------------------------------- ### Datasette Serve Command with Metadata Source: https://docs.datasette.io/en/latest/_sources/changelog.rst.txt Launch Datasette with a custom metadata file to apply configurations like extra CSS/JS URLs. Ensure the metadata file path is correctly specified. ```bash datasette mydb.db --metadata=metadata.json ``` -------------------------------- ### Install Testing Packages Source: https://docs.datasette.io/en/latest/testing_plugins.html Installs pytest and pytest-asyncio, which are essential for writing and running asynchronous tests for Datasette plugins. ```bash pip install pytest pytest-asyncio ``` -------------------------------- ### Start Datasette with Root Access Source: https://docs.datasette.io/en/latest/_sources/authentication.rst.txt Use the --root flag to enable the root user, granting all permissions for local development and testing. This generates a single-use login URL. ```bash datasette --root ``` -------------------------------- ### Install Plugins into Datasette Docker Image Source: https://docs.datasette.io/en/latest/installation.html Installs a plugin (datasette-vega) into a new Docker image named 'datasette-with-plugins'. ```bash docker run datasetteproject/datasette \ pip install datasette-vega ``` ```bash docker commit $(docker ps -lq) datasette-with-plugins ``` -------------------------------- ### Create Event Tracking Table on Startup Source: https://docs.datasette.io/en/latest/_sources/plugin_hooks.rst.txt This `startup` hook ensures the `datasette_events` table exists in the 'events' database before any events are tracked. It creates the table with appropriate columns if it doesn't already exist. ```python from datasette import hookimpl import json @hookimpl def startup(datasette): async def inner(): db = datasette.get_database("events") await db.execute_write(""" create table if not exists datasette_events ( id integer primary key, event_type text, created text, actor text, properties text ) """) return inner ``` -------------------------------- ### Install ipdb for Debugging Source: https://docs.datasette.io/en/latest/_sources/contributing.rst.txt Install the ipdb package to enable its use with the --pdb option for enhanced debugging. ```bash uv run datasette install ipdb ``` -------------------------------- ### Run Datasette with a database file Source: https://docs.datasette.io/en/latest/_sources/getting_started.rst.txt Start a Datasette server instance using a SQLite database file. Datasette will automatically create the database if it doesn't exist. ```bash datasette mydatabase.db ``` -------------------------------- ### Install Datasette using pip Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Install Datasette and its dependencies using pip. Requires Python 3.10 or higher. ```bash pip install datasette ``` -------------------------------- ### Install Datasette using Homebrew Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Use this command to install the latest version of Datasette if you are using Homebrew on macOS. ```bash brew install datasette ``` -------------------------------- ### Binary Download from SQL Query Source: https://docs.datasette.io/en/latest/binary_data.html This example demonstrates linking to binary data from an arbitrary SQL query using `_blob_column=` and `_blob_hash=` to specify the SHA-256 hash of the target value. ```http https://latest.datasette.io/fixtures.blob?sql=select+data+from+binary_data&_blob_column=data&_blob_hash=f3088978da8f9aea479ffc7f631370b968d2e855eeb172bea7f6c7a04262bb6d ``` -------------------------------- ### Install Older Datasette Version Source: https://docs.datasette.io/en/latest/_sources/changelog.rst.txt If you are running Python 3.5, you should stick with version 0.30.2. This command installs that specific version. ```bash pip install datasette==0.30.2 ``` -------------------------------- ### Install SpatiaLite Tools on OS X Source: https://docs.datasette.io/en/latest/_sources/spatialite.rst.txt Install the SpatiaLite command-line tools and dynamic library on macOS using Homebrew. ```bash brew update brew install spatialite-tools ``` -------------------------------- ### Run Datasette with Custom Metadata and Plugins Source: https://docs.datasette.io/en/latest/_sources/contributing.rst.txt Start Datasette using a custom metadata file and a directory of plugins. This allows for more complex testing scenarios and custom configurations. ```bash uv run datasette fixtures.db -m fixtures-metadata.json --plugins-dir=fixtures-plugins/ ``` -------------------------------- ### Datasette Publish Cloud Run Help Source: https://docs.datasette.io/en/latest/_sources/cli-reference.rst.txt Displays help for publishing data to Datasette running on Google Cloud Run. Includes options for metadata, service configuration, and resource allocation. ```bash Usage: datasette publish cloudrun [OPTIONS] [FILES]... Publish databases to Datasette running on Cloud Run Options: -m, --metadata FILENAME Path to JSON/YAML file containing metadata to publish --extra-options TEXT Extra options to pass to datasette serve --branch TEXT Install datasette from a GitHub branch e.g. main --template-dir DIRECTORY Path to directory containing custom templates --plugins-dir DIRECTORY Path to directory containing custom plugins --static MOUNT:DIRECTORY Serve static files from this directory at /MOUNT/... --install TEXT Additional packages (e.g. plugins) to install --plugin-secret ... Secrets to pass to plugins, e.g. --plugin- secret datasette-auth-github client_id xxx --version-note TEXT Additional note to show on /-/versions --secret TEXT Secret used for signing secure values, such as signed cookies --title TEXT Title for metadata --license TEXT License label for metadata --license_url TEXT License URL for metadata --source TEXT Source label for metadata --source_url TEXT Source URL for metadata --about TEXT About label for metadata --about_url TEXT About URL for metadata -n, --name TEXT Application name to use when building --service TEXT Cloud Run service to deploy (or over-write) --spatialite Enable SpatialLite extension --show-files Output the generated Dockerfile and metadata.json --memory TEXT Memory to allocate in Cloud Run, e.g. 1Gi --cpu [1|2|4] Number of vCPUs to allocate in Cloud Run --timeout INTEGER Build timeout in seconds --apt-get-install TEXT Additional packages to apt-get install --max-instances INTEGER Maximum Cloud Run instances (use 0 to remove the limit) [default: 1] --min-instances INTEGER Minimum Cloud Run instances --artifact-repository TEXT Artifact Registry repository to store the image [default: datasette] --artifact-region TEXT Artifact Registry location (region or multi- region) [default: us] --artifact-project TEXT Project ID for Artifact Registry (defaults to the active project) --help Show this message and exit. ``` -------------------------------- ### TOML for Test Dependencies Source: https://docs.datasette.io/en/latest/_sources/testing_plugins.rst.txt This TOML snippet shows how to declare test dependencies for an installable package in pyproject.toml. These dependencies can then be installed using pip. ```toml [project] name = "datasette-my-plugin" # ... [project.optional-dependencies] test = ["pytest", "pytest-asyncio"] ``` -------------------------------- ### Datasette Plugins CLI Help Source: https://docs.datasette.io/en/latest/_sources/cli-reference.rst.txt Displays help information for the 'datasette plugins' command, listing installed plugins and their details. ```bash datasette plugins --help ``` -------------------------------- ### Install Dependencies with pip Source: https://docs.datasette.io/en/latest/_sources/contributing.rst.txt Alternatively, manage your own virtual environment using Python's venv module and install development dependencies with pip. ```bash python3 -m venv ./venv source venv/bin/activate python3 -m pip install -e . --group dev ``` -------------------------------- ### Search Example with Facet Source: https://docs.datasette.io/en/latest/_sources/introspection.rst.txt Demonstrates how a search query with '?q=facet' returns only items matching the pattern '.*facet.*'. ```json { "matches": [ { "name": "fixtures: facetable", "url": "/fixtures/facetable", "type": "table", "description": null } ], "truncated": false } ``` -------------------------------- ### Install Plugin into Datasette Docker Image Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Install a Datasette plugin (e.g., datasette-vega) into a new local Docker image named 'datasette-with-plugins'. ```bash docker run datasetteproject/datasette \ pip install datasette-vega docker commit $(docker ps -lq) datasette-with-plugins ``` -------------------------------- ### Show available settings Source: https://docs.datasette.io/en/latest/_sources/cli-reference.rst.txt This command outputs all available Datasette settings. These settings can be configured when starting the Datasette server. ```bash datasette serve --help-settings ``` -------------------------------- ### Install pipx using Homebrew Source: https://docs.datasette.io/en/latest/_sources/installation.rst.txt Install pipx on macOS using Homebrew. This tool helps manage Python applications in isolated environments. ```bash brew install pipx pipx ensurepath ```