FastAPI Initializr is a tool to quickly generate and bootstrap new FastAPI projects. It aims to simplify the setup process by providing customizable project templates with common configurations and best practices.
- Generate FastAPI project structure
- Choose from different project templates:
- Minimal: Basic FastAPI setup with essential configurations
- Basic: Extended template with pre-configured structure (in progress) including:
- Organized directory structure (
app/routers,app/services,app/models, etc.) - Example CRUD endpoints
- Health check endpoint
- Basic SQLite integration
- Logging configuration
- More features coming soon!
- Organized directory structure (
- Customize Python version, database, and other project settings
- Include optional features like Docker setup and database migrations
- Support for both
pipandPoetryas dependency managers - Pre-configured utilities like
black,flake8,pre-commit, andcommitizen - Download generated project as a zip file
- FastAPI: Web framework for building APIs with Python
- Pydantic: Data validation and settings management using Python type annotations
- Poetry: Dependency management and packaging
- pip: Standard Python package installer
- Loguru: Library for flexible logging
- Jinja2: Template engine for generating project files
- Pytest: Testing framework for Python
- Docker: Containerization platform
- Docker Compose: Tool for defining and running multi-container Docker applications
- Python 3.10+
piporPoetry- Docker (optional)
- Docker Compose (optional)
- Make (optional)
-
Clone the repository:
git clone https://github.com/pedrosfaria2/fastapi_initializr.git cd fastapi_initializr -
Install dependencies and set up the environment:
make setup
To start the FastAPI server, use one of the following commands:
-
Run the application directly:
make run
-
Run the application using Docker:
make run-docker
-
Run the application using Docker Compose (for development):
make run-compose
Open your web browser and visit http://localhost:8001/docs to access the FastAPI Initializr Swagger.
- Access the API at
/generator/createendpoint. - Provide a configuration payload. Example:
{ "project_name": "my_fastapi_app", "description": "My FastAPI Application", "template_type": "minimal", // or "basic" for the extended template "python_version": "3.10", "author": "Your Name", "fastapi_version": "0.100.0", "uvicorn_version": "0.22.0", "dependency_manager": "poetry", "include_dockerfile": false, "include_docker_compose": false, "include_black": true, "include_flake8": true, "include_pre_commit": true, "include_conventional_commit": true } - The generated ZIP file will include a structured FastAPI project with:
main.pywith basic endpointsrequirements.txtorpyproject.tomlREADME.md.gitignore- Optional Dockerfile and/or docker-compose.yml
- Pre-configured utilities
- Additional structure and features if using the "basic" template (work in progress)
The basic template is currently under development. While the core functionality is implemented, including the directory structure, CRUD endpoints, and basic configurations, some features are still being refined and enhanced. Feel free to try it out and provide feedback!
FastAPI Initializr supports both pip and Poetry for managing dependencies. The choice of manager is specified in the configuration (dependency_manager).
If pip is selected:
- A
requirements.txtfile will be generated. - Install dependencies with:
pip install -r requirements.txt
If Poetry is selected:
- A
pyproject.tomlfile will be generated. - Install dependencies with:
poetry install
This tool provides pre-configured utilities to help maintain code quality and enforce standards:
-
Black: Code formatter. Run:
black . -
Flake8: Linter for Python. Run:
flake8 . -
Pre-Commit: Runs checks before commits. Install hooks:
pre-commit install
-
Commitizen: For conventional commits. Make a commit:
cz commit
These utilities are included in the generated project if enabled in the configuration.
This project is licensed under the MIT License. See the LICENSE file for details.