cli#

Command line interface for the application.

Litestar CLI#

app#

Litestar CLI.

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.

app info [OPTIONS]

routes#

Display information about the application’s routes.

app routes [OPTIONS]

Options

--schema#

Include schema routes

--exclude <exclude>#

routes to exclude via regex

run#

Run a Litestar app; requires uvicorn.

The app can be either passed as a module path in the form of <module name>.<submodule>:<app instance or factory>, set as an environment variable LITESTAR_APP with the same format or automatically discovered from one of these canonical paths: app.py, asgi.py, application.py or app/__init__.py. When auto-discovering application factories, functions with the name create_app are considered, or functions that are annotated as returning a Litestar instance.

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.

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

Generate an OpenAPI Schema.

app schema openapi [OPTIONS]

Options

--output <output>#

output file path

Default:

PosixPath('openapi_schema.json')

typescript#

Generate TypeScript specs from the OpenAPI schema.

app schema typescript [OPTIONS]

Options

--output <output>#

output file path

Default:

PosixPath('api-specs.ts')

--namespace <namespace>#

namespace to use for the typescript specs

sessions#

Manage server-side sessions.

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

Delete all sessions.

app sessions clear [OPTIONS]
delete#

Delete a specific session.

app sessions delete [OPTIONS] SESSION_ID

Arguments

SESSION_ID#

Required argument

version#

Show the currently installed Litestar version.

app version [OPTIONS]

Options

-s, --short#

Exclude release level and serial information

Database CLI#

app database#

Manage SQLAlchemy database components.

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

Downgrade database to a specific revision.

app database downgrade [OPTIONS] [REVISION]

Options

--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 downgrading.

Default:

False

Arguments

REVISION#

Optional argument

drop-all#

Drop all tables from the database.

app database drop-all [OPTIONS]

Options

--no-prompt#

Do not prompt for confirmation before upgrading.

Default:

False

init#

Initialize migrations for the project.

app database init [OPTIONS] DIRECTORY

Options

--multidb#

Support multiple databases

--package#

Create __init__.py for created folder

--no-prompt#

Do not prompt for confirmation before initializing.

Default:

False

Arguments

DIRECTORY#

Required argument

make-migrations#

Create a new migration revision.

app database make-migrations [OPTIONS]

Options

-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 a migration message.

Default:

False

merge-migrations#

Merge multiple revisions into a single new revision.

app database merge-migrations [OPTIONS]

Options

--revisions <revisions>#

Specify head revision to use as base for new revision.

-m, --message <message>#

Revision message

--branch-label <branch_label>#

Specify a branch label to apply to the new revision

--rev-id <rev_id>#

Specify a ID to use for revision.

--no-prompt#

Do not prompt for a migration message.

Default:

False

show-current-revision#

Shows the current revision for the database.

app database show-current-revision [OPTIONS]

Options

--verbose#

Enable verbose output.

stamp-migration#

Mark (Stamp) a specific revision as current without applying the migrations.

app database stamp-migration [OPTIONS]

Options

--revision <revision>#

Revision to stamp to

--sql#

Generate SQL output for offline migrations.

--purge#

Delete existing records in the alembic version table before stamping.

--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.

Default:

False

upgrade#

Upgrade database to a specific revision.

app database upgrade [OPTIONS] [REVISION]

Options

--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 upgrading.

Default:

False

Arguments

REVISION#

Optional argument