https://github.com/kilgoretrout1985/fastapiexample
just a fastapi-framework example playground
https://github.com/kilgoretrout1985/fastapiexample
asyncio example-project fastapi
Last synced: 2 months ago
JSON representation
just a fastapi-framework example playground
- Host: GitHub
- URL: https://github.com/kilgoretrout1985/fastapiexample
- Owner: kilgoretrout1985
- License: mit
- Created: 2022-08-10T12:37:07.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-05T11:31:56.000Z (almost 4 years ago)
- Last Synced: 2025-12-28T09:48:18.158Z (6 months ago)
- Topics: asyncio, example-project, fastapi
- Language: Python
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
# Fastapi example project
1)
```
python3 -m venv .env && \
source .env/bin/activate && \
pip install -U pip && \
pip install -e .
```
2) Configure Postgres connect dsn by editing `src/fastapiexample/config.py`.
If you want github to run and pass tests on your push to repositary, please
also supply correct postgres login, password, test db name and port
into `.github/workflows/tests.yaml` file.
If you can't or do not want to edit config.py (like storing secrets in
a file) - you can change config.py settings at runtime using environment
variables, e.g.:
```
db_dsn="postgresql+asyncpg://fastapiexamplepguser:pass@localhost/fastapiexample" uvicorn main:app --reload
```
This is a single bash line that sets env var `db_dsn` specifically for
current uvicorn-run and than runs it. Same for running tests:
```
DB_TEST_DSN="postgresql+asyncpg://fastapiexamplepguser:pass@localhost/fastapiexample_test" pytest
```
3) For development you should also run:
```
pip install -e .[testing] && tox
```
Everything should be green at this point.
4)
```
cd src/fastapiexample && python main.py && uvicorn main:app --reload
```
`python main.py` is used to create initial db tables before first run.
Use `python main.py --drop-all` to drop (delete all!) and recreate db in case you need it.
5) Open [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) for interactive docs.