Skip to content

FastAPI ​

Starter for a FastAPI service. Base steps come from Python Project Setup.

Create Project Directory ​

bash
mkdir vehub_crawler
cd vehub_crawler

Add Virtual Environment ​

bash
python3 -m venv .venv
source .venv/bin/activate

Install FastAPI ​

bash
pip install fastapi
pip install "uvicorn[standard]"

.gitignore ​

bash
echo '# Byte-compiled / optimized / DLL files
__pycache__/
.venv

# Editors
/.fleet
/.idea
/.vscode
/.zed

# Env
.env
.env.backup
.env.production

# System
.DS_Store
' >> .gitignore

main.py ​

python
from typing import Union

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

Run Development Server ​

bash
uvicorn main:app --reload

Or with the FastAPI CLI:

bash
fastapi dev main.py

Create Repo ​

bash
gh repo create vehub_crawler --private

Commit to repo ​

bash
git init
git add -A
git commit -m 'Initial FastAPI install'
git branch -M main
bash
git remote add origin git@github.com:zoonix/vehub_crawler.git
bash
git push -u origin main