A comprehensive guide for setting up a development environment to contribute to FastAPI-fastkit.
Before you begin, ensure you have:
- Python 3.12 or higher installed
- Git installed and configured
- Basic knowledge of Python and FastAPI
- Text editor or IDE (VS Code, PyCharm, etc.)
FastAPI-fastkit provides a Makefile for easy development setup:
$ git clone https://github.com/bnbong/FastAPI-fastkit.git
$ cd FastAPI-fastkit
$ make install-dev
Setting up development environment...
Creating virtual environment...
Installing dependencies...
Installing pre-commit hooks...
✅ Development environment ready!This single command:
- Installs the package in editable mode with dev dependencies
- Sets up pre-commit hooks
- Configures development tools
Note: You should create and activate a virtual environment before running this command.
If you prefer manual setup or the Makefile doesn't work on your system:
$ git clone https://github.com/bnbong/FastAPI-fastkit.git
$ cd FastAPI-fastkit$ python -m venv .venv
$ source .venv/bin/activate # On Windows: .venv\Scripts\activate# Install package in editable mode with development dependencies
$ pip install -e ".[dev]"
# Or install from requirements files
$ pip install -r requirements.txt
$ pip install -r requirements-dev.txt$ pre-commit install
pre-commit installed at .git/hooks/pre-commit$ fastkit --version
FastAPI-fastkit version 1.0.0-dev
$ python -m pytest tests/
======================== test session starts ========================
collected 45 items
tests/test_cli.py::test_init_command PASSED
tests/test_templates.py::test_template_listing PASSED
...
======================== 45 passed in 2.34s ========================The development environment includes several tools to maintain code quality:
Black - Code formatter:
$ black src/ tests/
reformatted src/main.py
reformatted tests/test_cli.py
All done! ✨ 🍰 ✨isort - Import sorter:
$ isort src/ tests/
Fixing import order in src/main.pymypy - Type checking:
$ mypy src/
Success: no issues found in 12 source filesThe project Makefile provides convenient commands for common development tasks:
| Command | Description |
|---|---|
make install |
Install package in production mode |
make install-dev |
Install package with development dependencies |
make install-test |
Install package for testing (uninstall + reinstall) |
make uninstall |
Uninstall the package |
make clean |
Clean build artifacts and cache files |
| Command | Description |
|---|---|
make format |
Format code with black and isort |
make format-check |
Check code formatting without making changes |
make lint |
Run all linting checks (isort, black, mypy) |
| Command | Description |
|---|---|
make test |
Run all tests |
make test-verbose |
Run tests with verbose output |
make test-coverage |
Run tests with coverage report |
make coverage-report |
Generate detailed coverage report (FORMAT=html/xml/json/all) |
| Command | Description |
|---|---|
make inspect-templates |
Run template inspection on all templates |
make inspect-templates-verbose |
Run template inspection with verbose output |
make inspect-template |
Inspect specific template(s) (TEMPLATES parameter) |
| Command | Description |
|---|---|
make serve-docs |
Serve documentation locally |
make build-docs |
Build documentation |
| Command | Description |
|---|---|
make translate |
Translate documentation (LANG, PROVIDER, MODEL parameters) |
# Format code and run all checks
$ make format lint
Running isort...
Running black...
Running mypy...
✅ All checks passed!
# Run tests with coverage
$ make test-coverage
======================== test session starts ========================
collected 45 items
tests/test_cli.py::test_init_command PASSED
...
======================== 45 passed in 2.34s ========================
---------- coverage: platform darwin, python 3.12.1-final-0 ----------
Name Stmts Miss Cover
--------------------------------------------
src/main.py 45 2 96%
src/cli.py 89 5 94%
src/templates.py 67 3 96%
--------------------------------------------
TOTAL 201 10 95%
# Generate HTML coverage report
$ make coverage-report FORMAT=html
🌐 Opening HTML coverage report in browser...
# Translate documentation to Korean
$ make translate LANG=ko PROVIDER=github MODEL=gpt-4o-mini
Starting translation...
Running: python scripts/translate.py --target-lang ko --api-provider github --model gpt-4o-miniUnderstanding the project structure is crucial for development:
FastAPI-fastkit/
├── src/
│ ├── fastapi_fastkit/
│ │ ├── __main__.py # Entry point of the application
│ │ ├── backend/
│ │ │ ├── inspector.py # FastAPI-fastkit template inspector
│ │ │ ├── interactive/
│ │ │ │ ├── config_builder.py # Configuration builder for interactive mode
│ │ │ │ ├── prompts.py # Prompts for interactive mode
│ │ │ │ ├── selectors.py # Selectors logic for interactive mode
│ │ │ │ └── validators.py # User input validators for interactive mode
│ │ │ ├── main.py # Backend's logic entry point
│ │ │ ├── package_managers/
│ │ │ │ ├── base.py # Base class for package managers
│ │ │ │ ├── factory.py # Factory for package managers
│ │ │ │ ├── pdm_manager.py # PDM package manager
│ │ │ │ ├── pip_manager.py # pip package manager
│ │ │ │ ├── poetry_manager.py # Poetry package manager
│ │ │ │ └── uv_manager.py # uv package manager
│ │ │ ├── project_builder/
│ │ │ │ ├── config_generator.py # Configuration generator for project builder
│ │ │ │ └── dependency_collector.py # Dependency collector for project builder
│ │ │ └── transducer.py # Transducer for project builder
│ │ ├── cli.py # FastAPI-fastkit main CLI entry point
│ │ ├── core/
│ │ │ ├── exceptions.py # Exception handling
│ │ │ └── settings.py # Settings configuration
│ │ ├── fastapi_project_template/
│ │ │ ├── PROJECT_README_TEMPLATE.md # fastkit template project base README file
│ │ │ ├── README.md # fastkit template README
│ │ │ ├── fastapi-async-crud/
│ │ │ ├── fastapi-custom-response/
│ │ │ ├── fastapi-default/
│ │ │ ├── fastapi-dockerized/
│ │ │ ├── fastapi-empty/
│ │ │ ├── fastapi-mcp/
│ │ │ ├── fastapi-psql-orm/
│ │ │ ├── fastapi-single-module/
│ │ │ └── modules/
│ │ │ ├── api/
│ │ │ │ └── routes/
│ │ │ ├── crud/
│ │ │ └── schemas/
│ │ ├── py.typed
│ │ └── utils/
│ │ ├── logging.py # Logging configuration
│ │ └── main.py # FastAPI-fastkit main entry point
│ └── logs
├── tests
│ ├── conftest.py # pytest configuration
│ ├── test_backends/
│ ├── test_cli_operations/
│ ├── test_core.py
│ ├── test_rich/
│ ├── test_templates/
│ └── test_utils.py
├── uv.lock
├── docs/ # Documentation
├── scripts/ # Development scripts
├── mkdocs.yml
├── overrides/ # mkdocs overrides
├── pdm.lock
├── pyproject.toml
├── requirements-docs.txt # requirements for documentation
├── requirements.txt # requirements for development
├── CHANGELOG.md
├── CITATION.cff
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── MANIFEST.in
├── Makefile
├── README.md
├── SECURITY.md
└── env.example # environment example(configures translation AI model env vars)src/fastapi_fastkit/ - Main package source code
cli.py- Main CLI entry pointbackend/- Core backend logicinspector.py- Template inspectorinteractive/- Interactive mode components (prompts, selectors, validators)package_managers/- Package manager implementations (pip, uv, pdm, poetry)project_builder/- Project building utilitiestransducer.py- Template transducer
core/- Core configuration and exceptionsfastapi_project_template/- Project templates (fastapi-default, fastapi-async-crud, etc.)utils/- Shared utility functions
tests/ - Test suite
test_backends/- Backend-specific teststest_cli_operations/- CLI operation teststest_templates/- Template system tests
docs/ - Documentation (MkDocs)
- User guides, tutorials, and API reference
$ git checkout -b feature/add-new-template
Switched to a new branch 'feature/add-new-template'Edit code, add features, fix bugs...
$ make check-all test
Running all quality checks...
Running all tests...
✅ All checks and tests passed!Pre-commit hooks will automatically run:
$ git add .
$ git commit -m "Add new FastAPI template with authentication"
format...................................................................Passed
isort-check..............................................................Passed
black-fix................................................................Passed
mypy.....................................................................Passed
coverage-test............................................................Passed
[feature/add-new-template abc1234] Add new FastAPI template with authentication$ git push origin feature/add-new-template
$ gh pr create --title "Add new FastAPI template with authentication"All tests:
$ make test
# or
$ python -m pytestSpecific test file:
$ python -m pytest tests/test_cli.py -vWith coverage:
$ make test-coverage
# or
$ python -m pytest --cov=src --cov-report=htmlWatch mode for development:
$ make test-watch
# or
$ ptw tests/When adding new features, always include tests:
# tests/test_commands/test_new_feature.py
import pytest
from fastapi_fastkit.commands.new_feature import NewFeatureCommand
class TestNewFeatureCommand:
def test_command_success(self):
"""Test successful command execution"""
command = NewFeatureCommand()
result = command.execute(valid_args)
assert result.success is True
assert result.message == "Feature executed successfully"
def test_command_validation_error(self):
"""Test command with invalid arguments"""
command = NewFeatureCommand()
with pytest.raises(ValueError, match="Invalid argument"):
command.execute(invalid_args)
def test_command_edge_case(self):
"""Test edge case handling"""
command = NewFeatureCommand()
result = command.execute(edge_case_args)
assert result.success is True
assert "warning" in result.message.lower()Unit Tests - Test individual functions and classes:
def test_validate_project_name():
assert validate_project_name("valid-name") is True
assert validate_project_name("invalid name!") is FalseIntegration Tests - Test command interactions:
def test_init_command_creates_project(tmp_path):
result = runner.invoke(cli, ['init'], input='test-project\n...')
assert result.exit_code == 0
assert (tmp_path / "test-project").exists()End-to-End Tests - Test complete workflows:
def test_full_project_creation_workflow(tmp_path):
# Create project
result = runner.invoke(cli, ['init'], input='...')
assert result.exit_code == 0
# Add route
result = runner.invoke(cli, ['addroute', 'test-project', 'users'])
assert result.exit_code == 0
# Verify files exist
assert (tmp_path / "test-project" / "src" / "api" / "routes" / "users.py").exists()$ make docs-serve
INFO - Building documentation...
INFO - Cleaning site directory
INFO - Documentation built in 0.43 seconds
INFO - [14:30:00] Serving on http://127.0.0.1:8000/$ make docs-build
INFO - Building documentation...
INFO - Documentation built in 0.43 secondsDocumentation is written in Markdown and built with MkDocs. Here's an example structure:
Feature Guide Template:
# New Feature Guide
This guide explains how to use the new feature.
## Prerequisites
- FastAPI-fastkit installed
- Basic Python knowledge
## Usage
<div class="termy">
```console
$ fastkit new-feature --option value
✅ Feature executed successfully!
```
</div>
!!! tip "Pro Tip"
Use `--help` to see all available options.Follow PEP 8 with these specific rules:
- Line length: 88 characters (Black default)
- Imports: Organized with isort
- Type hints: Required for all public functions
- Docstrings: Google style for all public APIs
from typing import List, Optional
from pathlib import Path
def create_project_structure(
project_name: str,
template_path: Path,
output_dir: Optional[Path] = None,
) -> List[Path]:
"""Create project structure from template.
Args:
project_name: Name of the project to create
template_path: Path to the template directory
output_dir: Output directory, defaults to current directory
Returns:
List of created file paths
Raises:
ValueError: If project_name is invalid
FileNotFoundError: If template_path doesn't exist
"""
if not project_name.isidentifier():
raise ValueError(f"Invalid project name: {project_name}")
if not template_path.exists():
raise FileNotFoundError(f"Template not found: {template_path}")
# Implementation here...
return created_filesFor development, you can set these environment variables:
| Variable | Description | Default |
|---|---|---|
FASTKIT_DEBUG |
Enable debug logging | False |
FASTKIT_DEV_MODE |
Enable development features | False |
FASTKIT_TEMPLATE_DIR |
Custom template directory | Built-in templates |
FASTKIT_CONFIG_DIR |
Configuration directory | ~/.fastkit |
TRANSLATION_API_KEY |
Translation API key (put Github PAT when using Github AI model provider) | None |
$ export FASTKIT_DEBUG=true
$ export FASTKIT_DEV_MODE=true
$ fastkit init
DEBUG: Loading configuration from /home/user/.fastkit/
DEBUG: Available templates: ['fastapi-default', ...]For other environment variable settings, refer to the @settings.py module.
1. Pre-commit hooks fail:
$ git commit -m "Fix bug"
black....................................................................Failed
hookid: black
Files were modified by this hook. Additional output:
would reformat src/cli.pySolution: Run formatters and commit again:
$ make format
$ git add .
$ git commit -m "Fix bug"2. Tests fail on different Python versions:
Solution: Use tox to test multiple Python versions:
$ pip install tox
$ tox
py38: commands succeeded
py39: commands succeeded
py310: commands succeeded
py311: commands succeeded
py312: commands succeeded3. Import errors in development:
Solution: Install package in editable mode:
$ pip install -e .- GitHub Issues: Report bugs and request features
- GitHub Discussions: Ask questions and share ideas
- Documentation: Check the User Guide
- Run all checks:
make check-all test - Update documentation if needed
- Add tests for new features
- Update CHANGELOG.md
- Follow commit message conventions
type(scope): brief description
Longer description if needed
Fixes #123
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changesrefactor: Code refactoringtest: Test additions/changeschore: Maintenance tasks
Examples:
feat(cli): add new template command
Add support for creating projects from custom templates.
The command accepts a template path and creates a new
project with the specified configuration.
Fixes #45
fix(templates): handle missing template files gracefully
When a template file is missing, show a clear error message
instead of crashing with a stack trace.
Fixes #67
For maintainers, the release process is:
- Update version in
setup.pyand__init__.py - Update CHANGELOG.md
- Create release PR
- Tag release after merge
- GitHub Actions automatically builds and publishes
$ git tag v1.2.0
$ git push origin v1.2.0Now that your development environment is set up:
- Explore the codebase to understand the architecture
- Run the test suite to ensure everything works
- Pick an issue from GitHub to work on
- Join discussions to connect with other contributors
Happy coding! 🚀
!!! tip "Development Tips"
- Use make check-all before committing
- Write tests first (TDD approach)
- Keep commits small and focused
- Update documentation with new features