FastAPI
Starter for a FastAPI service. Base steps come from Python Project Setup.
Create Project Directory
bash
mkdir vehub_crawler
cd vehub_crawlerAdd Virtual Environment
bash
python3 -m venv .venv
source .venv/bin/activateInstall 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
' >> .gitignoremain.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 --reloadOr with the FastAPI CLI:
bash
fastapi dev main.pyCreate Repo
bash
gh repo create vehub_crawler --privateCommit to repo
bash
git init
git add -A
git commit -m 'Initial FastAPI install'
git branch -M mainbash
git remote add origin git@github.com:zoonix/vehub_crawler.gitbash
git push -u origin main