コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 58 for Items (0.006 sec.)
依存関係としてのクラス 10509
依存関係としてのクラス 依存性注入 システムを深く掘り下げる前に、先ほどの例をアップグレードしてみましょう。 前の例の dict 前の例では、依存関係("dependable")から dict を返していました: Python 3.8+ - non-Annotated from typing import Union fr ... None ] = None , skip : int = 0 , limit : int = 100 ): return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : dict = Depends ( common_parameters )): return commons @app . get ( "/users/" ) async ... | None = None , skip : int = 0 , limit : int = 100 ): return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons @app . get ( "/use ... None ] = None , skip : int = 0 , limit : int = 100 ): return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons @app . get ( "/use ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/classes-as-dependenci...
クエリパラメータと文字列の検証 10509
クエリパラメータと文字列の検証 FastAPI ではパラメータの追加情報とバリデーションを宣言することができます。 以下のアプリケーションを例にしてみましょう: Python 3.8+ from typing import Union from fastapi import FastAPI app = FastAPI () @app . g ... et ( "/items/" ) async def read_items ( q : Union [ str , None ] = None ): results = { "items" : [{ "item_id" : "Foo" }, { "item_id" : ... q }) return results ? Other versions and variants Python 3.10+ from fastapi import FastAPI app = FastAPI () @app . get ( "/items/" ) async def read_items ( q : str | None = None ): results = { "items" : [{ "item_id" : "Foo" }, { "item_id" : "Bar" }]} ... : Python 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_items ( q : Union [ str , None ] = Query ( default = None , max_length = 50 )): results = { "items" : [ ...
https://man.mtool.work/fastapi/0.115/tutorial/query-params-str-validations/
Testing Dependencies with Overrides 9587
Testing Dependencies with Overrides Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Overriding dependencies during testing There are some scenarios where you might ... | None = None , skip : int = 0 , limit : int = 100 ): return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : Annotated [ dict , Depends ( common_parameters )]): return { "message" : "Hello Items ... , "skip" : 5 , "limit" : 10 } app . dependency_overrides [ common_parameters ] = override_dependency def test_override_in_items (): response = client . get ( "/items/" ) assert response . status_code == 200 assert response . json () == { "message" : ... "Hello Items!" , "params" : { "q" : None , "skip" : 5 , "limit" : 10 }, } def test_override_in_items_with_q (): response = client . get ...
https://man.mtool.work/fastapi/0.115/advanced/testing-dependencies/
Bigger Applications - Multiple Files 9397
Bigger Applications - Multiple Files Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . If you are building an application or a web API, it's rarely the case that you ... cture like this: . ├── app │ ├── __init__.py │ ├── main.py │ ├── dependencies.py │ └── routers │ │ ├── __init__.py │ │ ├── items.py │ │ └── users.py │ └── internal │ ├── __init__.py │ └── admin.py Tip There are several __init__.py files: one in each d ... importing code from one file into another. For example, in app/main.py you could have a line like: from app.routers import items The app directory contains everything. And it has an empty file app/__init__.py , so it is a "Python package" (a collectio ... ubdirectory app/routers/ with another file __init__.py , so it's a "Python subpackage": app.routers . The file app/routers/items.py is inside a package, app/routers/ , so, it's a submodule: app.routers.items . The same with app/routers/users.py , it's ...
https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/
ボディ - 更新 9265
ボディ - 更新 PUT による置換での更新 項目を更新するには HTTPの PUT 操作を使用することができます。 jsonable_encoder を用いて、入力データをJSON形式で保存できるデータに変換することができます(例:NoSQLデータベース)。例えば、 datetime を str に ... escription : Union [ str , None ] = None price : Union [ float , None ] = None tax : float = 10.5 tags : List [ str ] = [] items = { "foo" : { "name" : "Foo" , "price" : 50.2 }, "bar" : { "name" : "Bar" , "description" : "The bartenders" , "price" : 6 ... : 20.2 }, "baz" : { "name" : "Baz" , "description" : None , "price" : 50.2 , "tax" : 10.5 , "tags" : []}, } @app . get ( "/items/ {item_id} " , response_model = Item ) async def read_item ( item_id : str ): return items [ item_id ] @app . put ( "/item ... onse_model = Item ) async def update_item ( item_id : str , item : Item ): update_item_encoded = jsonable_encoder ( item ) items [ item_id ] = update_item_encoded return update_item_encoded ? Other versions and variants Python 3.10+ Python 3.9+ from f ...
https://man.mtool.work/fastapi/0.115/tutorial/body-updates/
ヘッダーのパラメータ 9016
ヘッダーのパラメータ ヘッダーのパラメータは、 Query や Path 、 Cookie のパラメータを定義するのと同じように定義できます。 Header をインポート まず、 Header をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi ... import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read_items ( user_agent : Union [ str , None ] = Header ( default = None )): return { "User-Agent" : user_ag ... on 3.10+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read_items ( user_agent : Annotated [ str | None , Header ()] = None ): return { "User-Agent" : user_agent } ... from typing import Annotated , Union from fastapi import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read_items ( user_agent : Annotated [ Union [ str , None ], Header ()] = None ): return { "User-Agent" : use ...
https://man.mtool.work/fastapi/0.115/tutorial/header-params/
OAuth2 scopes 8943
OAuth2 scopes Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can use OAuth2 scopes directly with FastAPI , they are integrated to work seamlessly. This would ... auth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" , scopes = { "me" : "Read information about the current user." , "items" : "Read items." }, ) app = FastAPI () def verify_password ( plain_password , hashed_password ): return pwd_context . veri ... e ( current_user : Annotated [ User , Depends ( get_current_active_user )], ): return current_user @app . get ( "/users/me/items/" ) async def read_own_items ( current_user : Annotated [ User , Security ( get_current_active_user , scopes = [ "items" ] ... auth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" , scopes = { "me" : "Read information about the current user." , "items" : "Read items." }, ) app = FastAPI () def verify_password ( plain_password , hashed_password ): return pwd_context . veri ...
https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
Separate OpenAPI Schemas for Input and Output or Not 8943
Separate OpenAPI Schemas for Input and Output or Not Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . When using Pydantic v2 , the generated OpenAPI is a bit more e ... tic import BaseModel class Item ( BaseModel ): name : str description : str | None = None app = FastAPI () @app . post ( "/items/" ) def create_item ( item : Item ): return item @app . get ( "/items/" ) def read_items () -> list [ Item ]: return [ Ite ... port BaseModel class Item ( BaseModel ): name : str description : Optional [ str ] = None app = FastAPI () @app . post ( "/items/" ) def create_item ( item : Item ): return item @app . get ( "/items/" ) def read_items () -> list [ Item ]: return [ Ite ... BaseModel class Item ( BaseModel ): name : str description : Union [ str , None ] = None app = FastAPI () @app . post ( "/items/" ) def create_item ( item : Item ): return item @app . get ( "/items/" ) def read_items () -> List [ Item ]: return [ Ite ...
https://man.mtool.work/fastapi/0.115/how-to/separate-openapi-schemas/
パスパラメータと数値の検証 8914
パスパラメータと数値の検証 クエリパラメータに対して Query でより多くのバリデーションとメタデータを宣言できるのと同じように、パスパラメータに対しても Path で同じ種類のバリデーションとメタデータを宣言することができます。 Pathのインポート まず ... n 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} " ) async def read_items ( item_id : int = Path ( title = "The ID of the item to get" ), q : Union [ str , None ... 0+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} " ) async def read_items ( item_id : Annotated [ int , Path ( title = "The ID of the item to get" )], q : Annot ... rn results from typing import Annotated , Union from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} " ) async def read_items ( item_id : Annotated [ int , Path ( title = "The ID of the item to get" )], q : Annot ...
https://man.mtool.work/fastapi/0.115/tutorial/path-params-numeric-validations/
Settings and Environment Variables 8723
Settings and Environment Variables Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In many cases your application could need some external settings or configuratio ... om pydantic_settings import BaseSettings class Settings ( BaseSettings ): app_name : str = "Awesome API" admin_email : str items_per_user : int = 50 settings = Settings () app = FastAPI () @app . get ( "/info" ) async def info (): return { "app_name" ... : settings . app_name , "admin_email" : settings . admin_email , "items_per_user" : settings . items_per_user , } Info In Pydantic v1 you would import BaseSettings directly from pydantic instead ... astAPI from pydantic import BaseSettings class Settings ( BaseSettings ): app_name : str = "Awesome API" admin_email : str items_per_user : int = 50 settings = Settings () app = FastAPI () @app . get ( "/info" ) async def info (): return { "app_name" ...
https://man.mtool.work/fastapi/0.115/advanced/settings/
PREV 1 2 3 4 5 6 NEXT