Run and manage FastAPI apps from the command line with FastAPI CLI. ๐
Project description
FastAPI CLI
Source Code: https://github.com/fastapi/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[standard]"
), 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. ๐
Internally, FastAPI CLI uses Uvicorn, a high-performance, production-ready, ASGI server. ๐
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fastapi_cli_slim-0.0.5.tar.gz
.
File metadata
- Download URL: fastapi_cli_slim-0.0.5.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2719d1237219234501f5ed6de25464f32cbc0d8f05d364a13488bd7e02c07e8e |
|
MD5 | 3e1f2b6c36354bedc0346185588d471b |
|
BLAKE2b-256 | c48e33c929c281c28e7a77fdd1bdb8d8830e836b3ddb48e360e1c7f51c087dac |
File details
Details for the file fastapi_cli_slim-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: fastapi_cli_slim-0.0.5-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1b763625fcfb8c957acd87c47d0e8967733df8ae1cca9333427fbf4c756b538 |
|
MD5 | 8913bd58fe4efcb0ff3a822683cbf2ab |
|
BLAKE2b-256 | 609b9c1a6ff9c6f4275436d2a1dad86f3f117974790c6d8e73cb32396fafb7ba |