Results of 1 - 10 of about 11 for everything (0.002 sec.)
- Lifespan Events 14225
- 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
...ith yield like this: Python 3.8+ from contextlib import asynccontextmanager from fastapi import FastAPI def fake_answer_to_everything_ml_model ( x : float ): return x * 42 ml_models = {} @asynccontextmanager async def lifespan ( app : FastAPI ): # Load the...ML model ml_models [ "answer_to_everything" ] = fake_answer_to_everything_ml_model yield # Clean up the ML models and release the resources ml_models . clear () app...FastAPI ( lifespan = lifespan ) @app . get ( "/predict" ) async def predict ( x : float ): result = ml_models [ "answer_to_everything" ]( x ) return { "result" : result } Here we are simulating the expensive startup operation of loading the model by puttin... - https://man.mtool.work/fastapi/0.115/advanced/events/
- Virtual Environments 9779
- 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
...This page will teach you how to use virtual environments and how they work. If you are ready to adopt a tool that manages everything for you (including installing Python), try uv . Create a Project First, create a directory for your project. What I normal...the virtual environment is active (the previous command worked). Tip This is optional , but it's a good way to check that everything is working as expected and you are using the virtual environment you intended. Linux, macOS, Windows Bash Windows PowerShe...-m pip install --upgrade pip ---> 100% Add .gitignore If you are using Git (you should), add a .gitignore file to exclude everything in your .venv from Git. Tip If you used uv to create the virtual environment, it already did this for you, you can skip th... - https://man.mtool.work/fastapi/0.115/virtual-environments/
- Sub Applications - Mounts 8926
- Sub Applications - Mounts Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . If you need to have two independent FastAPI applications, with their own independent Open
...cation "Mounting" means adding a completely "independent" application in a specific path, that then takes care of handling everything under that path, with the path operations declared in that sub-application. Top-level application First, create the main,...know to use that path prefix for the docs UI. And the sub-application could also have its own mounted sub-applications and everything would work correctly, because FastAPI handles all these root_path s automatically. You will learn more about the root_path... - https://man.mtool.work/fastapi/0.115/advanced/sub-applications/
- Bigger Applications - Multiple Files 8606
- 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
...can put everything in a single file. FastAPI provides a convenience tool to structure your application while keeping all the flexibility. Inf...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 collection of "Python modules"): app . It conta...app/main.py . Here's where you import and use the class FastAPI . This will be the main file in your application that ties everything together. And as most of your logic will now live in its own specific module, the main file will be quite simple. Import F... - https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/
- Repository Management Tasks 8304
- 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
...probably skip it. ? ...so, you are a team member of FastAPI ? Wow, you are so cool! ? You can help with everything on Help FastAPI - Get Help the same ways as external contributors. But additionally, there are some tasks that only you (a...super nice if you were added to the team, but it's worth mentioning it. ? When Things are Difficult When things are great, everything is easier, so that doesn't need much instructions. But when things are difficult, here are some guidelines. Try to find th... - https://man.mtool.work/fastapi/0.115/management-tasks/
- Custom Docs UI Static Assets (Self-Hosting) 8215
- 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
...d the scenes for you, but it needs this "redirect" helper. Create a path operation to test it Now, to be able to test that everything works, create a path operation : Python 3.8+ from fastapi import FastAPI from fastapi.openapi.docs import ( get_redoc_html...es for you, but it needs this "redirect" helper. Create a path operation to test static files Now, to be able to test that everything works, create a path operation : Python 3.8+ from fastapi import FastAPI from fastapi.openapi.docs import ( get_redoc_html... - https://man.mtool.work/fastapi/0.115/how-to/custom-docs-ui-assets/
- Using Dataclasses 8144
- Using Dataclasses Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . FastAPI is built on top of Pydantic , and I have been showing you how to use Pydantic models to d
...odels. And it is actually achieved in the same way underneath, using Pydantic. Info Keep in mind that dataclasses can't do everything Pydantic models can do. So, you might still need to use Pydantic models. But if you have a bunch of dataclasses laying aro... - https://man.mtool.work/fastapi/0.115/advanced/dataclasses/
- Development - Contributing 7984
- Development - Contributing Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . First, you might want to see the basic ways to help FastAPI and get help . Developing If
...r the newly created directory docs/ht/ . That command created a file docs/ht/mkdocs.yml with a simple config that inherits everything from the en version: INHERIT : ../en/mkdocs.yml Tip You could also simply create that file with those contents manually. T... - https://man.mtool.work/fastapi/0.115/contributing/
- Behind a Proxy 7912
- 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
...at it is being served at /app , so that you don't have to update all your code to include the prefix /api/v1 . Up to here, everything would work as normally. But then, when you open the integrated docs UI (the frontend), it would expect to get the OpenAPI... - https://man.mtool.work/fastapi/0.115/advanced/behind-a-proxy/
- Generate Clients 7912
- Generate Clients 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 OpenAPI specification, you get automatic compatibility with many tools,
...or: Methods. Request payloads in the body, query parameters, etc. Response payloads. You would also have inline errors for everything. And whenever you update the backend code, and regenerate the frontend, it would have any new path operations available as... - https://man.mtool.work/fastapi/0.115/advanced/generate-clients/