Skip to main content

Run and manage FastAPI apps from the command line with FastAPI CLI. ๐Ÿš€

Project description

FastAPI CLI

Test Publish Coverage Package version

Source Code: https://github.com/tiangolo/fastapi-cli


Run and manage FastAPI apps from the command line with FastAPI CLI. ๐Ÿš€

Description

FastAPI CLI is a command line program fastapi that you can use to serve your FastAPI app, manage your FastAPI project, and more.

When you install FastAPI (e.g. with pip install fastapi), it includes a package called fastapi-cli, this package provides the fastapi command in the terminal.

To run your FastAPI app for development, you can use the fastapi dev command:

$ fastapi dev main.py
INFO     Using path main.py
INFO     Resolved absolute path /home/user/code/awesomeapp/main.py
INFO     Searching for package file structure from directories with __init__.py files
INFO     Importing from /home/user/code/awesomeapp

 โ•ญโ”€ Python module file โ”€โ•ฎ
 โ”‚                      โ”‚
 โ”‚  ๐Ÿ main.py          โ”‚
 โ”‚                      โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

INFO     Importing module main
INFO     Found importable FastAPI app

 โ•ญโ”€ Importable FastAPI app โ”€โ•ฎ
 โ”‚                          โ”‚
 โ”‚  from main import app    โ”‚
 โ”‚                          โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

INFO     Using import string main:app

 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ FastAPI CLI - Development mode โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚                                                     โ”‚
 โ”‚  Serving at: http://127.0.0.1:8000                  โ”‚
 โ”‚                                                     โ”‚
 โ”‚  API docs: http://127.0.0.1:8000/docs               โ”‚
 โ”‚                                                     โ”‚
 โ”‚  Running in development mode, for production use:   โ”‚
 โ”‚                                                     โ”‚
 โ”‚  fastapi run                                        โ”‚
 โ”‚                                                     โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

INFO:     Will watch for changes in these directories: ['/home/user/code/awesomeapp']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [56345] using WatchFiles
INFO:     Started server process [56352]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

That command line program called fastapi is FastAPI CLI.

FastAPI CLI takes the path to your Python program and automatically detects the variable with the FastAPI (commonly named app) and how to import it, and then serves it.

For production you would use fastapi run instead. ๐Ÿš€

fastapi dev

When you run fastapi dev, it will run on development mode.

By default, it will have auto-reload enabled, so it will automatically reload the server when you make changes to your code. This is resource intensive and could be less stable than without it, you should only use it for development.

By default it will listen on the IP address 127.0.0.1, which is the IP for your machine to communicate with itself alone (localhost).

fastapi run

When you run fastapi run, it will run on production mode by default.

It will have auto-reload disabled by default.

It will listen on the IP address 0.0.0.0, which means all the available IP addresses, this way it will be publicly accessible to anyone that can communicate with the machine. This is how you would normally run it in production, for example, in a container.

In most cases you would (and should) have a "termination proxy" handling HTTPS for you on top, this will depend on how you deploy your application, your provider might do this for you, or you might need to set it up yourself. You can learn more about it in the FastAPI Deployment documentation.

License

This project is licensed under the terms of the MIT license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_cli-0.0.2.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

fastapi_cli-0.0.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_cli-0.0.2.tar.gz.

File metadata

  • Download URL: fastapi_cli-0.0.2.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.9

File hashes

Hashes for fastapi_cli-0.0.2.tar.gz
Algorithm Hash digest
SHA256 589565ba758432632eadcf7b950e0ec76bb283b549784d9df17f261a8a9de476
MD5 c947e5eb2cf04908032ad7489295f8b6
BLAKE2b-256 391a132f46e6a7122970a102fca6f71baa3b574be1ecac0f6888c68e6625fa33

See more details on using hashes here.

Provenance

File details

Details for the file fastapi_cli-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: fastapi_cli-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.9

File hashes

Hashes for fastapi_cli-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d7a8ec89fd52ad16c52de9fe7299e4b22c7a32e1bf28aa886e5517e4927423dd
MD5 9726158844101223e25d37783fe108a3
BLAKE2b-256 fd2fc43116ad92f8310960e22b0789efbf10015c5a3c8bcbae03beb861bfa006

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page