https://github.com/cpleonardo/fastapi-django-boilerplate
FastAPI with Django ORM boilerplate
https://github.com/cpleonardo/fastapi-django-boilerplate
async django django-admin django-orm fastapi
Last synced: about 1 month ago
JSON representation
FastAPI with Django ORM boilerplate
- Host: GitHub
- URL: https://github.com/cpleonardo/fastapi-django-boilerplate
- Owner: cpleonardo
- Created: 2024-11-11T03:34:51.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-13T17:54:54.000Z (7 months ago)
- Last Synced: 2025-12-26T17:50:06.212Z (6 months ago)
- Topics: async, django, django-admin, django-orm, fastapi
- Language: Python
- Homepage:
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### FastAPI with Django ORM Boilerplate
A basic boilerplate configuration for creating a project that leverages the speed and simplicity of FastAPI for building APIs and the powerful Django ORM for managing database interactions. This configuration allows developers to benefit from FastAPI’s asynchronous capabilities for handling high-performance requests while taking advantage of Django's mature ORM and admin interface for database and content management.
## Features
- FastAPI for building APIs quickly and efficiently.
- Django ORM for database interactions.
- Django Admin interface for content management.
- Full support for asynchronous requests with FastAPI.
- Docker Compose setup for easy deployment.
- Separate services for API (FastAPI), admin panel (Django), and database migrations.
- UV package manager for fast dependency installation.
## Installation
### Initial Setup
1. Clone the repository:
```sh
git clone git@github.com:cpleonardo/fastapi-django-boilerplate.git
cd fastapi-django-boilerplate
```
2. (Optional) Rename the project to your own name:
```sh
chmod +x rename_project.sh
./rename_project.sh your_project_name
```
This script will:
- Rename the Django project directory from `project` to your chosen name
- Update all Python files to reference the new project name
- Update `docker-compose.yml` to use the new project name
- Note: After renaming, clear cached files with: `find src -type d -name __pycache__ -exec rm -rf {} +`
### Option 1: Using Docker Compose (Recommended)
Build and run with Docker Compose:
```sh
docker compose up
```
This will:
- Run database migrations
- Collect static files
- Start the FastAPI server on port 8000
- Start the Django admin server on port 8001
### Option 2: Local Development
1. Install UV (if not already installed):
```sh
curl -LsSf https://astral.sh/uv/install.sh | sh
```
2. Install the dependencies:
```sh
uv pip install -r pyproject.toml
```
3. Run migrations:
```sh
cd src
python manage.py migrate
python manage.py collectstatic --no-input
```
4. (Optional) Create a super user:
```sh
python manage.py createsuperuser
```
5. Run the FastAPI server:
```sh
uvicorn project.asgi:app --host 0.0.0.0 --port 8000 --reload
```
6. (Optional) In another terminal, run the Django admin server:
```sh
cd src
python manage.py runserver 0.0.0.0:8001
```
## Usage
### With Docker Compose:
- Access the FastAPI server at `http://localhost:8000/docs` for Swagger UI or `http://localhost:8000/redoc` for ReDoc.
- Access the Django Admin panel at `http://localhost:8001/admin`.
### With Local Development:
- Access the API documentation at `http://localhost:8000/docs` for Swagger UI or `http://localhost:8000/redoc` for ReDoc.
- Access the Django Admin panel at `http://localhost:8001/admin` (if running the admin server separately).
## Docker Services
The `docker-compose.yml` defines three services:
- **migrations**: Runs database migrations and collects static files on startup
- **api**: FastAPI server running on port 8000 with hot-reload enabled
- **admin**: Django admin server running on port 8001
## Contributing
Contributions are welcome! Please open an issue or submit a pull request for any changes.
## License
This project is licensed under the MIT License.