|
Size: 1486
Comment:
|
Size: 1835
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| <<TableOfContents(2)>> | |
| Line 46: | Line 47: |
| == pip , venv steps == {{{ |
== pip , venv steps == {{{#!highlight sh cd ~/Documents mkdir -p fastapi-test cd fastapi-test |
| Line 52: | Line 56: |
| main.py | pip install -r requirements.txt cat << 'EOF' > main.py |
| Line 59: | Line 65: |
| return {"mensagem": "Olá, Mundo! O FastAPI está a funcionar!"} | return {"message": "Hello world!"} EOF |
| Line 62: | Line 69: |
| # /home/vitor/Documents/fastapi-test/.venv/bin/python3 \ # /home/vitor/Documents/fastapi-test/.venv/bin/fastapi dev main.py # http://127.0.0.1:8000 # Server started at http://127.0.0.1:8000 # OpenAPI/Swagger documentation at http://127.0.0.1:8000/docs |
|
| Line 63: | Line 75: |
| # http://127.0.0.1:8000 | |
| Line 66: | Line 77: |
Contents
FastAPI
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python based on standard Python type hints.
FastAPI works OK without uv. You can build, install, and run FastAPI projects using traditional tools like pip, venv, and poetry
main.py
Install
1 # uv An extremely fast Python package and project manager, written in Rust.
2 # https://docs.astral.sh/uv/getting-started/installation/
3 curl -LsSf https://astral.sh/uv/install.sh | sh
4 pipx install uv
5 pip install uv
6 uv self update
7 pip install --upgrade uv
8
9 uv add "fastapi[standard]"
10
11 pip install fastapi[standard]
12 # Virtual Environment: Python's built-in venv module
13 # Dependency Management: requirements.txt or pyproject.toml
14
Run
uv run fastapi dev
pip , venv steps
1 cd ~/Documents
2 mkdir -p fastapi-test
3 cd fastapi-test
4 python3 -m venv .venv
5 source .venv/bin/activate
6 echo "fastapi[standard]" > requirements.txt
7
8 pip install -r requirements.txt
9
10 cat << 'EOF' > main.py
11 from fastapi import FastAPI
12
13 app = FastAPI()
14
15 @app.get("/")
16 def read_root():
17 return {"message": "Hello world!"}
18 EOF
19
20 fastapi dev main.py
21 # /home/vitor/Documents/fastapi-test/.venv/bin/python3 \
22 # /home/vitor/Documents/fastapi-test/.venv/bin/fastapi dev main.py
23 # http://127.0.0.1:8000
24 # Server started at http://127.0.0.1:8000
25 # OpenAPI/Swagger documentation at http://127.0.0.1:8000/docs
26
27
28 uvicorn main:app --reload
