Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wmramadan/fastapi-boilerplate
FastAPI REST API pre-configured with a database. This will get you up and running with CRUD operations quickly.
https://github.com/wmramadan/fastapi-boilerplate
asyncio boilerplate celery docker docker-compose fastapi loguru pydantic pylint pymongo pytest python redis rest-api sqlalchemy
Last synced: about 2 months ago
JSON representation
FastAPI REST API pre-configured with a database. This will get you up and running with CRUD operations quickly.
- Host: GitHub
- URL: https://github.com/wmramadan/fastapi-boilerplate
- Owner: WMRamadan
- License: gpl-3.0
- Created: 2022-12-08T09:10:31.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-18T14:23:15.000Z (over 1 year ago)
- Last Synced: 2024-05-01T17:58:39.219Z (8 months ago)
- Topics: asyncio, boilerplate, celery, docker, docker-compose, fastapi, loguru, pydantic, pylint, pymongo, pytest, python, redis, rest-api, sqlalchemy
- Language: Python
- Homepage:
- Size: 121 KB
- Stars: 35
- Watchers: 3
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: docs/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# FastAPI Boilerplate
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.## Requirements
- Python3
- python3-virtualenv
- python3-pip
- Docker
- Docker-compose## Features
- SQLAlchemy
- Pydantic
- Docker
- Logging
- Celery
- Tests
- Config
- SSE
- PyMongo## ToDo
- Version 1.0 [Roadmap](./docs/v1-roadmap.md)## File Structure
```
.
├── 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
```## Environment Variables
- 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.## Updating Changelog
You can run `git-changelog.sh` bash script to update the [CHANGELOG](./CHANGELOG.md) file using the following command:
```bash
bash git-changelog.sh > CHANGELOG.md
```## Linting
You can run `pylint` with the following command inside the `fastapi-boilerplate` directory:
```bash
pylint --recursive=y api
```## Running Tests
You can run `pytest` with the following command inside the `fastapi-boilerplate` directory:
```bash
pytest api/
```## Quick Start (Local)
1. Clone the repo:
```bash
git clone https://github.com/WMRamadan/fastapi-boilerplate
cd fastapi-boilerplate
```
2. Initialize and activate a virtual environment:
```bash
virtualenv env
source env/bin/activate
```3. Install dependencies:
```bash
pip3 install -r requirements.txt
```4. Run `redis` service required for celery worker:
```bash
docker-compose -f docker-compose-services.yml up -d
```5. Run `celery` worker:
```bash
celery --app=api.worker.celery worker --loglevel=info --logfile=celery.log
```6. Run the development server:
```bash
uvicorn api.main:app --reload
```7. View the API docs:
```bash
http://localhost:8000/docs
# OR
http://localhost:8000/redoc
```## Quick Start (Docker)
1. Clone the repo:
```bash
git clone https://github.com/WMRamadan/fastapi-boilerplate
cd fastapi-boilerplate
```
2. Build:
```bash
docker-compose build
```3. Run the app:
```bash
docker-compose up
```4. View the API docs:
```bash
http://localhost/docs
# OR
http://localhost/redoc
```## Contribution
Please check our [Contributing Guide](./docs/CONTRIBUTING.md) on how you can contribute.