What FastAPI actually checks is that it is a "callable" (function, class or anything else) and the parameters defined.

If you pass a "callable" as a dependency in FastAPI, it will analyze the parameters for that "callable", and process them in the same way as the parameters for a path operation function. Including sub-dependencies.

That also applies to callables with no parameters at all. The same as it would be for path operation functions with no parameters.

Then, we can change the dependency "dependable" common_parameters from above to the class CommonQueryParameters:

In both cases the data will be converted, validated, documented on the OpenAPI schema, etc.

Use it

Now you can declare your dependency using this class.

And as when FastAPI calls that class the value that will be passed as commons to your function will be an "instance" of the class, you can declare that parameter commons to be of type of the class, CommonQueryParams.

But declaring the type is encouraged as that way your editor will know what will be passed as the parameter commons, and then it can help you with code completion, type checks, etc:

Shortcut

But you see that we are having some code repetition here, writing CommonQueryParams twice:

commons:CommonQueryParams=Depends(CommonQueryParams)

FastAPI provides a shortcut for these cases, in where the dependency is specifically a class that FastAPI will "call" to create an instance of the class itself.

For those specific cases, you can do the following:

Instead of writing:

commons:CommonQueryParams=Depends(CommonQueryParams)

...you write:

commons:CommonQueryParams=Depends()

So, you can declare the dependency as the type of the variable, and use Depends() as the "default" value, without any parameter, instead of having to write the full class again inside of Depends(CommonQueryParams).