Skip to content

yepMizu/FastAPI-learn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FastAPI Learn πŸš€ A hands-on learning project for building REST APIs with FastAPI and PostgreSQL, covering both raw SQL (psycopg2) and ORM-based (SQLAlchemy) approaches side by side.

πŸ› οΈ Tech Stack FastAPI β€” Modern, fast Python web framework PostgreSQL β€” Relational database psycopg2 β€” Raw PostgreSQL adapter for Python SQLAlchemy β€” Python ORM for database interaction Pydantic β€” Data validation via schemas Uvicorn β€” ASGI server for running the app

⚑ Getting Started

  1. Clone the repository bashgit clone https://github.com/yepMizu/FastAPI-learn.git cd FastAPI-learn

  2. Create and activate a virtual environment bashpython -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate

  3. Install dependencies bashpip install fastapi uvicorn sqlalchemy psycopg2-binary

  4. Configure your database Update the database URLs in app/database.py and app/psycopg2_db.py with your PostgreSQL credentials: python# database.py SQLALCHEMY_DATABASE_URL = "postgresql://your_user:your_password@localhost/your_database"

  5. Run the server bashcd app uvicorn main:app --reload The API will be available at http://127.0.0.1:8000

πŸ“– API Documentation FastAPI provides interactive docs out of the box: ToolURLSwagger UIhttp://127.0.0.1:8000/docsReDochttp://127.0.0.1:8000/redoc

πŸ—‚οΈ API Endpoints psycopg2 (Raw SQL) MethodEndpointDescriptionGET/posts/Get all postsPOST/posts/Add a new studentGET/posts/{id}Get a post by IDDELETE/posts/{id}Delete a post by ID SQLAlchemy (ORM) MethodEndpointDescriptionGET/sqlalchemy/Test SQLAlchemy connection

πŸ“ Notes SQLAlchemy tables are auto-created on server startup via Base.metadata.create_all(bind=engine) in main.py Both psycopg2 and SQLAlchemy connect to the same PostgreSQL instance but are kept separate for learning purposes Run uvicorn from inside the app/ directory to avoid Python import issues

πŸ‘€ Author GitHub: @yepMizu

About

For learning FastAPI && free commits

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages