You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness. Documentation: https://sqlmodel.tiangolo.com Source Code: https://github.com/tiangolo/sqlmodel SQLModel is a library for interacting with SQL databases from Python code, with Python objects. It is designed to be intuitive, easy to use, highly compatible, and robust. SQLModel is based on Python type annotatio
FastAPIでSQLAlchemyを利用するサンプルコードが公式ドキュメントにあります。 サンプルコードのmain.pyの重要な部分を抜粋するとこんな感じです。 app = FastAPI() # Dependency def get_db(): db = SessionLocal() try: yield db finally: db.close() @app.get("/users/", response_model=List[schemas.User]) def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): users = crud.get_users(db, skip=skip, limit=limit) return users SessionLocal()で作成したセッシ
代替ツールから受けたインスピレーションと比較¶ 何がFastAPIにインスピレーションを与えたのか、他の代替ツールと比較してどうか、そしてそこから何を学んだのかについて。 はじめに¶ FastAPIは、代替ツールのこれまでの働きがなければ存在しなかったでしょう。 以前に作られた多くのツールが、作成における刺激として役立ってきました。 私は数年前から新しいフレームワークの作成を避けてきました。まず、FastAPIでカバーされているすべての機能を、さまざまなフレームワーク、プラグイン、ツールを使って解決しようとしました。 しかし、その時点では、これらの機能をすべて提供し、以前のツールから優れたアイデアを取り入れ、可能な限り最高の方法でそれらを組み合わせ、それまで利用できなかった言語機能 (Python 3.6以降の型ヒント) を利用したものを作る以外に選択肢はありませんでした。 以前のツール¶
FastAPI は Python ベースのフレームワークで、その名の通り API を実装するのにうってつけです。軽量で非常に高速なフレームワークですが、FastAPI そのものには DB のシードやマイグレーションといった機能はなく、SQLAlchemy や Alembic など、他のライブラリを組み合わせて使うことが前提となります。 今回は、FastAPI で MySQL(厳密には MariaDB)を用いる際に、どのような実装が必要になってくるのかを見ていきたいと思います。セットアップは Docker コンテナ上で行います。 ※ 最終成果物は こちら のリポジトリにアップしています。 ファイル・ディレクトリ構成概観 まずはじめに、ファイル・ディレクトリ構成を示します。 ├── .env.development ├── app │ ├── cruds │ │ ├── __ini
概要 FastAPIでデータベースを利用するアプリケーションを書いたときに、APIの返り値の中の要素が足りないことがありました。例えば、User has many Itemsの関係があったときに、GET /usersで返り値のjsonにItemsが含まれていない場合です。 この記事ではその原因と解決策を調査します。 環境 $ pip freeze click==7.1.2 fastapi==0.61.1 h11==0.9.0 httptools==0.1.1 pydantic==1.6.1 SQLAlchemy==1.3.19 starlette==0.13.6 uvicorn==0.11.8 uvloop==0.14.0 websockets==8.1 from sqlalchemy import create_engine from sqlalchemy.ext.declarative
OAuth2 with Password (and hashing), Bearer with JWT tokens¶ Now that we have all the security flow, let's make the application actually secure, using JWT tokens and secure password hashing. This code is something you can actually use in your application, save the password hashes in your database, etc. We are going to start from where we left in the previous chapter and increment it. About JWT¶ JWT
こんにちは、サーバーサイドエンジニアの @kimihiro_n です。 最近は FastAPI という Python の Web フレームワークが社内で密かなブームとなっています。 今回はその FastAPI を使ったエラー定義まわりの話をしたいと思います。 FastAPI とは FastAPI の概要については先日ちょうど社内勉強会用に資料を作ったのでこちらを見てもらえるのが早いです。 ざっくり言えばシンプルなインターフェースとドキュメント(OpenAPI)の自動生成が強力なフレームワークになります。 OpenAPI でドキュメント管理 今回注目したいのはドキュメントの自動生成のほうです。 開発チームでもドキュメントとAPIの実際の仕様が一致しない問題が時々発生していて、どうドキュメントを管理していくかが課題となっています。 KPTで振り返った結果、「人がドキュメントを書くからメンテが大
Typer Typer Features Tutorial - User Guide Alternatives, Inspiration and Comparisons Help Typer - Get Help Development - Contributing Release Notes Typer, build great CLIs. Easy to code. Based on Python type hints. Documentation: https://typer.tiangolo.com Source Code: https://github.com/tiangolo/typer Typer is a library for building CLI applications that users will love using and developers will
Creating Microservices with Python Introduction to Microservices Benefits of Microservice Drawbacks of Microservice Why Microservice in Python Introduction to FastAPI Why FastAPI Installing FastAPI Creating Simple REST API using FastAPI Using PostgreSQL Database with FastAPI Microservice Data Management Patterns Database Per Service Shared Database API Composition Creating a Python Microservice in
最近、アプリケーションを開発する際のバックエンドはもっぱら FastAPI を使っています。Python ベースの、軽量で高速なフレームワークです。 実装を繰り返す中で行き着いた、個人的に開発を進めやすいディレクトリ構成をまとめました。 ※ただし、個別のファイルの中身に関しては言及するとボリュームが増えてしまうので、本記事では触れません。あくまでも全体感のみをお伝えする内容になります。 まず、下記が全体感です(User と Book がモデルとして存在しているとします)。 # ディレクトリ・ファイル構成全体 ├── app │ ├── __init__.py │ ├── cruds │ │ ├── __init__.py │ │ ├── users.py │ │ ├── books.py │ │ └── domains │ │ ├──
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く