Gen-AI Developer Classroom notes 08/Nov/2025

Building a FastAPI based application with database in it

  • Lets build an FastAPI Endpoint for updating movie informations
  • This service will have its own database and we will run our api inside a container.
  • Refer Here for the boiler plate code of movies info service
  • To run this refer below

Movies Info Service

Local Development

Using Docker Compose

docker-compose up -d

Manual Setup

  1. Install dependencies:
git clone https://github.com/GenAIDevelopment/PythonFoundations.git
cd ./PythonFoundations/fastapi/Oct25/bookmyshow-replica/services/moviesinfo
uv sync
  1. Start the service:
uv run moviesinfo

Environment Variables

Configure in .env file:
POSTGRES_DB – Database name
POSTGRES_USER – Database user
POSTGRES_PASSWORD – Database password
DATABASE_URL – Full database connection string
HOST – Service host (default: 0.0.0.0)
MOVIES_SVC_PORT – Service port (default: 8000)

API Endpoints

  • GET / – Health check
  • GET /items/{item_id} – Get item by ID

  • The service docs can be accessed by url http://localhost:18000/docs

SQlAlchemy async

  • Add dependencies
uv add sqlalchemy[asyncio] asyncpg

Exercise:

  • Try async mysql and async sqlserver.
  • Build a simple langgraph
    • create a fast api endpoint
    • on post
      • graph.invoke

Next Steps

  • Fix for lifespan
  • Adding Authentication and authorization

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading