GithubHelp home page GithubHelp logo

fatapi-postgresql-study's Introduction

fatapi-postgresql-study

参考:https://qiita.com/mtitg/items/47770e9a562dd150631d

Docker化しただけで大部分は参考のものと同じです.

目的

  • Python から DB をいじる方法のお勉強
  • データベースへの CRUD 操作を Web API 化する方法のお勉強

DB 接続して CRUD する Python 製 API サーバーを構築.

  • PostgreSQL でデータベースを構築.
  • FastAPI で データベースの CRUD 処理を Web API 化.
    • テーブルの操作は sqlalchemy, psycopg2 を利用.
  • データベースと,APIサーバをそれぞれコンテナ化し,Docker Compose で稼働

動かし方

  1. docker イメージのビルド
docker build . -t myclient
  1. docker compose でサービス稼働
docker compose up -d
  1. テーブルのレコード一覧取得(GET)
curl localhost:8000/todos/
# 出力
# []

最初は何も入ってないので空です.

  1. テーブルにレコード追加(jsonのペイロードをPOST)
curl \
-X POST localhost:8000/todos/ \
-H  'accept: application/json' \
-H  'Content-Type: application/json' \
-d '{"title":"hoge", "done":false}'
# 出力
# [{"id":1,"done":false,"title":"hoge"}]
curl localhost:8000/todos/
# 出力
# [{"id":1,"done":false,"title":"hoge"}]
  1. 使用したコンテナの停止・削除
docker compose down

SwaggerUI の使用

http://localhost:8000/docs にブラウザでアクセスすると,SwaggerUI を用いてブラウザ上で API を利用できる.

上のような curl コマンドを実行しなくても,レコード一覧の取得やレコードの追加,更新,削除などができるようになっている.

Next

https://github.com/shibuiwilliam/ml-system-in-actions/tree/main/chapter2_training/model_db

を参考にして,プロジェクト,モデル,実験管理のデータベースとそのAPIを作成する.

実験の履歴をデータベースで管理でき,REST API で操作できるので便利.

fatapi-postgresql-study's People

Contributors

y629 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.