https://github.com/rd003/fastapi_postgres_crud
REST APIs with FastApi, SQLAlchemy, alembic and postgres
https://github.com/rd003/fastapi_postgres_crud
alembic fastapi postgresql python3 sqlalchemy
Last synced: 28 days ago
JSON representation
REST APIs with FastApi, SQLAlchemy, alembic and postgres
- Host: GitHub
- URL: https://github.com/rd003/fastapi_postgres_crud
- Owner: rd003
- License: mit
- Created: 2025-10-18T12:30:59.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2025-10-18T16:46:44.000Z (8 months ago)
- Last Synced: 2025-10-19T08:44:54.895Z (8 months ago)
- Topics: alembic, fastapi, postgresql, python3, sqlalchemy
- Language: Python
- Homepage: https://ravindradevrani.com/posts/fastapi-crud-with-postgres/
- Size: 37.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# REST API CRUD with fastapi and postgres
It is a source code of my [blog post](https://ravindradevrani.com/posts/fastapi-crud-with-postgres/).
## Pre-requisite
- Must have install `python 3.10+`
- Install `uv` from [here](https://docs.astral.sh/uv/getting-started/installation/) ,if it is not installed in your machine.
- Either use Postgress in docker or install it
## Tech used
- Uv for creating the project and managing dependencies
- Python 3.12
- FastApi
- SqlAlchemy
- Alembic
- PostgreSQL
# How to run a project
- Create a database with name `book_db`
- Clone the repository `git clone https://github.com/rd003/fastapi_postgres_crud.git`
- Open it in terminal `cd fastapi_postgres_crud`
Fire these commands (they may vary to windows):
- `touch .env` (create a file, this command won't work in windows powershell/command prompt)
- Open the `.env` file (in linux/mac you may use `vim .env` or nano .env) and paste the content below
```env
DEBUG=True
DATABASE_URL=postgresql://postgres:p%4055w0rd@localhost:5432/book_db
```
Replace DATABASE_URL with yours.
- uv venv` (will create a virtual environment)
- `source .venv/bin/activate` (will activate venv)
- `uv sync` (to install the dependencies)
- `alembic upgrade head` (will create tables in the database)
- Run project with `uvicorn src.main:app --reload`. Bydefault, the app will be listening at `http://127.0.0.1:8000`
- In the web browser, open this url `http://127.0.0.1:8000/docs`. It will open the `swagger ui`