cli#

Command line interface for the application.

Litestar CLI#

app#

Litestar CLI.

The application will be automatically discovered if it’s in one of these canonical paths: ‘app.py’, ‘app/’, ‘application.py’ or ‘application/’. Submodules within ‘app/’ and ‘application/’ directories are also scanned. When auto-discovering application factories, functions with the name ‘create_app’ are considered, or functions that are annotated as returning a ‘Litestar’ instance.

Alternatively, the application can be specified explicitly via the ‘–app’ option (‘litestar –app=<module name>.<submodule>:<app instance or factory>’) or the ‘LITESTAR_APP’ environment variable of the same name.

Usage

app [OPTIONS] COMMAND [ARGS]...

Options

--app <app_path>#

Module path to a Litestar application

--app-dir <app_dir>#

Look for APP in the specified directory, by adding this to the PYTHONPATH. Defaults to the current working directory.

info#

Show information about the detected Litestar app.

Usage

app info [OPTIONS]

queues#

litestar-queues operations.

Usage

app queues [OPTIONS] COMMAND [ARGS]...
list#

List queued task records with filtering and pagination.

Usage

app queues list [OPTIONS]

Options

--status <statuses>#

Filter by task status. Repeatable.

Options:

pending | scheduled | running | completed | failed | cancelled | expired

--queue <queue_filter>#

Filter by logical queue name.

--task-name <task_name>#

Filter by registered task name.

--key <dedup_key>#

Filter by deduplication key.

--limit <limit>#

Maximum records to return (default 50).

--offset <offset>#

Zero-based starting record offset (default 0).

--json#

Emit machine-readable JSON.

run#

Start a standalone worker fleet.

Usage

app queues run [OPTIONS]

Options

--queue <queues>#

Queue name to process. Repeatable.

--max-concurrency <max_concurrency>#

Override WorkerConfig.max_concurrency for this run.

--drain-timeout <drain_timeout>#

Seconds to wait for in-flight tasks to drain after SIGTERM/SIGINT. Defaults to QueueConfig.worker.graceful_shutdown_timeout.

run-consumer#

Start a continuous external broker consumer.

Usage

app queues run-consumer [OPTIONS]

Options

--backend <backend>#

Required Configured broker backend to consume.

Options:

kafka | pubsub | rabbitmq | sqs

--max-concurrency <max_concurrency>#
--drain-timeout <drain_timeout>#
run-maintenance#

Run one bounded maintenance pass (external reconcile, stale recovery, and retention) and exit. Thresholds and limits come from QueueConfig.maintenance; this command never starts a worker or runs due work.

Usage

app queues run-maintenance [OPTIONS]

Options

--phase <phases>#

Maintenance phase to run. Repeatable; defaults to every configured phase. Only narrows configuration.

Options:

expire | external | stale | schedules | terminal | events

--json#

Emit machine-readable JSON.

run-task#

Run one queued record by id (external-executor consumer). By default reads the task id QUEUES_TASK_ID and QUEUES_CONFIG_FACTORY from the environment; the options below override those defaults so a job can be run by hand.

Usage

app queues run-task [OPTIONS]

Options

--task-id <task_id>#

Run the queued record with this id (local one-shot).

--config-factory <config_factory>#

module:callable returning a QueueConfig or QueueService.

--task-modules <task_modules>#

Comma-separated modules to import before running the task.

scheduler-health#

Exit non-zero if the scheduler canary task has not completed within the window.

Usage

app queues scheduler-health [OPTIONS]

Options

--minutes <minutes>#

Staleness threshold in minutes (default 5).

status#

Show queue status counts.

Usage

app queues status [OPTIONS]

Options

--queue <queue_filter>#

Count only records in this queue.

--json#

Emit machine-readable JSON.

routes#

Display information about the application’s routes.

Usage

app routes [OPTIONS]

Options

--schema#

Include schema routes

--exclude <exclude>#

routes to exclude via regex

run#

Run a Litestar app. (requires ‘uvicorn’ to be installed).

The application will be automatically discovered, or can be set as an option to the main ‘litestar’ command. Run ‘litestar –help’ for more information about app autodiscovery

Usage

app run [OPTIONS]

Options

-r, --reload#

Reload server on changes

-R, --reload-dir <reload_dir>#

Directories to watch for file changes

-I, --reload-include <reload_include>#

Glob patterns for files to include when watching for file changes

-E, --reload-exclude <reload_exclude>#

Glob patterns for files to exclude when watching for file changes

-p, --port <port>#

Serve under this port

Default:

8000

-W, --wc, --web-concurrency <wc>#

The number of HTTP workers to launch

Default:

1

-H, --host <host>#

Server under this host

Default:

'127.0.0.1'

-F, --fd, --file-descriptor <fd>#

Bind to a socket from this file descriptor.

-U, --uds, --unix-domain-socket <uds>#

Bind to a UNIX domain socket.

-d, --debug#

Run app in debug mode

-P, --pdb, --use-pdb#

Drop into PDB on an exception

--ssl-certfile <ssl_certfile>#

Location of the SSL cert file

--ssl-keyfile <ssl_keyfile>#

Location of the SSL key file

--create-self-signed-cert#

If certificate and key are not found at specified locations, create a self-signed certificate and a key

Environment variables

LITESTAR_RELOAD

Provide a default for -r

LITESTAR_RELOAD_DIRS

Provide a default for -R

LITESTAR_RELOAD_INCLUDES

Provide a default for -I

LITESTAR_RELOAD_EXCLUDES

Provide a default for -E

LITESTAR_PORT

Provide a default for -p

['LITESTAR_WEB_CONCURRENCY', 'WEB_CONCURRENCY']

Provide a default for -W

LITESTAR_HOST

Provide a default for -H

LITESTAR_FILE_DESCRIPTOR

Provide a default for -F

LITESTAR_UNIX_DOMAIN_SOCKET

Provide a default for -U

LITESTAR_DEBUG

Provide a default for -d

LITESTAR_PDB

Provide a default for -P

LITESTAR_SSL_CERT_PATH

Provide a default for --ssl-certfile

LITESTAR_SSL_KEY_PATH

Provide a default for --ssl-keyfile

LITESTAR_CREATE_SELF_SIGNED_CERT

Provide a default for --create-self-signed-cert

schema#

Manage server-side OpenAPI schemas.

Usage

app schema [OPTIONS] COMMAND [ARGS]...
openapi#

Generate an OpenAPI Schema.

Usage

app schema openapi [OPTIONS]

Options

--output <output>#

output file path

Default:

PosixPath('openapi_schema.json')

typescript#

Generate TypeScript specs from the OpenAPI schema.

Usage

app schema typescript [OPTIONS]

Options

--output <output>#

output file path

Default:

PosixPath('api-specs.ts')

--namespace <namespace>#

namespace to use for the typescript specs

security#

Litestar Security operations.

Usage

app security [OPTIONS] COMMAND [ARGS]...

Options

--version#

Show the version and exit.

routes#

Display the compiled security posture of every registered route.

app is supplied by Litestar. This group is published as a litestar.commands entry point, so the root CLI group wraps its subcommands and injects the application. Litestar’s CLI helpers are imported inside the body rather than at module scope, because importing them there would close a cycle: litestar.cli loads its entry points, which include this module.

Usage

app security routes [OPTIONS]

sessions#

Manage server-side sessions.

Usage

app sessions [OPTIONS] COMMAND [ARGS]...
clear#

Delete all sessions.

Usage

app sessions clear [OPTIONS]
delete#

Delete a specific session.

Usage

app sessions delete [OPTIONS] SESSION_ID

Arguments

SESSION_ID#

Required argument

version#

Show the currently installed Litestar version.

Usage

app version [OPTIONS]

Options

-s, --short#

Exclude release level and serial information

Database CLI#

app database#

Manage SQLAlchemy database components.

Usage

app database [OPTIONS] COMMAND [ARGS]...
branches#

Show current branch points in the migration history

Usage

app database branches [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--verbose#

Enable verbose output.

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

check#

Check if the target database is up to date

Usage

app database check [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

downgrade#

Downgrade database to a specific revision.

Usage

app database downgrade [OPTIONS] [REVISION]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--sql#

Generate SQL output for offline migrations.

--tag <tag>#

an arbitrary ‘tag’ that can be intercepted by custom env.py scripts via the .EnvironmentContext.get_tag_argument method.

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Arguments

REVISION#

Optional argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

drop-all#

Drop all tables from the database.

Usage

app database drop-all [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

dump-data#

Dump specified tables from the database to fixture files.

Usage

app database dump-data [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--table <table_names>#

Required Name of the table to dump. Multiple tables can be specified. Use ‘*’ to dump all tables.

--dir <dump_dir>#

Directory to save the fixture files. Defaults to WORKDIR/fixtures

--format <file_format>#

Fixture file format.

Default:

'json'

Options:

json | jsonl | csv

--compression <compression>#

Compression applied to each fixture file.

Default:

'none'

Options:

none | gzip | zip

--max-file-size <max_file_size>#

Start a new numbered shard before a file would exceed this on-disk size, in bytes or with a K, M, or G suffix (1024-based), for example 50M.

--max-records <max_records>#

Start a new numbered shard after this many records.

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

edit#

Edit a revision file using $EDITOR

Usage

app database edit [OPTIONS] REVISION

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

Arguments

REVISION#

Required argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

ensure-version#

Create the alembic version table if it doesn’t exist

Usage

app database ensure-version [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--sql#

Generate SQL output instead of executing

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

heads#

Show current available heads in the script directory

Usage

app database heads [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--verbose#

Enable verbose output.

--resolve-dependencies#

Resolve dependencies between heads

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

history#

List changeset scripts in chronological order

Usage

app database history [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--verbose#

Enable verbose output.

--rev-range <rev_range>#

Revision range (e.g., ‘base:head’, ‘abc:def’)

--indicate-current#

Indicate the current revision

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

init#

Initialize migrations for the project.

Usage

app database init [OPTIONS] [DIRECTORY]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--multidb#

Support multiple databases

--package#

Create __init__.py for created folder

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Arguments

DIRECTORY#

Optional argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

list-templates#

List available Alembic migration templates

Usage

app database list-templates [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

make-migrations#

Create a new migration revision.

Usage

app database make-migrations [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

-m, --message <message>#

Revision message

--autogenerate, --no-autogenerate#

Automatically populate revision with detected changes

--sql#

Export to .sql instead of writing to the database.

--head <head>#

Specify head revision to use as base for new revision.

--splice#

Allow a non-head revision as the “head” to splice onto

--branch-label <branch_label>#

Specify a branch label to apply to the new revision

--version-path <version_path>#

Specify specific path from config for version file

--rev-id <rev_id>#

Specify a ID to use for revision.

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

merge#

Merge two revisions together, creating a new migration file

Usage

app database merge [OPTIONS] REVISIONS

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

-m, --message <message>#

Merge message

--branch-label <branch_label>#

Branch label for merge revision

--rev-id <rev_id>#

Specify custom revision ID

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Arguments

REVISIONS#

Required argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

show#

Show the revision denoted by the given symbol

Usage

app database show [OPTIONS] REVISION

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

Arguments

REVISION#

Required argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

show-config#

Show all configurations with migrations enabled.

Usage

app database show-config [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

show-current-revision#

Shows the current revision for the database.

Usage

app database show-current-revision [OPTIONS]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--verbose#

Enable verbose output.

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

stamp#

Stamp the revision table with the given revision; don’t run any migrations

Usage

app database stamp [OPTIONS] REVISION

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--sql#

Generate SQL output for offline migrations

--tag <tag>#

Arbitrary ‘tag’ that can be intercepted by custom env.py scripts

--purge#

Delete all entries in version table before stamping

Arguments

REVISION#

Required argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

upgrade#

Upgrade database to a specific revision.

Usage

app database upgrade [OPTIONS] [REVISION]

Options

-c, --config <config>#

Dotted or colon path to SQLAlchemy config(s) or factory callable (env: ALCHEMY_CONFIG)

--validate-config#

Validate configuration before executing migrations

--bind-key <bind_key>#

Specify which SQLAlchemy config to use by bind key

--sql#

Generate SQL output for offline migrations.

--tag <tag>#

an arbitrary ‘tag’ that can be intercepted by custom env.py scripts via the .EnvironmentContext.get_tag_argument method.

--no-prompt#

Do not prompt for confirmation before executing the command.

Default:

False

Arguments

REVISION#

Optional argument

Environment variables

ALCHEMY_CONFIG

Provide a default for --config

User management CLI#

app user#

Manage application users and roles.

Usage

app user [OPTIONS] COMMAND [ARGS]...
create-roles#

Create pre-configured application roles and assign to users.

Usage

app user create-roles [OPTIONS]
create-user#

Create a user

Usage

app user create-user [OPTIONS]

Options

--email <email>#

Email of the new user

--name <name>#

Full name of the new user

--password <password>#

Password

--superuser#

Is a superuser

promote-to-superuser#

Promotes a user to application superuser

Usage

app user promote-to-superuser [OPTIONS]

Options

--email <email>#

Required Email of the user