A comprehensive REST API demonstrating modern Python backend development skills. This project includes four essential features for a Python portfolio.
| Feature | Description |
|---|---|
| Authentication API | User registration and login with JWT tokens |
| Todo API | Full CRUD operations with SQLite database |
| URL Shortener | Create short URLs with click tracking |
| File Upload | Secure file upload/download with JWT auth |
| Technology | Purpose |
|---|---|
| FastAPI | Modern async web framework |
| SQLAlchemy | ORM for database operations |
| SQLite | Lightweight database |
| Pydantic | Data validation |
| JWT (python-jose) | Token authentication |
| bcrypt (passlib) | Password hashing |
| Uvicorn | ASGI server |
backend-python/
├── app/
│ ├── __init__.py
│ ├── main.py # Application entry point
│ ├── config.py # Configuration settings
│ ├── database.py # Database connection
│ ├── auth.py # JWT authentication logic
│ ├── models/ # SQLAlchemy models
│ │ ├── user.py # User model
│ │ ├── todo.py # Todo model
│ │ ├── url.py # ShortURL model
│ │ └── file.py # File model
│ ├── schemas/ # Pydantic schemas
│ │ ├── user.py # Auth & user schemas
│ │ ├── todo.py # Todo schemas
│ │ ├── url.py # URL schemas
│ │ └── file.py # File schemas
│ └── routers/ # API endpoints
│ ├── auth.py # Authentication routes
│ ├── todos.py # Todo CRUD routes
│ ├── urls.py # URL shortener routes
│ └── files.py # File upload routes
├── uploads/ # Uploaded files directory
├── requirements.txt # Python dependencies
├── .env.example # Environment template
└── README.md
| Method | Endpoint | Description |
|---|---|---|
| POST | /register |
Register new user |
| POST | /login |
Login (get JWT token) |
| GET | /me |
Get current user profile |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
List all todos (with filters) |
| POST | / |
Create new todo |
| GET | /{id} |
Get todo by ID |
| PUT | /{id} |
Update todo |
| DELETE | /{id} |
Delete todo |
| PATCH | /{id}/toggle |
Toggle completion status |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
List user's short URLs |
| POST | / |
Create short URL |
| GET | /{id} |
Get URL stats |
| DELETE | /{id} |
Delete short URL |
| GET | /s/{code} |
Redirect to original URL |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
List uploaded files |
| POST | /upload |
Upload a file |
| GET | /{id} |
Get file info |
| GET | /download/{filename} |
Download file |
| DELETE | /{id} |
Delete file |
- Python 3.10+
- pip
-
Clone and navigate to project
cd backend-python -
Create virtual environment
python -m venv venv # Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment (optional)
cp .env.example .env # Edit .env with your settings -
Run the server
uvicorn app.main:app --reload --port 8000
Once running, access interactive docs at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Register a user:
curl -X POST http://localhost:8000/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"username": "johndoe",
"password": "secret123"
}'Login (get token):
curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=user@example.com&password=secret123"Create a todo:
curl -X POST http://localhost:8000/api/v1/todos \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "Learn FastAPI",
"description": "Build a portfolio project",
"priority": "high"
}'Create short URL:
curl -X POST http://localhost:8000/api/v1/urls \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"original_url": "https://github.com/example/repo",
"title": "My GitHub"
}'Upload a file:
curl -X POST http://localhost:8000/api/v1/files/upload \
-H "Authorization: Bearer YOUR_TOKEN" \
-F "file=@/path/to/file.pdf"| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
Database connection string | sqlite:///./app.db |
SECRET_KEY |
JWT signing key | (random key) |
ALGORITHM |
JWT algorithm | HS256 |
ACCESS_TOKEN_EXPIRE_MINUTES |
Token expiry | 1440 (24h) |
UPLOAD_DIR |
File upload directory | uploads |
MAX_FILE_SIZE |
Max upload size (bytes) | 10485760 (10MB) |
BASE_URL |
Base URL for short links | http://localhost:8000 |
- Password Hashing: bcrypt with salt
- JWT Authentication: Secure token-based auth
- Input Validation: Pydantic schema validation
- CORS: Configurable cross-origin policies
- File Validation: Extension and size limits
- SQL Injection Prevention: SQLAlchemy ORM
This project showcases:
- RESTful API design with FastAPI
- Database modeling with SQLAlchemy ORM
- JWT-based authentication system
- Request/response validation with Pydantic
- Async file handling
- Clean project architecture
- API documentation (OpenAPI/Swagger)
- Error handling and HTTP status codes
MIT License - feel free to use this project in your portfolio!