From 1b97bba3826be31ef808d5dd7e059d1f14c7d8e7 Mon Sep 17 00:00:00 2001 From: Kristin Martin Date: Fri, 12 Dec 2025 14:23:41 -0800 Subject: [PATCH 1/3] update run fastapi and initial python setup docs per issue 2008 --- python/frameworks/fastapi.html.markerb | 7 ----- python/partials/_poetry_new.erb | 35 +++++++++++++++++++++++-- python/the-basics/initial-setup.html.md | 8 +++--- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/python/frameworks/fastapi.html.markerb b/python/frameworks/fastapi.html.markerb index 42ed61848b..f15eb4f70e 100644 --- a/python/frameworks/fastapi.html.markerb +++ b/python/frameworks/fastapi.html.markerb @@ -24,13 +24,6 @@ Deploying a FastAPI app on Fly.io is... well it's fast! You can be up and runnin <%= partial "/docs/python/partials/poetry_new", locals: { runtime: "FastAPI" } %> - -Then we have to add the FastAPI dependency: - -```cmd -poetry add "fastapi[standard]" -``` - Now, let's create a simple FastAPI app in `main.py`: ```python diff --git a/python/partials/_poetry_new.erb b/python/partials/_poetry_new.erb index 8e8a7cdb96..ae805bc369 100644 --- a/python/partials/_poetry_new.erb +++ b/python/partials/_poetry_new.erb @@ -1,9 +1,40 @@ For managing our project, we use [Poetry](https://python-poetry.org/). For more information on the initial setup with poetry, refer to [setting up a python environment](/docs/python/the-basics/initial-setup). -We can initialize a new project like so: +**Note:** If you're using Poetry 2.0+, the `poetry shell` command is not available by default. +This guide uses `poetry run` to execute commands, which works with all Poetry versions. + +We can initialize a new project like so: ```cmd poetry new <%= runtime.downcase %>-app cd <%= runtime.downcase %>-app -poetry shell +``` + +This creates a basic project structure. For Fly.io deployment, ensure your `pyproject.toml` uses the Poetry format with dependencies under `[tool.poetry.dependencies]`: +```cmd +[tool.poetry] +name = "<%= runtime.downcase %>-app" +version = "0.1.0" +description = "" +authors = ["Your Name "] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.10" +fastapi = {extras = ["standard"], version = "^0.115.0"} + +[build-system] +requires = ["poetry-core>=2.0.0"] +build-backend = "poetry.core.masonry.api" +``` + +Then we have to add the FastAPI dependency if it's not already included: + +```cmd +poetry add "fastapi[standard]" +``` + +To run commands, use `poetry run`: +```cmd +poetry run uvicorn <%= runtime.downcase %>_app.main:app --reload ``` \ No newline at end of file diff --git a/python/the-basics/initial-setup.html.md b/python/the-basics/initial-setup.html.md index 1236a65bdb..a87107fe2a 100644 --- a/python/the-basics/initial-setup.html.md +++ b/python/the-basics/initial-setup.html.md @@ -1,8 +1,11 @@ --- title: "Setting up a Python Environment" layout: framework_docs +fly_content_type: guide +fly_framework: python objective: How to setup a functional python environment on your local machine. order: 0 + --- ## Initial Local Setup @@ -50,15 +53,14 @@ poetry add This will automatically create a virtual environment for you. To interact with your virtual environment, you can prefix your commands with `poetry run`: - ```cmd poetry run python main.py ``` Alternatively, you can activate the environment: - ```cmd -poetry shell +poetry env activate python main.py ``` +**Note:** If you're using Poetry 2.0+ (the default when installed with `pipx`), the `poetry shell` command is not available by default. Use `poetry run` (recommended) or `poetry env activate` instead. If you need `poetry shell`, you can install it as a plugin: `poetry self add poetry-plugin-shell` From 4ecf82ef3eb576f1cde9f13298164d117b571af8 Mon Sep 17 00:00:00 2001 From: Kristin Martin Date: Wed, 25 Feb 2026 18:36:18 +0000 Subject: [PATCH 2/3] Rework Poetry 2.0 docs to keep shared partial generic Remove hardcoded FastAPI content from the shared _poetry_new partial, restore poetry add to the FastAPI page, and update initial-setup with poetry env activate guidance and a callout about the Poetry 2.0 change. --- python/frameworks/fastapi.html.markerb | 6 +++++ python/partials/_poetry_new.erb | 35 +++---------------------- python/the-basics/initial-setup.html.md | 21 +++++++++------ 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/python/frameworks/fastapi.html.markerb b/python/frameworks/fastapi.html.markerb index f15eb4f70e..427409b41a 100644 --- a/python/frameworks/fastapi.html.markerb +++ b/python/frameworks/fastapi.html.markerb @@ -24,6 +24,12 @@ Deploying a FastAPI app on Fly.io is... well it's fast! You can be up and runnin <%= partial "/docs/python/partials/poetry_new", locals: { runtime: "FastAPI" } %> +Then we have to add the FastAPI dependency: + +```cmd +poetry add "fastapi[standard]" +``` + Now, let's create a simple FastAPI app in `main.py`: ```python diff --git a/python/partials/_poetry_new.erb b/python/partials/_poetry_new.erb index ae805bc369..b3cda158d1 100644 --- a/python/partials/_poetry_new.erb +++ b/python/partials/_poetry_new.erb @@ -1,40 +1,11 @@ -For managing our project, we use [Poetry](https://python-poetry.org/). +For managing our project, we use [Poetry](https://python-poetry.org/). For more information on the initial setup with poetry, refer to [setting up a python environment](/docs/python/the-basics/initial-setup). -**Note:** If you're using Poetry 2.0+, the `poetry shell` command is not available by default. -This guide uses `poetry run` to execute commands, which works with all Poetry versions. - We can initialize a new project like so: + ```cmd poetry new <%= runtime.downcase %>-app cd <%= runtime.downcase %>-app ``` -This creates a basic project structure. For Fly.io deployment, ensure your `pyproject.toml` uses the Poetry format with dependencies under `[tool.poetry.dependencies]`: -```cmd -[tool.poetry] -name = "<%= runtime.downcase %>-app" -version = "0.1.0" -description = "" -authors = ["Your Name "] -readme = "README.md" - -[tool.poetry.dependencies] -python = "^3.10" -fastapi = {extras = ["standard"], version = "^0.115.0"} - -[build-system] -requires = ["poetry-core>=2.0.0"] -build-backend = "poetry.core.masonry.api" -``` - -Then we have to add the FastAPI dependency if it's not already included: - -```cmd -poetry add "fastapi[standard]" -``` - -To run commands, use `poetry run`: -```cmd -poetry run uvicorn <%= runtime.downcase %>_app.main:app --reload -``` \ No newline at end of file +
If you're using Poetry 2.0+ (the default when installed via `pipx`), the `poetry shell` command is no longer built in. Use `poetry run` to run commands (e.g., `poetry run python main.py`), or activate the environment with `poetry env activate`. See the [initial setup guide](/docs/python/the-basics/initial-setup) for more details.
diff --git a/python/the-basics/initial-setup.html.md b/python/the-basics/initial-setup.html.md index a87107fe2a..18ec358c23 100644 --- a/python/the-basics/initial-setup.html.md +++ b/python/the-basics/initial-setup.html.md @@ -1,11 +1,8 @@ --- title: "Setting up a Python Environment" layout: framework_docs -fly_content_type: guide -fly_framework: python objective: How to setup a functional python environment on your local machine. order: 0 - --- ## Initial Local Setup @@ -20,7 +17,7 @@ We recommend the latest [supported versions](https://devguide.python.org/version ## Dependency Management -For project and dependency management we use [Poetry](https://python-poetry.org/). Like most package managers, Poetry combines multiple tools in one. +For project and dependency management we use [Poetry](https://python-poetry.org/). Like most package managers, Poetry combines multiple tools in one. You have other options: - [venv](https://docs.python.org/3/library/venv.html) and [pip](https://pip.pypa.io/) @@ -28,7 +25,7 @@ You have other options: - [pyenv](https://github.com/pyenv/pyenv) - [pip-tools](https://pypi.org/project/pip-tools/) -If you are just starting out, it is easiest to follow along using `poetry`. +If you are just starting out, it is easiest to follow along using `poetry`. After installing it, you will have to set 2 flags for virtual environment management. ```cmd @@ -36,7 +33,7 @@ poetry config virtualenvs.create true poetry config virtualenvs.in-project true ``` -This will make your development environment resemble what ends up happening inside the docker image. +This will make your development environment resemble what ends up happening inside the docker image. You can create a new project using this command: @@ -50,17 +47,25 @@ Once inside the project, you can add packages with the add command: poetry add ``` -This will automatically create a virtual environment for you. +This will automatically create a virtual environment for you. To interact with your virtual environment, you can prefix your commands with `poetry run`: + ```cmd poetry run python main.py ``` Alternatively, you can activate the environment: + ```cmd poetry env activate +``` + +This prints the activation command for your shell. To activate in one step: + +```cmd +source $(poetry env activate) python main.py ``` -**Note:** If you're using Poetry 2.0+ (the default when installed with `pipx`), the `poetry shell` command is not available by default. Use `poetry run` (recommended) or `poetry env activate` instead. If you need `poetry shell`, you can install it as a plugin: `poetry self add poetry-plugin-shell` +
If you're using Poetry 2.0+ (the default when installed via `pipx`), the `poetry shell` command is no longer built in. Use `poetry run` (recommended) or `poetry env activate` as shown above. If you prefer `poetry shell`, you can install it as a plugin: `poetry self add poetry-plugin-shell`.
From 67d000ab2ef5d042f1cbd891f9d79b04ae7233a1 Mon Sep 17 00:00:00 2001 From: Kristin Martin Date: Wed, 25 Feb 2026 19:50:36 +0000 Subject: [PATCH 3/3] Capitalize Docker in initial-setup.html.md --- python/the-basics/initial-setup.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/the-basics/initial-setup.html.md b/python/the-basics/initial-setup.html.md index 18ec358c23..1bc4dfeaf0 100644 --- a/python/the-basics/initial-setup.html.md +++ b/python/the-basics/initial-setup.html.md @@ -33,7 +33,7 @@ poetry config virtualenvs.create true poetry config virtualenvs.in-project true ``` -This will make your development environment resemble what ends up happening inside the docker image. +This will make your development environment resemble what ends up happening inside the Docker image. You can create a new project using this command: