118 lines
2.5 KiB
Markdown
118 lines
2.5 KiB
Markdown
# sqlalchemy-fastapi-pydentic-pytest
|
|
|
|
Pet project built with **FastAPI + SQLAlchemy (async) + Pydantic + Pytest**.
|
|
Implements CRUD for users, JWT authentication, and tests.
|
|
|
|
---
|
|
|
|
## 📂 Project Structure
|
|
```
|
|
/
|
|
├── server/backend # Source code: endpoints, pydantic, JWT, password email sending, permissions, rate-limiting
|
|
├── server/frontend # Pages: login, registration, reset-password, main
|
|
├── server/database # Database, alembic, db_balancer (not configured, template only)
|
|
├── server/testing # pytests
|
|
├── run.py # Entry point, application startup
|
|
├── makefile # Entry point, application and utility commands
|
|
├── requirements.txt # Dependencies
|
|
├── .env # Environment variables
|
|
└── README.md # This file
|
|
|
|
```
|
|
---
|
|
|
|
## ⚙️ Requirements
|
|
|
|
- Python 3.13.3
|
|
- SQLite (default)
|
|
|
|
---
|
|
|
|
## 🚀 Installation and Running
|
|
|
|
1. Clone the repository:
|
|
```bash
|
|
git clone <repository URL>
|
|
cd sqlalchemy-fastapi-pydentic-pytest
|
|
```
|
|
2. Create and activate a virtual environment:
|
|
```
|
|
python3 -m venv .venv
|
|
source .venv/bin/activate # Linux / macOS
|
|
venv\Scripts\activate # Windows
|
|
```
|
|
|
|
3. Install dependencies:
|
|
```
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
4. Configure the .env file (example):
|
|
```
|
|
ALLOW_ORIGINS=http://localhost:3000
|
|
ALLOW_CREDENTIALS=true
|
|
ALLOW_METHODS=GET,POST,PUT,DELETE
|
|
ALLOW_HEADERS=*
|
|
JWT_SECRET_KEY=your_secret_key
|
|
ACCESS_TOKEN_EXPIRE_MINUTES=30
|
|
```
|
|
5. Run DB migrations:
|
|
```
|
|
make migrate_head
|
|
```
|
|
6. Start the application:
|
|
```
|
|
python run.py, or without the environment, simply run make run
|
|
Open the page via Microsoft Live Server
|
|
```
|
|
|
|
7. OpenAPI documentation will be available at:
|
|
```
|
|
• Swagger UI → http://localhost:8000/docs
|
|
• JSON schema → http://localhost:8000/openapi.json
|
|
```
|
|
⸻
|
|
|
|
🔐 Authentication
|
|
• The /login endpoint accepts application/x-www-form-urlencoded:
|
|
```
|
|
username=<email>&password=<password>
|
|
```
|
|
|
|
Returns a JWT token:
|
|
```
|
|
{
|
|
"access_token": "...",
|
|
"token_type": "bearer"
|
|
}
|
|
```
|
|
⸻
|
|
```
|
|
👤 Users (CRUD)
|
|
• POST /user_create — create a user
|
|
• GET /get_user_by_email/{email} — get a user by email
|
|
• GET / — get all users
|
|
• PUT /user_update/{email} — update user data
|
|
• DELETE /user_delete/{email} — delete a user
|
|
```
|
|
⸻
|
|
|
|
🧪 Testing
|
|
|
|
Run all tests:
|
|
```
|
|
make test
|
|
```
|
|
Test coverage (planned):
|
|
```
|
|
• CRUD operations
|
|
• Pydantic schemas
|
|
• API endpoints
|
|
• JWT authorization
|
|
• Testing
|
|
```
|
|
⸻
|
|
|
|
📜 License
|
|
|
|
Educational project. |