https://github.com/devbruce/fastapi-di-tpl
FastAPI with Dependency Injector Template
https://github.com/devbruce/fastapi-di-tpl
dependency-injector fastapi template
Last synced: 10 months ago
JSON representation
FastAPI with Dependency Injector Template
- Host: GitHub
- URL: https://github.com/devbruce/fastapi-di-tpl
- Owner: devbruce
- License: mit
- Created: 2024-09-17T09:18:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-29T07:15:16.000Z (10 months ago)
- Last Synced: 2025-04-10T14:57:53.841Z (10 months ago)
- Topics: dependency-injector, fastapi, template
- Language: Python
- Homepage:
- Size: 322 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
FastAPI with Dependency Injector
> [!NOTE]
> This repository is a template of [FastAPI](https://fastapi.tiangolo.com/) with [Dependency Injector](https://python-dependency-injector.ets-labs.org/)
## 📖 How to Set Local Environment
### 🛠️ Prerequisites
- [pyenv](https://github.com/pyenv/pyenv)
- [Poetry](https://python-poetry.org/)
- [direnv](https://direnv.net/)
### ✔️ Set Environment Variables
Copy [`.envrc.example`](./.envrc.example) to `.envrc` for setting environment variables with [direnv](https://direnv.net/)
```bash
cp .envrc.example .envrc
```
```bash
direnv allow
```
### ✔️ Create Virtual Environment with [Poetry](https://python-poetry.org/)
- Install python with [pyenv](https://github.com/pyenv/pyenv)
```bash
pyenv install ${PYTHON_VERSION}
```
- Set poetry config
```bash
poetry config virtualenvs.in-project true
```
- Create virtualenv(`.venv`) with poetry
```bash
poetry env use $(pyenv root)/versions/${PYTHON_VERSION}/bin/python
```
- Install python dependencies with poetry([`poetry.lock`](./poetry.lock))
```bash
poetry install
```
- Activate virtualenv(`.venv`)
> Ref: [managing-environments#activating-the-environment](https://python-poetry.org/docs/managing-environments#activating-the-environment)
```bash
eval $(poetry env activate)
```
- Activate virtualenv(`.venv`) with plugin([python-poetry/poetry-plugin-shell](https://github.com/python-poetry/poetry-plugin-shell))
```bash
poetry shell
```
### ✔️ Install pre-commit Hooks(`.git/hooks`)
> pre-commit: [Link](https://pre-commit.com/)
```bash
pre-commit install -t pre-commit
```
```bash
pre-commit install -t pre-push
```
🖱️ Run Manually
```bash
pre-commit run
```
🖱️ How to Skip Hooks
After installing the hooks, you can use the `--no-verify` option to skip it.
```bash
git commit --no-verify
```
```bash
git push --no-verify
```
> [!TIP]
> For details on the make commands, refer to the [`Makefile`](./Makefile)
## 🚀 Run Server on Local
```bash
make run
```
## 💯 Test
```bash
make test
```
## ✅ Lint & Format
Check lint & format only
```bash
make check
```
Format
```bash
make format
```
## 👤 Authors
- Maintainer: @devbruce