diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..ea35ed0 --- /dev/null +++ b/404.html @@ -0,0 +1,681 @@ + + + +
+ + + + + + + + + + + + + + + + +Packages developers
+This is the part of documentation will talks you about some features, that can be helpfull to develop your own packages with FastDepends
If you wish to write your own FastAPI or another closely by architecture tool, you +should define your own custom fields to specify application behavior. At FastAPI these fields are:
+Custom fields can be used to adding something specific to a function arguments (like a BackgroundTask) or +parsing incoming objects special way. You able decide by own, why and how you will use these tools.
+FastDepends
grants you this opportunity a very intuitive and comfortable way.
As an example, will try to implement FastAPI Header field
+1 +2 +3 +4 +5 +6 +7 |
|
Just import fast_depends.library.CustomField
and implements use
(async or sync) method.
+That's all. We already have own Header field to parse kwargs the special way.
Now we already can use the Header field
+1 +2 +3 +4 +5 +6 +7 +8 +9 |
|
As we defined, Header parse incoming headers kwargs field, get a parameter by name and put it to +original function as an argument.
+CustomField
has some fields you should know about
class CustomField:
+ param_name: str
+ cast: bool
+ required: bool
+
param_name
- an original function argument name to replace by your field instance. It was header_field
at the example above.required
- if CustomField is required, raises pydantic.error_wrappers.ValidationError
if it is not present at final kwargscast
- specify the typecasting behavior. Use False to disable pydantic typecasting for fields using with your CustomField1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 |
|
Note
+Pydantic understands only python-native annotation or Pydantic classes. If users will annotate your fields by other classes,
+you should set cast=False
to avoid pydantic exeptions.
def use(self, **kwargs: AnyDict) -> AnyDict: ...
+
Your CustimField objects receive casted to kwargs an original function incoming arguments at use
method.
+Returning from the use
method dict replace an original one. Original function will be executed with a returned from your fields kwargs.
+Be accurate with.
And one more time:
+1 +2 +3 +4 +5 +6 +7 +8 +9 |
|
I hope it was clearly enough right now.
+Also, custom fields using according their definition: from left to right. +Next Custom Fields kwargs is a return of previous.
+An example:
+1 +2 |
|
field2 incoming kwargs is an output of field1.use()
+ + + + + + +Now we take the starlette example from usages and specify it to use Path now.
+First of all, Starlette pass to a handler the only one argument - request
+To use them with FastDepends
we need unwrap request
to kwargs.
1 +2 +3 +4 +5 +6 +7 +8 +9 |
|
Also, we wraps an original handler to fast_depends.inject
too at 3 line
Next step, define Path custom field
+1 +2 +3 +4 +5 +6 +7 +8 +9 |
|
And use it at our Starlette application: +
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 |
|
Depends is working as expected too
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 |
|
As an Annotated does +
1 +2 +3 |
|
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 |
|
The code above works "as it". You can copy it and declare other Header, Cookie, Query fields by yourself. Just try, it's fun!
+ + + + + + +FastDepend
is a very small toolkit to achieve one point: provide you opportunity
+to use FastAPI Depends
and typecasting everywhere.
Sometimes, more complex tools are required. In these cases I can reccomend you to take a look at +the following projects
+di
is a modern dependency injection toolkit, modeled around the simplicity of FastAPI's
+dependency injection.
Key features:
+di
also supports auto-wiring using type annotationspytest scopes
, but defined by usersdi
can execute dependencies in parallel and cache results ins scopes.Dependency Injector is a dependency injection framework for Python.
+It helps implementing the dependency injection principle.
+Key features:
+{"use strict";/*!
+ * escape-html
+ * Copyright(c) 2012-2013 TJ Holowaychuk
+ * Copyright(c) 2015 Andreas Lubbe
+ * Copyright(c) 2015 Tiancheng "Timothy" Gu
+ * MIT Licensed
+ */var $a=/["'&<>]/;Un.exports=Ra;function Ra(e){var t=""+e,r=$a.exec(t);if(!r)return t;var o,n="",i=0,s=0;for(i=r.index;i