Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 151 - 160 of 1,038 for Async (0.14 seconds)

  1. docs_src/request_files/tutorial001_03_an_py310.py

    from typing import Annotated
    
    from fastapi import FastAPI, File, UploadFile
    
    app = FastAPI()
    
    
    @app.post("/files/")
    async def create_file(file: Annotated[bytes, File(description="A file read as bytes")]):
        return {"file_size": len(file)}
    
    
    @app.post("/uploadfile/")
    async def create_upload_file(
        file: Annotated[UploadFile, File(description="A file read as UploadFile")],
    ):
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 421 bytes
    - Click Count (0)
  2. docs_src/request_files/tutorial001_02_py310.py

    from fastapi import FastAPI, File, UploadFile
    
    app = FastAPI()
    
    
    @app.post("/files/")
    async def create_file(file: bytes | None = File(default=None)):
        if not file:
            return {"message": "No file sent"}
        else:
            return {"file_size": len(file)}
    
    
    @app.post("/uploadfile/")
    async def create_upload_file(file: UploadFile | None = None):
        if not file:
            return {"message": "No upload file sent"}
        else:
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri May 13 23:38:22 GMT 2022
    - 470 bytes
    - Click Count (0)
  3. tests/test_request_params/test_header/test_required_str.py

    # Without aliases
    
    
    @app.get("/required-str")
    async def read_required_str(p: Annotated[str, Header()]):
        return {"p": p}
    
    
    class HeaderModelRequiredStr(BaseModel):
        p: str
    
    
    @app.get("/model-required-str")
    async def read_model_required_str(p: Annotated[HeaderModelRequiredStr, Header()]):
        return {"p": p.p}
    
    
    @pytest.mark.parametrize(
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sun Feb 08 10:18:38 GMT 2026
    - 10.3K bytes
    - Click Count (0)
  4. tests/test_request_params/test_file/test_list.py

    # Without aliases
    
    
    @app.post("/list-bytes", operation_id="list_bytes")
    async def read_list_bytes(p: Annotated[list[bytes], File()]):
        return {"file_size": [len(file) for file in p]}
    
    
    @app.post("/list-uploadfile", operation_id="list_uploadfile")
    async def read_list_uploadfile(p: Annotated[list[UploadFile], File()]):
        return {"file_size": [file.size for file in p]}
    
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sat Feb 21 13:01:31 GMT 2026
    - 11.6K bytes
    - Click Count (0)
  5. docs_src/events/tutorial003_py310.py

        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)
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 569 bytes
    - Click Count (0)
  6. tests/test_dependency_after_yield_websockets.py

    BrokenSessionDep = Annotated[Session, Depends(broken_dep_session)]
    
    app = FastAPI()
    
    
    @app.websocket("/ws")
    async def websocket_endpoint(websocket: WebSocket, session: SessionDep):
        await websocket.accept()
        for item in session:
            await websocket.send_text(f"{item}")
    
    
    @app.websocket("/ws-broken")
    async def websocket_endpoint_broken(websocket: WebSocket, session: BrokenSessionDep):
        await websocket.accept()
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Dec 17 21:25:59 GMT 2025
    - 2K bytes
    - Click Count (0)
  7. tests/test_stringified_annotation_dependency_py314.py

    
    @needs_py314
    def test_stringified_annotation():
        # python3.14: Use forward reference without "from __future__ import annotations"
        async def get_current_user() -> DummyUser | None:
            return None
    
        app = FastAPI()
    
        client = TestClient(app)
    
        @app.get("/")
        async def get(
            current_user: Annotated[DummyUser | None, Depends(get_current_user)],
        ) -> str:
            return "hello world"
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Wed Feb 04 13:49:44 GMT 2026
    - 711 bytes
    - Click Count (0)
  8. tests/test_request_params/test_cookie/test_optional_str.py

    # Without aliases
    
    
    @app.get("/optional-str")
    async def read_optional_str(p: Annotated[str | None, Cookie()] = None):
        return {"p": p}
    
    
    class CookieModelOptionalStr(BaseModel):
        p: str | None = None
    
    
    @app.get("/model-optional-str")
    async def read_model_optional_str(p: Annotated[CookieModelOptionalStr, Cookie()]):
        return {"p": p.p}
    
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Tue Feb 17 09:59:14 GMT 2026
    - 8.6K bytes
    - Click Count (0)
  9. tests/test_param_include_in_schema.py

    from fastapi.testclient import TestClient
    from inline_snapshot import snapshot
    
    app = FastAPI()
    
    
    @app.get("/hidden_cookie")
    async def hidden_cookie(
        hidden_cookie: str | None = Cookie(default=None, include_in_schema=False),
    ):
        return {"hidden_cookie": hidden_cookie}
    
    
    @app.get("/hidden_header")
    async def hidden_header(
        hidden_header: str | None = Header(default=None, include_in_schema=False),
    ):
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Tue Feb 17 09:59:14 GMT 2026
    - 8.6K bytes
    - Click Count (0)
  10. docs_src/security/tutorial002_py310.py

    def fake_decode_token(token):
        return User(
            username=token + "fakedecoded", email="******@****.***", full_name="John Doe"
        )
    
    
    async def get_current_user(token: str = Depends(oauth2_scheme)):
        user = fake_decode_token(token)
        return user
    
    
    @app.get("/users/me")
    async def read_users_me(current_user: User = Depends(get_current_user)):
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Jan 07 14:11:31 GMT 2022
    - 711 bytes
    - Click Count (0)
Back to Top