How it works¶
At first, I suppose, we need to discuss about this tool's key concept.
It is very simple:
- At your code's initialization time
FastDepends
builds special pydantic model with your function's expected arguments as a model fields, builds the dependencies graph - At runtime
FastDepends
grabs all incoming functions'*args, **kwargs
and initializes functions' representation models with them - At the next step
FastDepends
execute functions' dependensies with the model fields as an arguments, calls the original function - Finally,
FastDepends
catches functions' outputs and casts it to expectedreturn
type
This is pretty close to the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
Note
It is not the real code, but generally FastDepends
works this way
So, the biggest part of the FastDepends
code execution happens on application startup. At runtime the library just casts types to already built models. It works really fast. Generally, the library works with the same speed as the pydantic
- the main dependency.
On the other hand, working with only *args, **kwargs
allows the library to be independent from other frameworks, business domains, technologies, etc. You are free to decide for yourself, how exactly to use this tool.