From 37e29f110992f741a567397df8af04a8f1d0e7a4 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 28 Aug 2024 10:33:46 -0500 Subject: [PATCH] Update FastAPI guide for virtual projects and use `uv init` to create the `pyproject.toml` (#6752) Follows https://github.com/astral-sh/uv/pull/6751 Matches https://github.com/astral-sh/uv-fastapi-example/pull/3 --- docs/guides/integration/fastapi.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/guides/integration/fastapi.md b/docs/guides/integration/fastapi.md index 6b84dddb7..a18d1d74a 100644 --- a/docs/guides/integration/fastapi.md +++ b/docs/guides/integration/fastapi.md @@ -27,8 +27,20 @@ follows: │ └── admin.py ``` -To migrate this project to uv, add a `pyproject.toml` file to the root directory of the project, as -a sibling to the `app` directory. +To migrate this project to uv, add a `pyproject.toml` file to the root directory of the project with +`uv init`: + +```console +$ uv init +$ uv add fastapi --extra standard +``` + +!!! tip + + If you have an existing `pyproject.toml`, `uv init` cannot be used — but you may not need to + make any changes to the file. + +You should now have the following structure: ```plaintext . @@ -46,11 +58,11 @@ a sibling to the `app` directory. │ └── admin.py ``` -The contents of the `pyproject.toml` file should look something like this: +And the contents of the `pyproject.toml` file should look something like this: ```toml title="pyproject.toml" [project] -name = "app" +name = "uv-fastapi-example" version = "0.1.0" description = "FastAPI project" readme = "README.md" @@ -63,7 +75,7 @@ dependencies = [ From there, you can run the FastAPI application with: ```console -$ uv run fastapi dev app/main.py +$ uv run fastapi dev ``` `uv run` will automatically resolve and lock the project dependencies (i.e., create a `uv.lock`