Skip to content
/ py-api-log-test Public template

A template to build API with easy and enough logs and tests, using Python :)

Notifications You must be signed in to change notification settings

vochicong/py-api-log-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 などとして定義されているかによって、 requestsfastapi.testclient.TestClient を使い分けます。

About

A template to build API with easy and enough logs and tests, using Python :)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published