Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 2 months ago
JSON representation

FastAPI with Dependency Injector Template

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.tpl`](./.envrc.tpl) to `.envrc` for setting environment variables with [direnv](https://direnv.net/)

```bash
cp .envrc.tpl .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`) with poetry

```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