I’m starting a new FastAPI project for my capstone, and I want to document the entire process so I can look back on it later.
Prerequisites
- Python 3.10+ installed
- Git installed and configured
- A GitHub account
- Basic terminal knowledge
1. Create your project folder
mkdir my-project
cd my-project
2. Set up a virtual environment
Always use a virtual environment.
python -m venv venv
Activate it:
# macOS / Linux
source venv/bin/activate
# Windows (CMD)
venv\Scripts\activate.bat
Your terminal prompt should now show (venv) at the start.
3. Install FastAPI and Uvicorn
pip install fastapi uvicorn
uvicorn is the ASGI server that runs your FastAPI app.
4. Freeze your dependencies
pip freeze > requirements.txt
This creates a requirements.txt file so anyone can reproduce your environment with:
pip install -r requirements.txt
5. Create your first app
Create a file called main.py at the root of your project:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello, FastAPI!"}
6. Run the dev server
uvicorn main:app --reload
Now open your browser and visit:
-
http://127.0.0.1:8000— your root endpoint -
http://127.0.0.1:8000/docs— auto-generated Swagger UI
FastAPI auto-generates interactive API docs from your code.
7. Structure your project (optional but recommended)
For a capstone or real project, a flat main.py will get messy fast. Here's a minimal structure that scales well:
my-fastapi-project/
├── app/
│ ├── __init__.py
│ ├── main.py
│ └── models/
│ ├── __init__.py
├── requirements.txt
├── .gitignore
└── README.md
Update your entry point to point to app.main:
uvicorn app.main:app --reload
8. Add a .gitignore
Before committing anything, create a .gitignore so you don't accidentally push your virtual environment or secrets:
you can get text from gitignore.io
9. Write a README.md
just as you want~
10. Initialize Git and push to GitHub
- Create a repo on GitHub
- Connect and push
This is really easy and you can do it.
Done! Your FastAPI project is now on GitHub.
Top comments (0)