Skip to content

studyhaxer/day13-fastapi-sqlite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Day 13 — FastAPI + SQLite + SQLAlchemy

A fully functional Notes REST API built with FastAPI and SQLite database.
Data persists after server restarts — no more Python list storage.


What I Learned Today

  • Setting up a SQLite database with SQLAlchemy
  • Defining database tables as Python classes (models)
  • Separating concerns across multiple files
  • Using Depends() for database session injection
  • Response models with NoteOut schema
  • Full CRUD operations using SQLAlchemy queries

Project Structure

day13-fastapi-sqlite/
│
├── main.py        → FastAPI app and all endpoints
├── database.py    → Database connection, engine, session
├── models.py      → SQLAlchemy table definition
├── schemas.py     → Pydantic models for request and response
└── README.md

API Endpoints

Method Endpoint Description
GET /notes Get all notes
GET /notes?keyword=x Search notes by keyword in title
GET /notes/important Get all important notes
GET /notes/{note_id} Get a single note by ID
POST /notes Create a new note
PUT /notes/{note_id} Update an existing note
DELETE /notes/{note_id} Delete a note

Request Body

POST /notes

{
  "title": "My Note",
  "content": "Note content here",
  "is_important": false
}

PUT /notes/{note_id} — all fields optional

{
  "title": "Updated Title",
  "is_important": true
}

How to Run

# Clone the repo
git clone https://github.com/studyhaxer/day13-fastapi-sqlite
cd day13-fastapi-sqlite

# Create virtual environment
python -m venv venv
venv\Scripts\activate        # Windows
source venv/bin/activate     # Mac/Linux

# Install dependencies
pip install fastapi uvicorn sqlalchemy

# Run the server
uvicorn main:app --reload

Open http://127.0.0.1:8000/docs to explore and test all endpoints interactively.


Tech Stack

  • FastAPI — Python web framework
  • SQLite — Local file-based database
  • SQLAlchemy — ORM for database operations
  • Pydantic — Data validation and serialization
  • Uvicorn — ASGI server

Part of My Daily Python Streak

This is Day 13 of my daily Python learning streak.
Every day — a new concept, a GitHub push, and a LinkedIn post.

Follow the journey: linkedin.com/in/studyhaxer
GitHub: github.com/studyhaxer

About

Day 13 of #60DaysOfPython — Notes REST API rewritten with SQLAlchemy + SQLite for real persistence. Full CRUD, keyword search, importance filter, and FastAPI response_model validation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages