Flama CLIRun
Flama CLI~ 3 min read

Run

Flama CLI

We have already seen how to use the command line to run an app in the Quickstart, but we didn't do a proper introduction of the command line interface (CLI). Flama CLI is a convenient tool which is installed automatically with the package, and reduces the hurdles of serving your app.

Once you have a developed app that you want to serve, you need to choose and configure a web server, e.g. gunicorn or uvicorn, and that eventually becomes a repetitive task.

Flama CLI precisely aims at reducing the effort invested in this step to the bare minimum, so that you can focus on developing your app.

Parameters

App path

To be able to serve an app, you need to have a file where you have the following lines:

from flama import Flama
app = Flama()
...

As we did in the Quickstart, let's assume that the file containing these lines is main.py, which is located at:

project_folder/└── src    └── main.py        └── app

For Flama to be able to run the app, it needs to know the exact path to the app variable. The path can be passed directly to the CLI as argument, or by utilising the equivalent environment variable FLAMA_APP. Thus, if we are at project_folder (following the previous example of folder structure), we can run the app by either of the following two ways:

Using option argument

flama run src.main:app
INFO: Started server process [3267]INFO: Waiting for application startup.INFO: Application startup complete.INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

Using environment variable

export FLAMA_APP=src.main:appflama run
INFO: Started server process [3267]INFO: Waiting for application startup.INFO: Application startup complete.INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

Server parameters

Flama CLI uses uvicorn as webserver, and it is because of this that it accepts every argument of the uvicorn CLI:

flama run --help
Usage: flama run [OPTIONS] FLAMA_APP Run a Flama Application based on a route.
<FLAMA_APP> is the route to the Flama object to be served, e.g. 'examples.hello_flama:app'. This can be passed directly as argument of the command line, or by environment variable.╭─ Options ────────────────────────────────────────────────────────────────────╮│ --server-host TEXT ││ --server-port INTEGER ││ --server-reload ││ --server-uds TEXT ││ --server-fd INTEGER ││ --server-reload-dirs PATH ││ --server-reload-includes TEXT ││ --server-reload-excludes TEXT ││ --server-reload-delay FLOAT ││ --server-workers INTEGER ││ --server-loop ││ --server-http ││ --server-ws ││ --server-ws-max-size INTEGER ││ --server-ws-ping-interval FLOAT ││ --server-ws-ping-timeout FLOAT ││ --server-ws-per-message-deflate BOOLEAN ││ --server-lifespan ││ --server-interface ││ --server-env-file PATH ││ --server-log-config PATH ││ --server-log-level ││ --server-access-log / --server-no-access-log ││ --server-use-colors / --server-no-use-colors ││ --server-proxy-headers / --server-no-proxy-headers ││ --server-server-header / --server-no-server-header ││ --server-date-header / --server-no-date-header ││ --server-forwarded-allow-ips TEXT ││ --server-root-path TEXT ││ --server-limit-concurrency INTEGER ││ --server-backlog INTEGER ││ --server-limit-max-requests INTEGER ││ --server-timeout-keep-alive INTEGER ││ --server-ssl-keyfile TEXT ││ --server-ssl-certfile TEXT ││ --server-ssl-keyfile-password TEXT ││ --server-ssl-version INTEGER ││ --server-ssl-cert-reqs INTEGER ││ --server-ssl-ca-certs TEXT ││ --server-ssl-ciphers TEXT ││ --server-headers TEXT ││ --server-app-dir TEXT ││ --server-h11-max-incomplete-event-size INTEGER ││ --server-factory ││ --help │╰──────────────────────────────────────────────────────────────────────────────╯

For the exhaustive list of arguments you can pass, and their usage, we recommend you to check here.