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
FastDependsbuilds special pydantic model with your function's expected arguments as a model fields, builds the dependencies graph - At runtime
FastDependsgrabs all incoming functions'*args, **kwargsand initializes functions' representation models with them - At the next step
FastDependsexecute functions' dependensies with the model fields as an arguments, calls the original function - Finally,
FastDependscatches functions' outputs and casts it to expectedreturntype
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 32 | |
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.