Skip to Content
ファストAPI
book

ファストAPI

by Bill Lubanovic
March 2025
Intermediate to advanced
280 pages
3h 20m
Japanese
O'Reilly Media, Inc.
Content preview from ファストAPI

第3章. FastAPIツアー

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

FastAPIは、Pythonの標準的な型ヒントをベースに、Python 3.6+でAPIを構築するための、モダンで高速(高性能)なWebフレームワークである。

セバスチャン・ラミレス、FastAPIの開発者

プレビュー

FastAPIは2018年にSebastián Ramírez によって発表された。 多くの Python Web フレームワークよりも多くの利点があり、ここ数年で Python 3 に追加された機能を活用している。 この章では、FastAPI の主な機能の概要を、最初に知っておきたいこと、つまり Web リクエストとレスポンスの扱い方に重点を置いて説明する。

FastAPIとは何か?

どのウェブ・フレームワークもそうであるように、FastAPIはウェブ・アプリケーションの構築を助ける。 どのフレームワークも、機能、省略、デフォルトによって、いくつかの演算子をより簡単にするように設計されている。 FastAPIはその名の通り、ウェブAPIの開発をターゲットにしているが、従来のウェブ・コンテンツ・アプリケーションにも使うことができる。

FastAPIのWebサイトでは、このような利点を謳っている:

パフォーマンス

場合によってはNode.jsやGoと同じくらい速く、Pythonフレームワークとしては異例だ。

より迅速な開発

鋭利なエッジや変なところはない。

コード品質の向上

タイプ・ヒンティングとモデルはバグを減らすのに役立つ。

自動生成ドキュメントとテストページ

OpenAPIの記述を手作業で編集するよりもずっと簡単だ。

FastAPIは以下を使用する:

  • Python型のヒント

  • 非同期サポートを含むウェブ・マシナリー用Starlette

  • データ定義と検証のためのPydantic

  • 他を活用し、拡張するための特殊化統合

この組み合わせは、ウェブ・アプリケーション、特にRESTfulなウェブ・サービスのための快適な開発環境となる。

FastAPI アプリケーション

小さなFastAPIアプリケーション(単一のエンドポイントを持つウェブサービス)を書いてみよう。 今のところ、ウェブレイヤーと呼んでいるところで、ウェブリクエストとレスポンスだけを処理する。 まず、これから使う基本的なPythonパッケージをインストールする:

  • FastAPIフレームワーク:pip install fastapi

  • Uvicornのウェブサーバだ:pip install uvicorn

  • HTTPieテキストウェブクライアント:pip install httpie

  • Requests同期ウェブクライアントパッケージ:pip install requests

  • HTTPX同期/非同期ウェブクライアントパッケージ:pip install httpx

curlは最もよく知られたテキストウェブクライアントだが、HTTPieの方が使いやすいと思う。 また、デフォルトでJSONエンコーディングとデコーディングになっており、FastAPIとの相性が良い。 この章の後半で、特定のエンドポイントにアクセスするために必要なcurlコマンドラインの構文を含むスクリーンショットを見ることができる。

例3-1では、内向的なウェブ開発者になりきって、このコードを ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

GitHubアクションを学ぶ

GitHubアクションを学ぶ

Brent Laster
仕事ではじめる機械学習 第2版

仕事ではじめる機械学習 第2版

有賀 康顕, 中山 心太, 西林 孝

Publisher Resources

ISBN: 9798341624658