Skip to content

Conversation

@skupr-anaconda
Copy link

This statement in the docs https://fastapi.tiangolo.com/fastapi-cli/?h=fastapi+cli#fastapi-cli says:
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.

Which means that you can run the command fastapi after installing fastapi-cli itself. The same applies to this section https://github.com/fastapi/fastapi-cli/tree/0.0.20?tab=readme-ov-file#description.

I guess it's not designed to run without the fastapi package, but the code itself has pydantic, which is not mentioned as a runtime dependency.

pydantic is a missing runtime dependency and is not mentioned here https://github.com/fastapi/fastapi-cli/blob/0.0.20/pyproject.toml#L34-L39, but it's used at runtime here https://github.com/fastapi/fastapi-cli/blob/0.0.20/src/fastapi_cli/cli.py#L6 and here https://github.com/fastapi/fastapi-cli/blob/0.0.20/src/fastapi_cli/config.py#L5.

This line of the fastapi code https://github.com/fastapi/fastapi/blob/master/fastapi/cli.py#L2 says that it directly relies on fastapi_cli.

Basically, an entry point fastapi = fastapi_cli.cli:main belongs to the fastapi-cli package.

Operating System Details

unix and win platforms

Python Version

py310-py314

Additional Context

If I run fastapi --help or fastapi --version without pydantic >=2.0.0 in the test environment, I get:

TEST START: /Users/skupr/opt/miniconda3/conda-bld/osx-arm64/fastapi-cli-0.0.20-py314hca03da5_0.conda
Adding in variants from /var/folders/q7/279tg2zx0ss6phrmz7vnww6w0000gp/T/tmpxgu5m6ov/info/recipe/conda_build_config.yaml
Renaming /Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/_build_env prefix directory '/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/_build_env' to '/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/build_prefix_moved_fastapi-cli-0.0.20-py314hca03da5_0_osx-arm64'
shutil.move(/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/_build_env prefix)=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/_build_env, dest=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/build_prefix_moved_fastapi-cli-0.0.20-py314hca03da5_0_osx-arm64)
Renaming work directory '/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/work' to '/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/work_moved_fastapi-cli-0.0.20-py314hca03da5_0_osx-arm64'
shutil.move(work)=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/work, dest=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/work_moved_fastapi-cli-0.0.20-py314hca03da5_0_osx-arm64)
Reloading output folder: ...working... done
Solving environment (_test_env): ...working... done

## Package Plan ##

  environment location: /Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold


The following NEW packages will be INSTALLED:

    anyio:               4.10.0-py314hca03da5_0
    bzip2:               1.0.8-h80987f9_6
    ca-certificates:     2025.12.2-hca03da5_0
    click:               8.2.1-py314hca03da5_1
    fastapi-cli:         0.0.20-py314hca03da5_0    local
    h11:                 0.16.0-py314hca03da5_1
    httptools:           0.7.1-py314haa24f5a_0
    idna:                3.11-py314hca03da5_0
    iniconfig:           2.3.0-py314hca03da5_0
    libcxx:              20.1.8-hd7fd590_1
    libexpat:            2.7.3-h50f4ffc_4
    libffi:              3.4.4-hca03da5_1
    libmpdec:            4.0.0-h80987f9_0
    libuv:               1.48.0-h80987f9_0
    libzlib:             1.3.1-h5f15de7_0
    lz4-c:               1.9.4-h313beb8_1
    markdown-it-py:      4.0.0-py314hca03da5_1
    mdurl:               0.1.2-py314hca03da5_0
    ncurses:             6.5-hee39554_0
    openssl:             3.0.18-h9b4081a_0
    packaging:           25.0-py314hca03da5_1
    pip:                 25.3-pyh0d26453_0
    pluggy:              1.5.0-py314hca03da5_0
    pygments:            2.19.2-py314hca03da5_0
    pytest:              8.4.2-py314hca03da5_0
    python:              3.14.2-h1858270_101_cp314
    python-dotenv:       1.1.0-py314hca03da5_0
    python_abi:          3.14-2_cp314
    pyyaml:              6.0.3-py314h091b9d3_0
    readline:            8.3-h0b18652_0
    rich:                14.2.0-py314hca03da5_0
    rich-toolkit:        0.17.1-py314hca03da5_0    local
    shellingham:         1.5.4-py314hca03da5_0
    sniffio:             1.3.1-py314hca03da5_0
    sqlite:              3.51.1-hab6afd1_0
    tk:                  8.6.15-hcd8a7d5_0
    typer:               0.20.0-py314hca03da5_0
    typer-slim:          0.20.0-py314hca03da5_0
    typer-slim-standard: 0.20.0-py314hca03da5_0
    typing_extensions:   4.15.0-py314hca03da5_0
    tzdata:              2025b-h04d1e81_0
    uvicorn:             0.40.0-py314hca03da5_0    local
    uvicorn-standard:    0.40.0-py314hca03da5_0    local
    uvloop:              0.22.1-py314h8e34c70_1
    watchfiles:          1.1.1-py314h931abed_1
    websockets:          15.0.1-py314h75312c3_0
    xz:                  5.6.4-h80987f9_1
    yaml:                0.2.5-h1a28f6b_0
    zlib:                1.3.1-h5f15de7_0
    zstd:                1.5.7-h817c040_0

Preparing transaction: ...working... done
Verifying transaction: ...working...

done
export PREFIX=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold
export SRC_DIR=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/test_tmp
import: 'fastapi_cli'
import: 'fastapi_cli'
+ pip check
No broken requirements found.
+ fastapi --help
Traceback (most recent call last):
  File "/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold/bin/fastapi", line 7, in <module>
    from fastapi_cli.cli import main
  File "/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768227686608/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold/lib/python3.14/site-packages/fastapi_cli/cli.py", line 6, in <module>
    from pydantic import ValidationError
ModuleNotFoundError: No module named 'pydantic'
WARNING: Tests failed for fastapi-cli-0.0.20-py314hca03da5_0.conda - moving package to /Users/skupr/opt/miniconda3/conda-bld/broken

CondaBuildUserError: TESTS FAILED: fastapi-cli-0.0.20-py314hca03da5_0.conda

But if I add pydantic to the runtime dependencies, it works fine:

TEST START: /Users/skupr/opt/miniconda3/conda-bld/osx-arm64/fastapi-cli-0.0.20-py314hca03da5_0.conda
Adding in variants from /var/folders/q7/279tg2zx0ss6phrmz7vnww6w0000gp/T/tmpdvbz39b_/info/recipe/conda_build_config.yaml
Renaming /Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/_build_env prefix directory '/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/_build_env' to '/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/build_prefix_moved_fastapi-cli-0.0.20-py314hca03da5_0_osx-arm64'
shutil.move(/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/_build_env prefix)=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/_build_env, dest=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/build_prefix_moved_fastapi-cli-0.0.20-py314hca03da5_0_osx-arm64)
Renaming work directory '/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/work' to '/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/work_moved_fastapi-cli-0.0.20-py314hca03da5_0_osx-arm64'
shutil.move(work)=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/work, dest=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/work_moved_fastapi-cli-0.0.20-py314hca03da5_0_osx-arm64)
Reloading output folder: ...working... done
Solving environment (_test_env): ...working... done

## Package Plan ##

  environment location: /Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold


The following NEW packages will be INSTALLED:

    annotated-types:     0.6.0-py314hca03da5_1
    anyio:               4.10.0-py314hca03da5_0
    bzip2:               1.0.8-h80987f9_6
    ca-certificates:     2025.12.2-hca03da5_0
    click:               8.2.1-py314hca03da5_1
    fastapi-cli:         0.0.20-py314hca03da5_0    local
    h11:                 0.16.0-py314hca03da5_1
    httptools:           0.7.1-py314haa24f5a_0
    idna:                3.11-py314hca03da5_0
    iniconfig:           2.3.0-py314hca03da5_0
    libcxx:              20.1.8-hd7fd590_1
    libexpat:            2.7.3-h50f4ffc_4
    libffi:              3.4.4-hca03da5_1
    libmpdec:            4.0.0-h80987f9_0
    libuv:               1.48.0-h80987f9_0
    libzlib:             1.3.1-h5f15de7_0
    lz4-c:               1.9.4-h313beb8_1
    markdown-it-py:      4.0.0-py314hca03da5_1
    mdurl:               0.1.2-py314hca03da5_0
    ncurses:             6.5-hee39554_0
    openssl:             3.0.18-h9b4081a_0
    packaging:           25.0-py314hca03da5_1
    pip:                 25.3-pyh0d26453_0
    pluggy:              1.5.0-py314hca03da5_0
    pydantic:            2.12.4-py314hca03da5_0
    pydantic-core:       2.41.5-py314h931abed_1
    pygments:            2.19.2-py314hca03da5_0
    pytest:              8.4.2-py314hca03da5_0
    python:              3.14.2-h1858270_101_cp314
    python-dotenv:       1.1.0-py314hca03da5_0
    python_abi:          3.14-2_cp314
    pyyaml:              6.0.3-py314h091b9d3_0
    readline:            8.3-h0b18652_0
    rich:                14.2.0-py314hca03da5_0
    rich-toolkit:        0.17.1-py314hca03da5_0    local
    shellingham:         1.5.4-py314hca03da5_0
    sniffio:             1.3.1-py314hca03da5_0
    sqlite:              3.51.1-hab6afd1_0
    tk:                  8.6.15-hcd8a7d5_0
    typer:               0.20.0-py314hca03da5_0
    typer-slim:          0.20.0-py314hca03da5_0
    typer-slim-standard: 0.20.0-py314hca03da5_0
    typing-extensions:   4.15.0-py314hca03da5_0
    typing-inspection:   0.4.2-py314hca03da5_0
    typing_extensions:   4.15.0-py314hca03da5_0
    tzdata:              2025b-h04d1e81_0
    uvicorn:             0.40.0-py314hca03da5_0    local
    uvicorn-standard:    0.40.0-py314hca03da5_0    local
    uvloop:              0.22.1-py314h8e34c70_1
    watchfiles:          1.1.1-py314h108b7f8_1     local
    websockets:          15.0.1-py314h75312c3_0
    xz:                  5.6.4-h80987f9_1
    yaml:                0.2.5-h1a28f6b_0
    zlib:                1.3.1-h5f15de7_0
    zstd:                1.5.7-h817c040_0

Preparing transaction: ...working... done
Verifying transaction: ...working...

done
export PREFIX=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold
export SRC_DIR=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/test_tmp
import: 'fastapi_cli'
import: 'fastapi_cli'
+ pip check
No broken requirements found.
+ fastapi --help

 Usage: fastapi [OPTIONS] COMMAND [ARGS]...

 FastAPI CLI - The fastapi command line app. 😎

 Manage your FastAPI projects, run your FastAPI apps, and more.

 Read more in the docs: https://fastapi.tiangolo.com/fastapi-cli/.

╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --version                                   Show the version and exit.                                         │
│ --verbose                 --no-verbose      Enable verbose output [default: no-verbose]                        │
│ --install-completion                        Install completion for the current shell.                          │
│ --show-completion                           Show completion for the current shell, to copy it or customize the │
│                                             installation.                                                      │
│ --help                -h                    Show this message and exit.                                        │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ dev   Run a FastAPI app in development mode. 🧪                                                                │
│ run   Run a FastAPI app in production mode. 🚀                                                                 │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

+ fastapi --version
FastAPI CLI version: 0.0.20
+ fastapi dev --help

 Usage: fastapi dev [OPTIONS] [PATH]

 Run a FastAPI app in development mode. 🧪

 This is equivalent to fastapi run but with reload enabled and listening on the 127.0.0.1 address.

 It automatically detects the Python module or package that needs to be imported based on the file or directory
 path passed.

 If no path is passed, it tries with:

 - main.py
 - app.py
 - api.py
 - app/main.py
 - app/app.py
 - app/api.py

 It also detects the directory that needs to be added to the PYTHONPATH to make the app importable and adds it.

 It detects the FastAPI app object to use. By default it looks in the module or package for an object named:

 - app
 - api

 Otherwise, it uses the first FastAPI app found in the imported module or package.

╭─ Arguments ────────────────────────────────────────────────────────────────────────────────────────────────────╮
│   path      [PATH]  A path to a Python file or package directory (with __init__.py files) containing a FastAPI │
│                     app. If not provided, a default set of paths will be tried.                                │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --host                                           TEXT     The host to serve on. For local development in       │
│                                                           localhost use 127.0.0.1. To enable public access,    │
│                                                           e.g. in a container, use all the IP addresses        │
│                                                           available with 0.0.0.0.                              │
│                                                           [default: 127.0.0.1]                                 │
│ --port                                           INTEGER  The port to serve on. You would normally have a      │
│                                                           termination proxy on top (another program) handling  │
│                                                           HTTPS on port 443 and HTTP on port 80, transferring  │
│                                                           the communication to your app.                       │
│                                                           [env var: PORT]                                      │
│                                                           [default: 8000]                                      │
│ --reload                   --no-reload                    Enable auto-reload of the server when (code) files   │
│                                                           change. This is resource intensive, use it only      │
│                                                           during development.                                  │
│                                                           [default: reload]                                    │
│ --reload-dir                                     PATH     Set reload directories explicitly, instead of using  │
│                                                           the current working directory.                       │
│ --root-path                                      TEXT     The root path is used to tell your app that it is    │
│                                                           being served to the outside world with some path     │
│                                                           prefix set up in some termination proxy or similar.  │
│ --app                                            TEXT     The name of the variable that contains the FastAPI   │
│                                                           app in the imported module or package. If not        │
│                                                           provided, it is detected automatically.              │
│ --entrypoint           -e                        TEXT     The FastAPI app import string in the format          │
│                                                           'some.importable_module:app_name'.                   │
│ --proxy-headers            --no-proxy-headers             Enable/Disable X-Forwarded-Proto, X-Forwarded-For,   │
│                                                           X-Forwarded-Port to populate remote address info.    │
│                                                           [default: proxy-headers]                             │
│ --forwarded-allow-ips                            TEXT     Comma separated list of IP Addresses to trust with   │
│                                                           proxy headers. The literal '*' means trust           │
│                                                           everything.                                          │
│ --help                 -h                                 Show this message and exit.                          │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

+ fastapi run --help

 Usage: fastapi run [OPTIONS] [PATH]

 Run a FastAPI app in production mode. 🚀

 This is equivalent to fastapi dev but with reload disabled and listening on the 0.0.0.0 address.

 It automatically detects the Python module or package that needs to be imported based on the file or directory
 path passed.

 If no path is passed, it tries with:

 - main.py
 - app.py
 - api.py
 - app/main.py
 - app/app.py
 - app/api.py

 It also detects the directory that needs to be added to the PYTHONPATH to make the app importable and adds it.

 It detects the FastAPI app object to use. By default it looks in the module or package for an object named:

 - app
 - api

 Otherwise, it uses the first FastAPI app found in the imported module or package.

╭─ Arguments ────────────────────────────────────────────────────────────────────────────────────────────────────╮
│   path      [PATH]  A path to a Python file or package directory (with __init__.py files) containing a FastAPI │
│                     app. If not provided, a default set of paths will be tried.                                │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --host                                           TEXT     The host to serve on. For local development in       │
│                                                           localhost use 127.0.0.1. To enable public access,    │
│                                                           e.g. in a container, use all the IP addresses        │
│                                                           available with 0.0.0.0.                              │
│                                                           [default: 0.0.0.0]                                   │
│ --port                                           INTEGER  The port to serve on. You would normally have a      │
│                                                           termination proxy on top (another program) handling  │
│                                                           HTTPS on port 443 and HTTP on port 80, transferring  │
│                                                           the communication to your app.                       │
│                                                           [env var: PORT]                                      │
│                                                           [default: 8000]                                      │
│ --reload                   --no-reload                    Enable auto-reload of the server when (code) files   │
│                                                           change. This is resource intensive, use it only      │
│                                                           during development.                                  │
│                                                           [default: no-reload]                                 │
│ --workers                                        INTEGER  Use multiple worker processes. Mutually exclusive    │
│                                                           with the --reload flag.                              │
│ --root-path                                      TEXT     The root path is used to tell your app that it is    │
│                                                           being served to the outside world with some path     │
│                                                           prefix set up in some termination proxy or similar.  │
│ --app                                            TEXT     The name of the variable that contains the FastAPI   │
│                                                           app in the imported module or package. If not        │
│                                                           provided, it is detected automatically.              │
│ --entrypoint           -e                        TEXT     The FastAPI app import string in the format          │
│                                                           'some.importable_module:app_name'.                   │
│ --proxy-headers            --no-proxy-headers             Enable/Disable X-Forwarded-Proto, X-Forwarded-For,   │
│                                                           X-Forwarded-Port to populate remote address info.    │
│                                                           [default: proxy-headers]                             │
│ --forwarded-allow-ips                            TEXT     Comma separated list of IP Addresses to trust with   │
│                                                           proxy headers. The literal '*' means trust           │
│                                                           everything.                                          │
│ --help                 -h                                 Show this message and exit.                          │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

+ exit 0

Resource usage statistics from testing fastapi-cli:
   Process count: 4
   CPU time: Sys=0:00:00.0, User=0:00:00.0
   Memory: 18.6M
   Disk usage: 40B
   Time elapsed: 0:00:04.1


TEST END: /Users/skupr/opt/miniconda3/conda-bld/osx-arm64/fastapi-cli-0.0.20-py314hca03da5_0.conda
Renaming work directory '/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/work' to '/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/work_moved_fastapi-cli-0.0.20-py314hca03da5_0_osx-arm64_main_build_loop'
shutil.move(work)=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/work, dest=/Users/skupr/opt/miniconda3/conda-bld/fastapi-cli_1768229511632/work_moved_fastapi-cli-0.0.20-py314hca03da5_0_osx-arm64_main_build_loop)
# Automatic uploading is disabled
# If you want to upload package(s) to anaconda.org later, type:


# To have conda build upload to anaconda.org automatically, use
# conda config --set anaconda_upload yes
anaconda upload \
    /Users/skupr/opt/miniconda3/conda-bld/osx-arm64/fastapi-cli-0.0.20-py314hca03da5_0.conda
anaconda_upload is not set.  Not uploading wheels: []

INFO :: The inputs making up the hashes for the built packages are as follows:
{
  "fastapi-cli-0.0.20-py314hca03da5_0.conda": {
    "recipe": {
      "channel_targets": "defaults",
      "target_platform": "osx-arm64"
    }
  }
}


####################################################################################
Resource usage summary:

Total time: 0:00:36.3
CPU usage: sys=0:00:00.1, user=0:00:00.2
Maximum memory usage observed: 84.2M
Total disk usage observed (not including envs): 720B


Additionally, I sorted dependencies alphabetically for readability and maintenance.

Also, see the conda-build recipe of fastapi-cli 0.0.20 https://github.com/AnacondaRecipes/fastapi-cli-feedstock/blob/main/recipe/meta.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant