A production-ready, secure, and authenticated RESTful Notes API built using FastAPI and SQLAlchemy (ORM), backed by a PostgreSQL database running inside a Docker container.
This project implements strict user isolation via JWT Authentication, ensuring that users can only manage their own notes.
This is part of a bigger project, same API in three different languages, hence the 'polyglot' name.
- Full CRUD Operations: Create, read, update (
PATCH), and delete notes. - JWT Authentication: User registration and token-based login security hooks.
- Data Isolation: Foreign key constraints map notes to specific owners.
- Data Validation: Strict structural parsing using Pydantic schemas.
- Language: Python 3.12
- Framework: FastAPI (ASGI)
- ORM: SQLAlchemy
- Database: PostgreSQL 16 (Dockerized)
- Security: Passlib (Bcrypt 4.0.1) & PyJWT
git clone https://github.com/chriscarias/notes-api-python.git
cd notes-api-pythonEnsure Docker is running, then fire up the database process:
docker run --name polyglot-db \
-e POSTGRES_USER=user \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=notes_db \
-p 5433:5432 \
-d postgres:16Port mapping if needed.
Create a .env file in the root directory:
Code snippet
DATABASE_URL=postgresql://user:password@127.0.0.1:5433/notes_db
JWT_SECRET=YOUR_NEW_SECURE_RANDOM_STRING
use openssl rand -hex 32 to create JWT_SECRET
Create a virtual environment and install the required packages:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtuvicorn main:app --reloadThe API will be at http://127.0.0.1:8000. Interactive API docs at http://127.0.0.1:8000/docs.