コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 41 for Type (0.007 sec.)
Request Files 12651
Request Files Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can define files to be uploaded by the client using File . Info To receive uploaded files, first ... e interpreted as query parameters or body (JSON) parameters. The files will be uploaded as "form data". If you declare the type of your path operation function parameter as bytes , FastAPI will read the file for you and you will receive the contents ... al cases in which you might benefit from using UploadFile . File Parameters with UploadFile Define a file parameter with a type of UploadFile : Python 3.9+ from typing import Annotated from fastapi import FastAPI , File , UploadFile app = FastAPI () ... has the following attributes: filename : A str with the original file name that was uploaded (e.g. myimage.jpg ). content_type : A str with the content type (MIME type / media type) (e.g. image/jpeg ). file : A SpooledTemporaryFile (a file-like obje ...
https://man.mtool.work/fastapi/0.115/tutorial/request-files/
Additional Responses in OpenAPI 12185
Additional Responses in OpenAPI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Warning This is a rather advanced topic. If you are starting with FastAPI , you mig ... ht not need this. You can declare additional responses, with additional status codes, media types, descriptions, etc. Those additional responses will be included in the OpenAPI schema, so they will also appear in the AP ... correct place is: In the key content , that has as value another JSON object ( dict ) that contains: A key with the media type, e.g. application/json , that contains as value another JSON object, that contains: A key schema , that has as the value t ... side the OpenAPI schema: { "components" : { "schemas" : { "Message" : { "title" : "Message" , "required" : [ "message" ], "type" : "object" , "properties" : { "message" : { "title" : "Message" , "type" : "string" } } }, "Item" : { "title" : "Item" , ...
https://man.mtool.work/fastapi/0.115/advanced/additional-responses/
Custom Response Classes - File, HTML, Redirect, Streaming, etc. 10662
Custom Response Classes - File, HTML, Redirect, Streaming, etc. There are several custom response classes you can use to create an instance and return them directly from your path operations . Read more about it in the FastAPI docs for Cust ... e them to optimize JSON performance. ::: fastapi.responses.UJSONResponse options: members: - charset - status_code - media_type - body - background - raw_headers - render - init_headers - headers - set_cookie - delete_cookie ::: fastapi.responses.ORJ ... SONResponse options: members: - charset - status_code - media_type - body - background - raw_headers - render - init_headers - headers - set_cookie - delete_cookie Starlette Responses ::: f ... astapi.responses.FileResponse options: members: - chunk_size - charset - status_code - media_type - body - background - raw_headers - render - init_headers - headers - set_cookie - delete_cookie ::: fastapi.responses.HTM ...
https://man.mtool.work/fastapi/0.115/reference/responses/
リクエストフォームとファイル 10662
リクエストフォームとファイル File と Form を同時に使うことでファイルとフォームフィールドを定義することができます。 情報 アップロードされたファイルやフォームデータを受信するには、まず python-multipart をインストールします。 例えば、 pip inst ... leb : UploadFile = File (), token : str = Form () ): return { "file_size" : len ( file ), "token" : token , "fileb_content_type" : fileb . content_type , } ? Other versions and variants Python 3.9+ Python 3.8+ from typing import Annotated from fastap ... e , File ()], token : Annotated [ str , Form ()], ): return { "file_size" : len ( file ), "token" : token , "fileb_content_type" : fileb . content_type , } from fastapi import FastAPI , File , Form , UploadFile from typing_extensions import Annotated ... e , File ()], token : Annotated [ str , Form ()], ): return { "file_size" : len ( file ), "token" : token , "fileb_content_type" : fileb . content_type , } File と Form のパラメータの定義 ファイルやフォームのパラメータは Body や Query の場合と同じよう ...
https://man.mtool.work/fastapi/0.115/tutorial/request-forms-and-files/
OAuth2 scopes 9993
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 ... o declare and use scopes. Each "scope" is just a string (without spaces). They are normally used to declare specific security permissions, for example: users:read or users:write are common examples. instagram_basic is used by Facebook / Instagram. ht ... 2tfVFaWK1Be7DlH.PKZbv5H8KnzzVgXXbVxpva.pFm" , "disabled" : True , }, } class Token ( BaseModel ): access_token : str token_type : str class TokenData ( BaseModel ): username : str | None = None scopes : list [ str ] = [] class User ( BaseModel ): use ... copes" : form_data . scopes }, expires_delta = access_token_expires , ) return Token ( access_token = access_token , token_type = "bearer" ) @app . get ( "/users/me/" , response_model = User ) async def read_users_me ( current_user : Annotated [ User ...
https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer 9527
パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer これでセキュリティの流れが全てわかったので、 JWT トークンと安全なパスワードのハッシュ化を使用して、実際にアプリケーションを安全にしてみましょう。 このコードは、アプリケーシ ... bw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW" , "disabled" : False , } } class Token ( BaseModel ): access_token : str token_type : str class TokenData ( BaseModel ): username : Union [ str , None ] = None class User ( BaseModel ): username : str email ... a = { "sub" : user . username }, expires_delta = access_token_expires ) return Token ( access_token = access_token , token_type = "bearer" ) @app . get ( "/users/me/" , response_model = User ) async def read_users_me ( current_user : User = Depends ( ... bw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW" , "disabled" : False , } } class Token ( BaseModel ): access_token : str token_type : str class TokenData ( BaseModel ): username : str | None = None class User ( BaseModel ): username : str email : str | N ...
https://man.mtool.work/fastapi/0.115/tutorial/security/oauth2-jwt/
WebSocket 9325
WebSocket FastAPI で WebSocket が使用できます。 WebSockets のインストール まず WebSockets のインストールが必要です。 $ pip install websockets ---> 100% WebSocket クライアント 本番環境 本番環境では、React、Vue.js、Angularなどの最新のフレーム ... n 3.8+ from fastapi import FastAPI , WebSocket from fastapi.responses import HTMLResponse app = FastAPI () html = """ <!DOCTYPE html> <html> <head> <title>Chat</title> </head> <body> <h1>WebSocket Chat</h1> <form action="" onsubmit="sendMessage(event ... )"> <input type="text" id="messageText" autocomplete="off"/> <button>Send</button> </form> <ul id='messages'> </ul> <script> var ws = new ... n 3.8+ from fastapi import FastAPI , WebSocket from fastapi.responses import HTMLResponse app = FastAPI () html = """ <!DOCTYPE html> <html> <head> <title>Chat</title> </head> <body> <h1>WebSocket Chat</h1> <form action="" onsubmit="sendMessage(event ...
https://man.mtool.work/fastapi/0.115/advanced/websockets/
Simple OAuth2 with Password and Bearer 9139
Simple OAuth2 with Password and Bearer Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Now let's build from the previous chapter and add the missing parts to have ... pes" separated by spaces. Each "scope" is just a string (without spaces). They are normally used to declare specific security permissions, for example: users:read or users:write are common examples. instagram_basic is used by Facebook / Instagram. ht ... ption ( status_code = 400 , detail = "Incorrect username or password" ) return { "access_token" : user . username , "token_type" : "bearer" } @app . get ( "/users/me" ) async def read_users_me ( current_user : Annotated [ User , Depends ( get_current ... ption ( status_code = 400 , detail = "Incorrect username or password" ) return { "access_token" : user . username , "token_type" : "bearer" } @app . get ( "/users/me" ) async def read_users_me ( current_user : Annotated [ User , Depends ( get_current ...
https://man.mtool.work/fastapi/0.115/tutorial/security/simple-oauth2/
カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス 8812
カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。 レスポンスを直接返す で見たように、 Response を直接返すことでこの挙動をオーバーライドできます。 しか ... と、データは自動的に変換されず、ドキュメントも自動生成されません (例えば、生成されるOpenAPIの一部としてHTTPヘッダー Content-Type に特定の「メディアタイプ」を含めるなど) 。 しかし、 path operationデコレータ に、使いたい Response を宣言することもできます ... タ response_class は、レスポンスの「メディアタイプ」を定義するために利用することもできます。 この場合、HTTPヘッダー Content-Type には application/json がセットされます。 そして、OpenAPIにはそのようにドキュメントされます。 豆知識 ORJSONResponse は、現在 ... I からHTMLを直接返す場合は、 HTMLResponse を使います。 HTMLResponse をインポートする。 path operation のパラメータ content_type に HTMLResponse を渡す。 Python 3.8+ from fastapi import FastAPI from fastapi.responses import HTMLResponse app = FastAPI ...
https://man.mtool.work/fastapi/0.115/advanced/custom-response/
GraphQL 8377
GraphQL Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . As FastAPI is based on the ASGI standard, it's very easy to integrate any GraphQL library also compatible w ... k with GraphQL , Strawberry is the recommended library as it has the design closest to FastAPI's design, it's all based on type annotations . Depending on your use case, you might prefer to use a different library, but if you asked me, I would probab ... tAPI: Python 3.8+ import strawberry from fastapi import FastAPI from strawberry.fastapi import GraphQLRouter @strawberry . type class User : name : str age : int @strawberry . type class Query : @strawberry . field def user ( self ) -> User : return ... almost identical interface . Tip If you need GraphQL, I still would recommend you check out Strawberry , as it's based on type annotations instead of custom classes and types. Learn More You can learn more about GraphQL in the official GraphQL docum ...
https://man.mtool.work/fastapi/0.115/how-to/graphql/
PREV 1 2 3 4 5 NEXT