https://github.com/vochicong/py-api-log-test
A template to build API with easy and enough logs and tests, using Python :)
https://github.com/vochicong/py-api-log-test
api fastapi loguru pytest python
Last synced: about 1 month ago
JSON representation
A template to build API with easy and enough logs and tests, using Python :)
- Host: GitHub
- URL: https://github.com/vochicong/py-api-log-test
- Owner: vochicong
- Created: 2020-09-04T12:42:26.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-11T11:54:39.000Z (almost 6 years ago)
- Last Synced: 2025-08-20T00:50:02.112Z (10 months ago)
- Topics: api, fastapi, loguru, pytest, python
- Language: Python
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PythonでAPI作成、ログとテスト
PythonでAPIを作成する際の、雛形プロジェクトです。
パッケージ管理は `poetry` を使います。
主な道具
* `fastapi`
* `loguru`
* `pytest`
## ログ
`from loguru import logger` ですぐに使いやすい `logger` が出来上がります。
`lib.util.set_logger` で少し手を加えています。
* `DEBUG_LOG_FILE` ("/var/log/app_debug.log") に `DEBUG` レベルのログを記録
* 標準エラー出力 `stderr` には、 `LOG_LEVEL` 環境変数で定義するレベル( `INFO` など)のログを出力
## テスト
`lib.util.ApiClient` は、
APIの `get` , `post` をテストするために、
`BASE_URL` 環境変数が `http://localhost` などとして定義されているかによって、
`requests`
と
`fastapi.testclient.TestClient`
を使い分けます。