FastAPI REST API pre-configured with a database. This will get you up and running with CRUD operations quickly. Use this starter, boilerplate for all your new FastAPI projects.
- Python3
- python3-virtualenv
- python3-pip
- Docker
- Docker-compose
- SQLAlchemy
- Pydantic
- Docker
- Logging
- Celery
- Tests
- Config
- SSE
- PyMongo
- Version 1.0 Roadmap
.
├── api
│ ├── __init__.py
│ ├── collections.py
│ ├── config.py
│ ├── database.py
│ ├── main.py
| ├── worker.py
│ └── models
│ │ ├── __init__.py
│ │ ├── item_model.py
│ │ └── task_model.py
│ │ └── user_model.py
│ └── schemas
│ │ ├── __init__.py
│ │ ├── items_schema.py
│ │ ├── questions_schema.py
│ │ └── tasks_schema.py
│ │ └── users_schema.py
│ └── routers
│ │ ├── __init__.py
│ │ ├── async_router.py
│ │ ├── items.py
│ │ ├── questions.py
│ │ ├── stream.py
│ │ ├── tasks.py
│ │ └── users.py
│ └── helpers
│ │ ├── __init__.py
│ │ ├── async_helper.py
│ │ └── crud.py
│ └── tests
│ │ ├── __init__.py
│ │ ├── db.py
│ │ └── test_main.py
├── docker
│ └── Dockerfile
- SQLALCHEMY_DATABASE_URL - Database URL used, can be either SQLite or PostgreSQL.
- MONGODB_URL - Database URL for MongoDB server.
- MONGODB_NAME - Name used for MongoDB Database.
- CELERY_CONF_BROKER_URL - Celery redis broker URL.
- CELERY_CONF_RESULT_BACKEND - Celery redis result backend.
- ALLOWED_ORIGINS - A list of origins that should be permitted to make cross-origin requests.
- ALLOW_CREDENTIALS - Allowed credentials
bool
for CORS middelware. - ALLOW_METHODS - Allowed methods ['GET','POST','PUT','PATCH','DELETE','OPTIONS'] for CORS middleware.
- ALLOW_HEADERS - A list of HTTP request headers that should be supported for cross-origin requests.
- APP_DEBUG - Set app debug mode
bool
value.
You can run git-changelog.sh
bash script to update the CHANGELOG file using the following command:
bash git-changelog.sh > CHANGELOG.md
You can run pylint
with the following command inside the fastapi-boilerplate
directory:
pylint --recursive=y api
You can run pytest
with the following command inside the fastapi-boilerplate
directory:
pytest api/
-
Clone the repo:
git clone https://github.com/WMRamadan/fastapi-boilerplate cd fastapi-boilerplate
-
Initialize and activate a virtual environment:
virtualenv env source env/bin/activate
-
Install dependencies:
pip3 install -r requirements.txt
-
Run
redis
service required for celery worker:docker-compose -f docker-compose-services.yml up -d
-
Run
celery
worker:celery --app=api.worker.celery worker --loglevel=info --logfile=celery.log
-
Run the development server:
uvicorn api.main:app --reload
-
View the API docs:
http://localhost:8000/docs # OR http://localhost:8000/redoc
-
Clone the repo:
git clone https://github.com/WMRamadan/fastapi-boilerplate cd fastapi-boilerplate
-
Build:
docker-compose build
-
Run the app:
docker-compose up
-
View the API docs:
http://localhost/docs # OR http://localhost/redoc
Please check our Contributing Guide on how you can contribute.