Results of 1 - 10 of about 17 for something (0.003 sec.)
- Lifespan Events 11380
- Lifespan Events Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can define logic (code) that should be executed before the application starts up . This means t
...se to handle requests. ? The same models are shared among requests, so, it's not one model per request, or one per user or something similar. Let's imagine that loading the model can take quite some time , because it has to read a lot of data from disk ....ync Context Manager If you check, the function is decorated with an @asynccontextmanager . That converts the function into something called an " async context manager ". Python 3.8+ from contextlib import asynccontextmanager from fastapi import FastAPI de...: float ): result = ml_models [ "answer_to_everything" ]( x ) return { "result" : result } A context manager in Python is something that you can use in a with statement, for example, open() can be used as a context manager: with open ( "file.txt" ) as fi... - https://man.mtool.work/fastapi/0.115/advanced/events/
- HTTP Basic Auth 10897
- HTTP Basic Auth Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . For the simplest cases, you can use HTTP Basic Auth. In HTTP Basic Auth, the application expects a
...a request with a username johndoe and a password love123 . Then the Python code in your application would be equivalent to something like: if "johndoe" == "stanleyjobson" and "love123" == "swordfish" : ... But right at the moment Python compares the first...or password". But then the attackers try with username stanleyjobsox and password love123 . And your application code does something like: if "stanleyjobsox" == "stanleyjobson" and "love123" == "swordfish" : ... Python will have to compare the whole stanl...took some microseconds longer to send the "Incorrect username or password" response, the attackers will know that they got something right, some of the initial letters were right. And then they can try again knowing that it's probably something more simil... - https://man.mtool.work/fastapi/0.115/advanced/security/http-basic-auth/
- Repository Management Tasks 10897
- Repository Management Tasks These are the tasks that can be performed to manage the FastAPI repository by team members . Tip This section is useful only to a handful of people, team members with permissions to manage the repository. You can
...ject (discussion, PR), just thank them for being interested in the project, or for having dedicated some time to try to do something. It's difficult to convey emotion in text, use emojis to help. ? In discussions and PRs, in many cases, people bring their...breath, and be gentle with your answers. Try to avoid using bitter sarcasm or potentially passive-aggressive comments. If something is wrong, it's better to be direct (try to be gentle) than sarcastic. Try to be as specific and objective as possible, avo...uld almost never be used. feature : Features New features, adding support for things that didn't exist before. bug : Fixes Something that was supported didn't work, and this fixes it. There are many PRs that claim to be bug fixes because the user is doing... - https://man.mtool.work/fastapi/0.115/management-tasks/
- Behind a Proxy 10656
- Behind a Proxy Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In some situations, you might need to use a proxy server like Traefik or Nginx with a configuration
...stuff here "servers" : [ { "url" : "/api/v1" } ], "paths" : { // More stuff here } } In this example, the "Proxy" could be something like Traefik . And the server would be something like FastAPI CLI with Uvicorn , running your FastAPI application. Providi...n style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) The response would be something like: { "message" : "Hello World" , "root_path" : "/api/v1" } Setting the root_path in the FastAPI app Alternatively, if y...proxy doesn't have a stripped path prefix. In a case like that (without a stripped path prefix), the proxy would listen on something like https://myawesomeapp.com , and then if the browser goes to https://myawesomeapp.com/api/v1/app and your server (e.g.... - https://man.mtool.work/fastapi/0.115/advanced/behind-a-proxy/
- Advanced Middleware 10414
- Advanced Middleware Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In the main tutorial you read how to add Custom Middleware to your application. And then you al
...SGI app as the first argument. So, in the documentation for third-party ASGI middlewares they will probably tell you to do something like: from unicorn import UnicornMiddleware app = SomeASGIApp () new_app = UnicornMiddleware ( app , some_config = "rainbo...ses, we'll see next how to use them. Technical Details For the next examples, you could also use from starlette.middleware.something import SomethingMiddleware . FastAPI provides several middlewares in fastapi.middleware just as a convenience for you, the... - https://man.mtool.work/fastapi/0.115/advanced/middleware/
- How To - Recipes 10155
- How To - Recipes Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Here you will see different recipes or "how to" guides for several topics . Most of these ideas wo
...ore or less independent , and in most cases you should only need to study them if they apply directly to your project . If something seems interesting and useful to your project, go ahead and check it, but otherwise, you might probably just skip them. Tip... - https://man.mtool.work/fastapi/0.115/how-to/
- Virtual Environments 9190
- Virtual Environments Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . When you work in Python projects you probably should use a virtual environment (or a similar m
.... And you would probably end up running some projects with some incompatible versions of the packages, and not knowing why something isn't working. Also, depending on your operating system (e.g. Linux, Windows, macOS), it could have come with Python alrea...tem would look for programs in: C:\Windows\System32 After activating the virtual environment, the PATH variable would look something like this: Linux, macOS Windows /home/user/code/awesome-project/.venv/bin:/usr/bin:/bin:/usr/sbin:/sbin That means that th...an many developers out there. ? Knowing these details will most probably be useful in a future time when you are debugging something that seems complex, but you will know how it all works underneath . ?... - https://man.mtool.work/fastapi/0.115/virtual-environments/
- OpenAPI Callbacks 8448
- OpenAPI Callbacks Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You could create an API with a path operation that could trigger a request to an external API cre
...ocumentation part. Tip The actual callback is just an HTTP request. When implementing the callback yourself, you could use something like HTTPX or Requests . Write the callback documentation code This code won't be executed in your app, we only need it to...t to the callback_url (the external API ): https://www.external.org/events/invoices/2expen51ve with a JSON body containing something like: { "description" : "Payment celebration" , "paid" : true } and it would expect a response from that external API with... - https://man.mtool.work/fastapi/0.115/advanced/openapi-callbacks/
- 依存関係としてのクラス 8207
- 依存関係としてのクラス 依存性注入 システムを深く掘り下げる前に、先ほどの例をアップグレードしてみましょう。 前の例の dict 前の例では、依存関係("dependable")から dict を返していました: Python 3.8+ - non-Annotated from typing import Union fr
...あることです。 Pythonにおける「 呼び出し可能 」とは、Pythonが関数のように「呼び出す」ことができるものを指します。 そのため、 something オブジェクト(関数ではないかもしれませんが)を持っていて、それを次のように「呼び出す」(実行する)ことができるとします: so...mething () または something ( some_argument , some_keyword_argument = "foo" ) これを「呼び出し可能」なものと呼びます。 依存関係としてのクラス Pythonの... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/classes-as-dependenci...
- エラーハンドリング 7966
- エラーハンドリング APIを使用しているクライアントにエラーを通知する必要がある状況はたくさんあります。 このクライアントは、フロントエンドを持つブラウザ、誰かのコード、IoTデバイスなどが考えられます。 クライアントに以下のようなことを伝える必要が
..., exc : UnicornException ): return JSONResponse ( status_code = 418 , content = { "message" : f "Oops! { exc . name } did something. There goes a rainbow..." }, ) @app . get ( "/unicorns/ {name} " ) async def read_unicorn ( name : str ): if name == "yolo...HTTPステータスコードが 418 で、JSONの内容が以下のような明確なエラーを受け取ることになります: { "message" : "Oops! yolo did something. There goes a rainbow..." } 技術詳細 また、 from starlette.requests import Request と from starlette.responses import JSON... - https://man.mtool.work/fastapi/0.115/tutorial/handling-errors/