FastAPI Starter Kit – a base project designed to help you develop web applications using Python and the FastAPI framework. This starter kit is built to simplify backend development with a pre-configured architecture for testing, database management, and mocking third-party services.
- FastAPI Framework: A modern and fast framework for building web APIs with Python.
- BDD Testing with Behave: Use behavior-driven development (BDD) for scenario-based testing.
- Unit Testing with Pytest: Pre-configured for unit and functional tests.
- SQLAlchemy: ORM (Object-Relational Mapper) for database interaction.
- Alembic: A database schema migration tool for managing schema changes.
- Mountebank: Mock third-party services with imposters for integration testing.
- PostgreSQL: Latest version of PostgreSQL as the default database.
- Adminer: A web-based tool to easily manage the PostgreSQL database.
- Docker and Docker Compose must be installed on your machine.
-
Clone this repository:
git clone https://github.com/your-project/fastapi-web-starter-kit.git cd fastapi-web-starter-kit
-
Install Python dependencies (if working locally without Docker):
python3 -m venv env source env/bin/activate pip install -r requirements.txt
-
Start the application using Docker Compose:
docker-compose up --build
-
Access the FastAPI application at http://localhost:8000.
-
Access Adminer to manage the database at http://localhost:8080.
-
requirements.txt
: Contains the necessary Python libraries. -
docker-compose.yml
: Docker configuration for the application, including PostgreSQL, Adminer, and Mountebank. -
alembic/
: Directory for database migrations using Alembic. -
tests/
: Directory for unit, functional, and BDD tests. -
imposters.ejs
: Configuration file for Mountebank, allowing you to mock third-party services.
FastAPI is used to create fast and performant RESTful APIs. The application is available at http://localhost:8000.
PostgreSQL is the database configured with the latest version, and you can manage it via Adminer at http://localhost:8080.
Mountebank is configured to simulate third-party services and test API integrations. Imposter configuration is stored in the imposters.ejs
file.
-
BDD with Behave: BDD scenarios are defined in the
features/
directory. -
Unit and Functional Testing with Pytest: Traditional tests are located in the
tests/
directory.
Database schema migrations are managed via Alembic. Use the following commands to create and apply migrations:
# Create a new migration
alembic revision --autogenerate -m "Migration name"
# Apply migrations
alembic upgrade head
-
Start the application:
docker-compose up --build
-
Apply database migrations:
docker-compose exec app alembic upgrade head
-
Run unit and functional tests:
docker-compose exec app pytest
-
Run BDD tests:
docker-compose exec app behave