This is a FastAPI project to manage banks and their branches using PostgreSQL and SQLAlchemy.
- FastAPI
- PostgreSQL
- SQLAlchemy (async)
- Python 3.7+
- PostgreSQL
-
Clone the repository:
git clone [https://github.com/yourusername/yourproject.git](https://github.com/kanhaiyagupta9045/Postgres-and-FastAPI-.git) cd Postgres-and-FastAPI-
-
Create a virtual environment and activate it:
virtualenv env source env/bin/activate # On Windows use `.\env\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Set up the PostgreSQL database and update the database URL in your environment variables:
DATABASE_URL=postgresql://username:password@localhost/dbname
- id: Integer, Primary Key
- name: String(49), Unique, Not Null
- branches: Relationship to
Branch
- ifsc: String(11), Primary Key
- bank_id: Integer, Foreign Key to
banks.id
- branch: String(74), Not Null
- address: String(195), Not Null
- city: String(50), Not Null
- district: String(50), Not Null
- state: String(26), Not Null
- bank: Relationship to
Bank
- ifsc: str
- bank_id: int
- branch: str
- address: str
- city: str
- district: str
- state: str
- orm_mode: True
- name: str
- id: int
- branches: List[Branch]
- orm_mode: True
- URL:
/create_bank/
- Method:
POST
- Request Body:
BankCreate
- Response:
Bank
- Description: Creates a new bank.
- URL:
/read_banks/
- Method:
GET
- Response:
List[BankCreate]
- Description: Reads all banks.
- URL:
/create_branch/
- Method:
POST
- Request Body:
BranchCreate
- Response:
Branch
- Description: Creates a branch for a specific bank.
- URL:
/branch/{id}
- Method:
GET
- Response:
BranchSchema
- Description: Reads branch details for a specific bank ID.
curl -X POST "http://127.0.0.1:8000/create_bank/" -H "Content-Type: application/json" -d '{"name": "State Bank of India"}'