Notes API (Python)

Back to Python

A RESTful notes management API built with FastAPI. The project demonstrates idiomatic Python API design: Pydantic schemas for validation, SQLAlchemy for ORM-based data access, and a clean separation between route handlers and CRUD logic.

Tech

  • Python
  • FastAPI
  • SQLAlchemy
  • SQLite
  • Pydantic

API

Five endpoints cover the full CRUD surface for notes:

  • POST /notes — create a new note; returns the created resource.
  • GET /notes — retrieve all notes as a list.
  • GET /notes/{note_id} — fetch a single note by ID; returns 404 if not found.
  • PUT /notes/{note_id} — update title and content; returns 404 if not found.
  • DELETE /notes/{note_id} — remove a note and return the deleted resource.

Architecture

  • CRUD layer — database operations are isolated in crud.py, keeping route handlers in main.py thin and focused on HTTP concerns.
  • Pydantic schemas — NoteCreate, NoteUpdate, and NoteResponse enforce input validation and shape the API contract independently of the ORM model.
  • SQLAlchemy ORM — the Note model maps to a SQLite table; sessions are managed via FastAPI dependency injection with a try/finally teardown to guarantee cleanup.
  • Auto-generated docs — FastAPI serves interactive Swagger UI and ReDoc out of the box at /docs and /redoc.