<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>fallpoke</author_name>
  <author_url>https://blog.hatena.ne.jp/fallpoke/</author_url>
  <blog_title>誰かの技術置き場</blog_title>
  <blog_url>https://fallpoke-tech.hatenadiary.jp/</blog_url>
  <categories>
    <anon>FastAPI</anon>
    <anon>Python</anon>
    <anon>Webアプリ</anon>
    <anon>備忘録</anon>
  </categories>
  <description>お疲れ様です。 FastAPIで作成したAPI間で共通で使える変数を定義する方法のメモです。 最近の実装で必要になり調べたところFastAPIの機能として元からあることを知りました。 fastapi.tiangolo.com FastAPIでAPIを作成する際app = FastAPI()と最初に定義するかと思います。 このFastAPIのclassにstateがあり、app.state.[任意の名前] = (値)として変数を格納できます。 from fastapi import FastAPI app = FastAPI() app.state.message = &quot;メッセージ&quot; デモ デモ…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Ffallpoke-tech.hatenadiary.jp%2Fentry%2F2025%2F06%2F25%2F000521&quot; title=&quot;【FastAPI】API間で共通の変数を扱うapp.state【備忘録】 - 誰かの技術置き場&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>https://cdn-ak.f.st-hatena.com/images/fotolife/f/fallpoke/20250624/20250624001100.png</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2025-06-25 00:05:21</published>
  <title>【FastAPI】API間で共通の変数を扱うapp.state【備忘録】</title>
  <type>rich</type>
  <url>https://fallpoke-tech.hatenadiary.jp/entry/2025/06/25/000521</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
