Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 622 for Depends (0.21 sec)

  1. tests/test_generic_parameterless_depends.py

    from typing import TypeVar
    
    from fastapi import Depends, FastAPI
    from fastapi.testclient import TestClient
    from typing_extensions import Annotated
    
    app = FastAPI()
    
    T = TypeVar("T")
    
    Dep = Annotated[T, Depends()]
    
    
    class A:
        pass
    
    
    class B:
        pass
    
    
    @app.get("/a")
    async def a(dep: Dep[A]):
        return {"cls": dep.__class__.__name__}
    
    
    @app.get("/b")
    async def b(dep: Dep[B]):
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Tue Apr 02 02:52:56 GMT 2024
    - 1.8K bytes
    - Viewed (0)
  2. tests/test_ws_router.py

    
    @router.websocket("/depends-err/")
    async def router_ws_depends_err(websocket: WebSocket, data=Depends(ws_dependency_err)):
        pass  # pragma: no cover
    
    
    async def ws_dependency_validate(x_missing: str = Header()):
        pass  # pragma: no cover
    
    
    @router.websocket("/depends-validate/")
    async def router_ws_depends_validate(
        websocket: WebSocket, data=Depends(ws_dependency_validate)
    ):
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Sun Jun 11 19:08:14 GMT 2023
    - 7.5K bytes
    - Viewed (0)
  3. tests/test_dependency_overrides.py

    @app.get("/decorator-depends/", dependencies=[Depends(common_parameters)])
    async def decorator_depends():
        return {"in": "decorator-depends"}
    
    
    @router.get("/router-depends/")
    async def router_depends(commons: dict = Depends(common_parameters)):
        return {"in": "router-depends", "params": commons}
    
    
    @router.get("/router-decorator-depends/", dependencies=[Depends(common_parameters)])
    async def router_decorator_depends():
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:40:57 GMT 2024
    - 15.4K bytes
    - Viewed (0)
  4. fastapi/dependencies/utils.py

    
    def get_parameterless_sub_dependant(*, depends: params.Depends, path: str) -> Dependant:
        assert callable(
            depends.dependency
        ), "A parameter-less dependency must have a callable dependency"
        return get_sub_dependant(depends=depends, dependency=depends.dependency, path=path)
    
    
    def get_sub_dependant(
        *,
        depends: params.Depends,
        dependency: Callable[..., Any],
        path: str,
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Tue Apr 02 02:52:56 GMT 2024
    - 29.5K bytes
    - Viewed (0)
  5. docs_src/sql_databases/sql_app_py310/main.py

        db_user = crud.get_user_by_email(db, email=user.email)
        if db_user:
            raise HTTPException(status_code=400, detail="Email already registered")
        return crud.create_user(db=db, user=user)
    
    
    @app.get("/users/", response_model=list[schemas.User])
    def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
        users = crud.get_users(db, skip=skip, limit=limit)
        return users
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Fri Jan 07 14:11:31 GMT 2022
    - 1.6K bytes
    - Viewed (0)
  6. tests/test_ambiguous_params.py

            return foo
    
        with pytest.raises(
            AssertionError,
            match=(
                "Cannot specify `Depends` in `Annotated` and default value"
                " together for 'foo'"
            ),
        ):
    
            @app.get("/")
            async def get2(foo: Annotated[int, Depends(dep)] = Depends(dep)):
                pass  # pragma: nocover
    
        with pytest.raises(
            AssertionError,
            match=(
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Tue Dec 12 00:22:47 GMT 2023
    - 2.1K bytes
    - Viewed (0)
  7. tests/test_params_repr.py

    def test_body_repr_list():
        assert repr(Body([])) == "Body([])"
    
    
    def test_depends_repr():
        assert repr(Depends()) == "Depends(NoneType)"
        assert repr(Depends(get_user)) == "Depends(get_user)"
        assert repr(Depends(use_cache=False)) == "Depends(NoneType, use_cache=False)"
        assert (
            repr(Depends(get_user, use_cache=False)) == "Depends(get_user, use_cache=False)"
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Fri Jul 07 17:12:13 GMT 2023
    - 3.3K bytes
    - Viewed (0)
  8. docs/zh/docs/tutorial/dependencies/classes-as-dependencies.md

        ```
    
    **FastAPI** 调用 `CommonQueryParams` 类。这将创建该类的一个 "实例",该实例将作为参数 `commons` 被传递给你的函数。
    
    ## 类型注解 vs `Depends`
    
    注意,我们在上面的代码中编写了两次`CommonQueryParams`:
    
    ```Python
    commons: CommonQueryParams = Depends(CommonQueryParams)
    ```
    
    最后的 `CommonQueryParams`:
    
    ```Python
    ... = Depends(CommonQueryParams)
    ```
    
    ...实际上是 **Fastapi** 用来知道依赖项是什么的。
    
    FastAPI 将从依赖项中提取声明的参数,这才是 FastAPI 实际调用的。
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Tue Oct 17 05:59:11 GMT 2023
    - 6.5K bytes
    - Viewed (0)
  9. docs/en/docs/tutorial/dependencies/classes-as-dependencies.md

        ```
    
    === "Python 3.8 non-Annotated"
    
        !!! tip
            Prefer to use the `Annotated` version if possible.
    
        ```Python
        commons: CommonQueryParams = Depends()
        ```
    
    You declare the dependency as the type of the parameter, and you use `Depends()` without any parameter, instead of having to write the full class *again* inside of `Depends(CommonQueryParams)`.
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 11.4K bytes
    - Viewed (0)
  10. fastapi/security/api_key.py

        ## Usage
    
        Create an instance object and use that object as the dependency in `Depends()`.
    
        The dependency result will be a string containing the key value.
    
        ## Example
    
        ```python
        from fastapi import Depends, FastAPI
        from fastapi.security import APIKeyQuery
    
        app = FastAPI()
    
        query_scheme = APIKeyQuery(name="api_key")
    
    
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Tue Apr 23 22:29:18 GMT 2024
    - 9.1K bytes
    - Viewed (0)
Back to top