This project is built using FastAPI and provides various ways to run the application along with command-line utilities for managing the database and users.
git clone https://github.com/jobissjo/Fastapi-Starter.git
cd Fastapi-StarterMake sure you have Python installed (preferably 3.9+).
python -m venv venvActivate the virtual environment:
- Windows:
venv\Scripts\activate- Linux/macOS:
source venv/bin/activatepip install -r requirements.txtCopy the format-env file and create your own .env file.
cp format-env .envEdit the .env file and fill in your credentials and environment details.
If you want to rename the repository, remove git and change the folder name with your project name
Use the CLI to setup some initial setup:
python cli.py initial-setupThis do some of the basic setups like
-
In database migrations we use alembic tool, that version we do not track, so that folder not include, if we try to initial migrate that cause a problem, so create a versions folder inside alembic folder
-
Same like, if use sqlite db, that db will present inside app/db folder, that will also we do not track, so need to add that folder
-
If you needed any additional setup here do that place
Use the CLI to create an admin/superuser:
python cli.py createsuperuserIf you want to preload any data into the database, you can add your logic in:
app/commands/initial_data.pyThen run:
python cli.py initialdataThere are three ways to run the app:
fastapi devpython cli.py runserverOptional arguments:
--host(default:0.0.0.0)--port(default:8000)--reload(enabled by default)--no-reload(disable auto-reload)
Example:
python cli.py runserver --host 127.0.0.1 --port 8080 --no-reloaduvicorn app.main:appYou can also pass --reload, --host, and --port options as needed.
.
├── .vscode/ # Editor-specific settings (e.g., launch configs)
├── alembic/ # Database migrations (powered by Alembic)
├── app/ # Core application source code
│ ├── __pycache__/ # Python bytecode cache (auto-generated)
│ ├── commands/ # Custom CLI commands (e.g., createsuperuser, initial setup/data)
│ ├── core/ # Core configurations (settings, logging, database config)
│ ├── db/ # SQLite3 database files for development
│ ├── middlewares/ # Application-level middlewares (e.g., exception handlers)
│ ├── models/ # SQLAlchemy ORM models
│ ├── repositories/ # All database query logic (CRUD and advanced queries)
│ ├── routes/ # API route definitions, organized by version (v1, v2)
│ ├── schemas/ # Pydantic schemas for request/response validation
│ ├── services/ # Business logic for handling operations and processing
│ ├── templates/ # HTML templates (e.g., for emails or UI rendering)
│ ├── utils/ # Utility/helper functions used across the project
│ ├── __init__.py # Package initializer
│ └── main.py # Application entry point
├── tests/ # Unit and integration tests
├── venv/ # Virtual environment (excluded from version control)
├── .gitignore # Files and folders to ignore in version control
├── alembic.ini # Alembic configuration
├── cli.py # CLI script entry point
├── format-env # Environment variable format template
└── requirements.txt # Python dependencies
- Make sure your database and other services (e.g., Redis, etc.) mentioned in
.envare running. - Keep sensitive credentials out of version control.
- Use async libraries, if we combine sync code inside async function, it would block, if sync code, asyncio.to_thread is good