Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions python/frameworks/fastapi.html.markerb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 33 additions & 2 deletions python/partials/_poetry_new.erb
Original file line number Diff line number Diff line change
@@ -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 <you@example.com>"]
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
```
8 changes: 5 additions & 3 deletions python/the-basics/initial-setup.html.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -50,15 +53,14 @@ poetry add <dep>
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`