From b921ffcf912b7d701c0e098bfc79492ae96517ce Mon Sep 17 00:00:00 2001 From: <> Date: Tue, 27 Feb 2024 14:04:39 +0000 Subject: [PATCH] Deployed ae8f14c with MkDocs version: 1.5.3 --- .nojekyll | 0 404.html | 1 + advanced/index.html | 83 + advanced/starlette/index.html | 135 + alternatives/index.html | 1 + assets/images/favicon.png | Bin 0 -> 1870 bytes assets/javascripts/bundle.8fd75fb4.min.js | 29 + assets/javascripts/bundle.8fd75fb4.min.js.map | 7 + assets/javascripts/custom.js | 180 + assets/javascripts/lunr/min/lunr.ar.min.js | 1 + assets/javascripts/lunr/min/lunr.da.min.js | 18 + assets/javascripts/lunr/min/lunr.de.min.js | 18 + assets/javascripts/lunr/min/lunr.du.min.js | 18 + assets/javascripts/lunr/min/lunr.el.min.js | 1 + assets/javascripts/lunr/min/lunr.es.min.js | 18 + assets/javascripts/lunr/min/lunr.fi.min.js | 18 + assets/javascripts/lunr/min/lunr.fr.min.js | 18 + assets/javascripts/lunr/min/lunr.he.min.js | 1 + assets/javascripts/lunr/min/lunr.hi.min.js | 1 + assets/javascripts/lunr/min/lunr.hu.min.js | 18 + assets/javascripts/lunr/min/lunr.hy.min.js | 1 + assets/javascripts/lunr/min/lunr.it.min.js | 18 + assets/javascripts/lunr/min/lunr.ja.min.js | 1 + assets/javascripts/lunr/min/lunr.jp.min.js | 1 + assets/javascripts/lunr/min/lunr.kn.min.js | 1 + assets/javascripts/lunr/min/lunr.ko.min.js | 1 + assets/javascripts/lunr/min/lunr.multi.min.js | 1 + assets/javascripts/lunr/min/lunr.nl.min.js | 18 + assets/javascripts/lunr/min/lunr.no.min.js | 18 + assets/javascripts/lunr/min/lunr.pt.min.js | 18 + assets/javascripts/lunr/min/lunr.ro.min.js | 18 + assets/javascripts/lunr/min/lunr.ru.min.js | 18 + assets/javascripts/lunr/min/lunr.sa.min.js | 1 + .../lunr/min/lunr.stemmer.support.min.js | 1 + assets/javascripts/lunr/min/lunr.sv.min.js | 18 + assets/javascripts/lunr/min/lunr.ta.min.js | 1 + assets/javascripts/lunr/min/lunr.te.min.js | 1 + assets/javascripts/lunr/min/lunr.th.min.js | 1 + assets/javascripts/lunr/min/lunr.tr.min.js | 18 + assets/javascripts/lunr/min/lunr.vi.min.js | 1 + assets/javascripts/lunr/min/lunr.zh.min.js | 1 + assets/javascripts/lunr/tinyseg.js | 206 + assets/javascripts/lunr/wordcut.js | 6708 +++++++++++++++++ assets/javascripts/termynal.js | 264 + .../workers/search.b8dbb3d2.min.js | 42 + .../workers/search.b8dbb3d2.min.js.map | 7 + assets/stylesheets/custom.css | 146 + assets/stylesheets/main.7e359304.min.css | 1 + assets/stylesheets/main.7e359304.min.css.map | 1 + assets/stylesheets/palette.06af60db.min.css | 1 + .../stylesheets/palette.06af60db.min.css.map | 1 + assets/stylesheets/termynal.css | 109 + contributing/index.html | 10 + index.html | 115 + search/search_index.json | 1 + sitemap.xml | 68 + sitemap.xml.gz | Bin 0 -> 317 bytes tutorial/annotated/index.html | 149 + tutorial/classes/index.html | 146 + tutorial/index.html | 188 + tutorial/overrides/index.html | 85 + tutorial/validations/index.html | 12 + tutorial/yield/index.html | 40 + usages/index.html | 71 + works/index.html | 62 + 65 files changed, 9156 insertions(+) create mode 100644 .nojekyll create mode 100644 404.html create mode 100644 advanced/index.html create mode 100644 advanced/starlette/index.html create mode 100644 alternatives/index.html create mode 100644 assets/images/favicon.png create mode 100644 assets/javascripts/bundle.8fd75fb4.min.js create mode 100644 assets/javascripts/bundle.8fd75fb4.min.js.map create mode 100644 assets/javascripts/custom.js create mode 100644 assets/javascripts/lunr/min/lunr.ar.min.js create mode 100644 assets/javascripts/lunr/min/lunr.da.min.js create mode 100644 assets/javascripts/lunr/min/lunr.de.min.js create mode 100644 assets/javascripts/lunr/min/lunr.du.min.js create mode 100644 assets/javascripts/lunr/min/lunr.el.min.js create mode 100644 assets/javascripts/lunr/min/lunr.es.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.he.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hu.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hy.min.js create mode 100644 assets/javascripts/lunr/min/lunr.it.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ja.min.js create mode 100644 assets/javascripts/lunr/min/lunr.jp.min.js create mode 100644 assets/javascripts/lunr/min/lunr.kn.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ko.min.js create mode 100644 assets/javascripts/lunr/min/lunr.multi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.nl.min.js create mode 100644 assets/javascripts/lunr/min/lunr.no.min.js create mode 100644 assets/javascripts/lunr/min/lunr.pt.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ro.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ru.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sa.min.js create mode 100644 assets/javascripts/lunr/min/lunr.stemmer.support.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sv.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ta.min.js create mode 100644 assets/javascripts/lunr/min/lunr.te.min.js create mode 100644 assets/javascripts/lunr/min/lunr.th.min.js create mode 100644 assets/javascripts/lunr/min/lunr.tr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.vi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.zh.min.js create mode 100644 assets/javascripts/lunr/tinyseg.js create mode 100644 assets/javascripts/lunr/wordcut.js create mode 100644 assets/javascripts/termynal.js create mode 100644 assets/javascripts/workers/search.b8dbb3d2.min.js create mode 100644 assets/javascripts/workers/search.b8dbb3d2.min.js.map create mode 100644 assets/stylesheets/custom.css create mode 100644 assets/stylesheets/main.7e359304.min.css create mode 100644 assets/stylesheets/main.7e359304.min.css.map create mode 100644 assets/stylesheets/palette.06af60db.min.css create mode 100644 assets/stylesheets/palette.06af60db.min.css.map create mode 100644 assets/stylesheets/termynal.css create mode 100644 contributing/index.html create mode 100644 index.html create mode 100644 search/search_index.json create mode 100644 sitemap.xml create mode 100644 sitemap.xml.gz create mode 100644 tutorial/annotated/index.html create mode 100644 tutorial/classes/index.html create mode 100644 tutorial/index.html create mode 100644 tutorial/overrides/index.html create mode 100644 tutorial/validations/index.html create mode 100644 tutorial/yield/index.html create mode 100644 usages/index.html create mode 100644 works/index.html 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..57bd50a --- /dev/null +++ b/404.html @@ -0,0 +1 @@ +
Packages developers
This is the part of documentation will talks you about some features, that can be helpful 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 exceptions.
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 with opportunity to use FastAPI Depends
and typecasting everywhere.
Sometimes, more complex tools are required. In these cases I can recommend 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 Va=/["'&<>]/;qn.exports=za;function za(e){var t=""+e,r=Va.exec(t);if(!r)return t;var o,n="",i=0,s=0;for(i=r.index;i