Skip to content

CLI

The Tekst-API offers a simple CLI, e.g. for bootstrapping the API before startup, triggering certain maintenance routines or migrating the database after an upgrade of Tekst.

Important

If the Tekst-API is running in a container, the commands below have to be prefixed with...

docker exec -i $container

...where $container is the name of the container!

To get an overview of the available commands and their arguments, you can also run python -m tekst --help.

bootstrap

This command has to be run each time before starting up the Tekst-API. It makes sure the data in the database is compatible with the Tekst version used (and runs automatic migrations if needed and configured), inserts demo data into the database if it is empty (on first start), creates the initial admin user (if no users exist yet), generates precomputed data (cache) and updates the search indices (if necessary).

All this can only be done by a single process and should not happen concurrently. This is why it has to happen before the API startup, which is usually powered by multiple workers acting asynchronously.

python -m tekst bootstrap

index

(Re)creates/updates all search indices if they are out of date.

python -m tekst index

Tip

The index command is included in the things the maintenance command does (see below!).

precompute

Tekst uses a precomputed cache holding data that is expensive to generate but essential for the application to work. This command triggers the update/creation of the precomputed cache.

python -m tekst precompute # use -f/--force to enforce even if up-to-date

Tip

The precompute command is included in the things the maintenance command does (see below!). Regeneration of the precomputed cache is not enforced when run as part of the maintenance routine.

cleanup

Triggers the internal cleanup routine of the Tekst-API. It deletes stale user messages and outdated access tokens.

python -m tekst cleanup

Tip

The cleanup command is included in the things the maintenance command does (see below!).

maintenance

A single command that runs index, precompute and cleanup sequentially. Very handy to be scheduled as a recurring (e.g. nightly) job.

python -m tekst maintenance

migrate

Checks the data in the database for compatibility with the currently used version of Tekst and runs database migrations if necessary. This has to be used after an upgrade of Tekst if TEKST_AUTO_MIGRATE=false.

python -m tekst migrate

# Or use the --yes flag to suppress asking for confirmation:
# python -m tekst migrate --yes

schema

Generates a JSON file with the OpenAPI schema of the Tekst-API.

python -m tekst schema

This command takes several arguments for customizing its behavior:

Usage: python -m tekst schema [OPTIONS]

  Exports Tekst's OpenAPI schema to a JSON file

  Important: The active Tekst environment variables might influence the
  schema!

Options:
  -f, --to-file           Output to file defined by --output-file instead of
                          stdout
  -o, --output-file TEXT  Output file path to write to if --to-file flag is
                          set  [default: openapi.json]
  -i, --indent INTEGER    Indent output by n whitespace characters (0 for no
                          indentation)  [default: 2]
  -s, --sort-keys         Sort keys in output JSON
  -q, --quiet             Don't output anything (only effective if --to-file
                          flag is not set)
  --help                  Show this message and exit.

export

Bulk-exports one or more (or all) resources' data in on or more (or all) available export formats.

python -m tekst export

This command takes several arguments for customizing its behavior:

Usage: python -m tekst export [OPTIONS]

  Exports the contents of the given resources (or all) using the given formats
  (or all) to the given output directory

Options:
  -r, --resource TEXT  ID(s) of resource(s) to export, all if not set
  -f, --format TEXT    Format(s) to export, all if not set  [default: json,
                       tekst-json, csv]
  -o, --output TEXT    Output directory to write to  [default:
                       /tmp/tekst_resource_export/]
  -q, --quiet          Don't output anything (except errors and warnings)
  -d, --delete         Delete all existing files in the output directory
  --help               Show this message and exit.