Results of 1 - 10 of about 11 for self (0.003 sec.)
- 依存関係としてのクラス 12429
- 依存関係としてのクラス 依存性注入 システムを深く掘り下げる前に、先ほどの例をアップグレードしてみましょう。 前の例の dict 前の例では、依存関係("dependable")から dict を返していました: Python 3.8+ - non-Annotated from typing import Union fr
...のクラスのインスタンスを作成する際に、同じ構文を使用していることに気づくかもしれません。 例えば: class Cat : def __init__ ( self , name : str ): self . name = name fluffy = Cat ( name = "Mr Fluffy" ) この場合、 fluffy は Cat クラスのインスタンスです。..._db = [{ "item_name" : "Foo" }, { "item_name" : "Bar" }, { "item_name" : "Baz" }] class CommonQueryParams : def __init__ ( self , q : Union [ str , None ] = None , skip : int = 0 , limit : int = 100 ): self . q = q self . skip = skip self . limit = l..._db = [{ "item_name" : "Foo" }, { "item_name" : "Bar" }, { "item_name" : "Baz" }] class CommonQueryParams : def __init__ ( self , q : str | None = None , skip : int = 0 , limit : int = 100 ): self . q = q self . skip = skip self . limit = limit @app... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/classes-as-dependenci...
- Advanced Dependencies 12216
- Advanced Dependencies Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Parameterized dependencies All the dependencies we have seen are a fixed function or class. B
...fixed content. A "callable" instance In Python there's a way to make an instance of a class a "callable". Not the class itself (which is already a callable), but an instance of that class. To do that, we declare a method __call__ : Python 3.9+ from...ng import Annotated from fastapi import Depends , FastAPI app = FastAPI () class FixedContentQueryChecker : def __init__ ( self , fixed_content : str ): self . fixed_content = fixed_content def __call__ ( self , q : str = "" ): if q : return self . f...Depends , FastAPI from typing_extensions import Annotated app = FastAPI () class FixedContentQueryChecker : def __init__ ( self , fixed_content : str ): self . fixed_content = fixed_content def __call__ ( self , q : str = "" ): if q : return self . f... - https://man.mtool.work/fastapi/0.115/advanced/advanced-dependencies/
- Custom Request and APIRoute class 10028
- Custom Request and APIRoute class Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In some cases, you may want to override the logic used by the Request and APIRout
...t Body , FastAPI , Request , Response from fastapi.routing import APIRoute class GzipRequest ( Request ): async def body ( self ) -> bytes : if not hasattr ( self , "_body" ): body = await super () . body () if "gzip" in self . headers . getlist ( "C...ontent-Encoding" ): body = gzip . decompress ( body ) self . _body = body return self . _body class GzipRoute ( APIRoute ): def get_route_handler ( self ) -> Callable : original_rou...t Body , FastAPI , Request , Response from fastapi.routing import APIRoute class GzipRequest ( Request ): async def body ( self ) -> bytes : if not hasattr ( self , "_body" ): body = await super () . body () if "gzip" in self . headers . getlist ( "C... - https://man.mtool.work/fastapi/0.115/how-to/custom-request-and-route/
- WebSocket 9068
- WebSocket FastAPI で WebSocket が使用できます。 WebSockets のインストール まず WebSockets のインストールが必要です。 $ pip install websockets ---> 100% WebSocket クライアント 本番環境 本番環境では、React、Vue.js、Angularなどの最新のフレーム
...ut.value) input.value = '' event.preventDefault() } </script> </body> </html> """ class ConnectionManager : def __init__ ( self ): self . active_connections : List [ WebSocket ] = [] async def connect ( self , websocket : WebSocket ): await websocket.... accept () self . active_connections . append ( websocket ) def disconnect ( self , websocket : WebSocket ): self . active_connections . r...emove ( websocket ) async def send_personal_message ( self , message : str , websocket : WebSocket ): await websocket . send_text ( message ) async def broadcast ( self , message :... - https://man.mtool.work/fastapi/0.115/advanced/websockets/
- yieldを持つ依存関係 8072
- yieldを持つ依存関係 FastAPIは、いくつかの 終了後の追加のステップ を行う依存関係をサポートしています。 これを行うには、 return の代わりに yield を使い、その後に追加のステップを書きます。 豆知識 yield は必ず一度だけ使用するようにしてください。
...ld を持つ FastAPI の依存関係の中でそれらを使用することができます: Python 3.8+ class MySuperContextManager : def __init__ ( self ): self . db = DBSession () def __enter__ ( self ): return self . db def __exit__ ( self , exc_type , exc_value , tracebac...k ): self . db . close () async def get_db (): with MySuperContextManager () as db : yield db 豆知識 コンテキストマネージャを作成する... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-with-yie...
- Pythonの型の紹介 7823
- Pythonの型の紹介 Python 3.6以降 では「型ヒント」オプションがサポートされています。 これらの "型ヒント" は変数の 型 を宣言することができる新しい構文です。(Python 3.6以降) 変数に型を宣言することでエディターやツールがより良いサポートを提供す
...言することもできます。 例えば、 Person クラスという名前のクラスがあるとしましょう: Python 3.8+ class Person : def __init__ ( self , name : str ): self . name = name def get_person_name ( one_person : Person ): return one_person . name 変数の型を Person...として宣言することができます: Python 3.8+ class Person : def __init__ ( self , name : str ): self . name = name def get_person_name ( one_person : Person ): return one_person . name そして、再び、すべ... - https://man.mtool.work/fastapi/0.115/python-types/
- Custom Docs UI Static Assets (Self-Hosting) 7735
- Custom Docs UI Static Assets (Self-Hosting) Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . The API docs use Swagger UI and ReDoc , and each of those need some Jav
...those files are served from a CDN . But it's possible to customize it, you can set a specific CDN, or serve the files yourself. Custom CDN for JavaScript and CSS Let's say that you want to use a different CDN , for example you want to use https://un...e able to go to your docs at http://127.0.0.1:8000/docs , and reload the page, it will load those assets from the new CDN. Self-hosting JavaScript and CSS for docs Self-hosting the JavaScript and CSS could be useful if, for example, you need your app...king even while offline, without open Internet access, or in a local network. Here you'll see how to serve those files yourself, in the same FastAPI app, and configure the docs to use them. Project file structure Let's say your project file structure... - https://man.mtool.work/fastapi/0.115/how-to/custom-docs-ui-assets/
- GraphQL 7681
- 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
...outer @strawberry . type class User : name : str age : int @strawberry . type class Query : @strawberry . field def user ( self ) -> User : return User ( name = "Patrick" , age = 100 ) schema = strawberry . Schema ( query = Query ) graphql_app = Grap... - https://man.mtool.work/fastapi/0.115/how-to/graphql/
- Configure Swagger UI 7646
- Configure Swagger UI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can configure some extra Swagger UI parameters . To configure them, pass the swagger_ui_pa
...TML that loads Swagger UI for the interactive API docs (normally served at `/docs`). You would only call this function yourself if you needed to override some parts, for example the URLs to use to load Swagger UI's JavaScript and CSS. Read more about...ger UI](https://fastapi.tiangolo.com/how-to/configure-swagger-ui/) and the [FastAPI docs for Custom Docs UI Static Assets (Self-Hosting)](https://fastapi.tiangolo.com/how-to/custom-docs-ui-assets/). """ current_swagger_ui_parameters = swagger_ui_defa...esponse that loads ReDoc for the alternative API docs (normally served at `/redoc`). You would only call this function yourself if you needed to override some parts, for example the URLs to use to load ReDoc's JavaScript and CSS. Read more about it i... - https://man.mtool.work/fastapi/0.115/how-to/configure-swagger-ui/
- エラーハンドリング 7592
- エラーハンドリング APIを使用しているクライアントにエラーを通知する必要がある状況はたくさんあります。 このクライアントは、フロントエンドを持つブラウザ、誰かのコード、IoTデバイスなどが考えられます。 クライアントに以下のようなことを伝える必要が
...i import FastAPI , Request from fastapi.responses import JSONResponse class UnicornException ( Exception ): def __init__ ( self , name : str ): self . name = name app = FastAPI () @app . exception_handler ( UnicornException ) async def unicorn_except... - https://man.mtool.work/fastapi/0.115/tutorial/handling-errors/