A lightweight, ready-to-use template for building APIs with FastAPI. Get started in minutes without the hassle of complex setup!
This template is designed to streamline your FastAPI development by eliminating:
- 🛠️ Database configuration
- ⚙️ Environment setup
- 📂 Tedious project initialization and structure
- 🗂️ Manual setup of SQLAlchemy models and Pydantic schemas
- ✅ Type safety with Mypy support
- 🧹 Code quality ensured by Ruff linter and formatter
- 📦 Dependency management via Poetry
- 🗄️ Asynchronous SQLAlchemy with AsyncPG driver for high-performance work with PostgreSQL
- 🐳 Dockerized Postgres for quick database setup
- 🔄 Alembic migrations for seamless database schema management
Follow these steps to set up and run the project locally.
-
Clone the Repository
Using HTTPS:
git clone https://github.com/eugeneliukindev/FastAPI-Starter-Kit.git
Using SSH (recommended):
git clone [email protected]:eugeneliukindev/FastAPI-Starter-Kit.git
-
Install Dependencies
This project uses Poetry for dependency management. See pyproject.toml for details.
Optional: Configure Poetry to create a virtual environment in the project root:
poetry config virtualenvs.in-project true
Install dependencies:
With
dev
dependencies (for development):poetry install
Without
dev
dependencies (for production):poetry install --without dev
-
Set Up the Database
Use the provided Docker Compose file to spin up a Postgres database:
docker compose up -d
Note: Ensure Docker is installed and running.
-
Run Alembic Migrations
Apply an existing database migration using Alembic:
alembic upgrade head
-
Start the Application
Run the FastAPI server:
python main.py
Your API is now running! Access it at
http://localhost:8000
(or the configured port).
- 📚 API Documentation: Auto-generated by FastAPI at
/docs
(Swagger UI) or/redoc
- 🛠️ Development Tools:
- Run
mypy .
for type checking - Run
ruff check .
for linting - Run
ruff format .
for code formatting
- Run
-
Important Note About .env
The
.env
file is used to store sensitive data like database credentials. For demonstration purposes, it's not included in.gitignore
. For security reasons, we strongly recommend adding.env
to.gitignore
to prevent accidentally committing sensitive data to the repository:echo ".env" >> .gitignore
-
Initializing pre-commit Hooks
If you installed
dev
dependencies via poetry install, pre-commit was included in the installation. To activate it, run:pre-commit install
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/YourFeature
) - Commit your changes (
git commit -m 'Add YourFeature'
) - Push to the branch (
git push origin feature/YourFeature
) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
Happy coding! 🎉 If you have questions or need help, feel free to open an issue.