From 86dd119d3a421f595179109a53f51d4017648bff Mon Sep 17 00:00:00 2001 From: <> Date: Fri, 27 Sep 2024 08:50:30 +0000 Subject: [PATCH] Deployed a218c04 with MkDocs version: 1.6.0 --- .nojekyll | 0 404.html | 370 + api_docs/index.html | 3154 ++++++++ assets/_mkdocstrings.css | 119 + assets/images/favicon.png | Bin 0 -> 1870 bytes assets/javascripts/bundle.ad660dcc.min.js | 29 + assets/javascripts/bundle.ad660dcc.min.js.map | 7 + 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 +++++++++++++++++ .../workers/search.b8dbb3d2.min.js | 42 + .../workers/search.b8dbb3d2.min.js.map | 7 + assets/stylesheets/main.6543a935.min.css | 1 + assets/stylesheets/main.6543a935.min.css.map | 1 + assets/stylesheets/palette.06af60db.min.css | 1 + .../stylesheets/palette.06af60db.min.css.map | 1 + changelog/index.html | 617 ++ index.html | 1376 ++++ objects.inv | 6 + search/search_index.json | 1 + sitemap.xml | 3 + sitemap.xml.gz | Bin 0 -> 127 bytes 53 files changed, 12936 insertions(+) create mode 100644 .nojekyll create mode 100644 404.html create mode 100644 api_docs/index.html create mode 100644 assets/_mkdocstrings.css create mode 100644 assets/images/favicon.png create mode 100644 assets/javascripts/bundle.ad660dcc.min.js create mode 100644 assets/javascripts/bundle.ad660dcc.min.js.map 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/workers/search.b8dbb3d2.min.js create mode 100644 assets/javascripts/workers/search.b8dbb3d2.min.js.map create mode 100644 assets/stylesheets/main.6543a935.min.css create mode 100644 assets/stylesheets/main.6543a935.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 changelog/index.html create mode 100644 index.html create mode 100644 objects.inv create mode 100644 search/search_index.json create mode 100644 sitemap.xml create mode 100644 sitemap.xml.gz 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..fdbd16c --- /dev/null +++ b/404.html @@ -0,0 +1,370 @@ + + + +
+ + + + + + + + + + + + + + +Connectable
+
+
+You can inherit from this class to make the dependency visible for DI +without adding these empty methods.
+ +src/magic_di/_connectable.py
19 +20 +21 +22 +23 +24 +25 +26 +27 |
|
ConnectableProtocol
+
+
+
+ Bases: Protocol
Interface for injectable clients. +Adding these methods to your class will allow it to be dependency injectable. +The dependency injector uses duck typing to check that the class +implements the interface. +This means that you do not need to inherit from this protocol.
+ +src/magic_di/_connectable.py
4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 +16 |
|
DependencyInjector
+
+
+src/magic_di/_injector.py
65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 |
|
__hash__() -> int
+
+Injector is always unique
+ +src/magic_di/_injector.py
273 +274 +275 |
|
bind(bindings: dict[type, type]) -> None
+
+Bind new bindings to the injector.
+This method is used to add new bindings to the injector. +Bindings are a dictionary where the keys are the +classes used in dependencies type hints, +and the values are the classes that should replace them.
+For example, if you have a class Foo
that depends on an interface Bar
,
+and you have a class BarImpl
that implements Bar
,
+you would add a binding like this: injector.bind({Bar: BarImpl})
.
+Then, whenever Foo
is injected,
+it will receive an instance of BarImpl
instead of Bar
.
If a binding for a particular class or type already exists, +this method will update that binding with the new value
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
bindings |
+
+ dict[type, type]
+ |
+
+
+
+ The bindings to add. + |
+ + required + | +
src/magic_di/_injector.py
221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 |
|
connect() -> None
+
+
+ async
+
+
+Connect all injected dependencies
+ +src/magic_di/_injector.py
141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 |
|
disconnect() -> None
+
+
+ async
+
+
+Disconnect all injected dependencies
+ +src/magic_di/_injector.py
156 +157 +158 +159 +160 +161 +162 +163 +164 +165 |
|
get_dependencies_by_interface(interface: Callable[..., AnyObject]) -> Iterable[AnyObject]
+
+Get all injected dependencies that implement a particular interface.
+ +src/magic_di/_injector.py
167 +168 +169 +170 +171 +172 +173 +174 +175 +176 |
|
inject(obj: Callable[..., T]) -> Callable[..., T]
+
+Inject dependencies into a class/function. +This method is idempotent, always returns the same instance
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
obj |
+
+ Callable[..., T]
+ |
+
+
+
+ The class/function to inject dependencies into. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Callable[..., T]
+ |
+
+
+
+ Callable[..., T]: Partial for class/function with dependencies injected. + |
+
src/magic_di/_injector.py
78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 |
|
lazy_inject(obj: Callable[..., T]) -> Callable[..., T]
+
+Lazily inject dependencies into a class or function.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
obj |
+
+ Callable[..., T]
+ |
+
+
+
+ The class or function to inject dependencies into. + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Callable[..., T]
+ |
+
+
+
+ Callable[..., T]: A function that, when called, + |
+
+ Callable[..., T]
+ |
+
+
+
+ will inject the dependencies and + |
+
+ Callable[..., T]
+ |
+
+
+
+ return the injected class instance or function. + |
+
src/magic_di/_injector.py
191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 |
|
override(bindings: dict[type, type]) -> Iterator[None]
+
+Temporarily override the bindings and dependencies of the injector.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
bindings |
+
+ dict
+ |
+
+
+
+ The bindings to use for the override. + |
+ + required + | +
src/magic_di/_injector.py
247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 |
|
celery
+
+
+fastapi
+
+
+Package containing tools for integrating Dependency Injector with FastAPI framework.
+ + + +inject_app(app: FastAPI, *, injector: DependencyInjector | None = None, use_deprecated_events: bool = False) -> FastAPI
+
+Inject dependencies into a FastAPI application using the provided injector.
+This function sets up the FastAPI application to connect and disconnect the injector +at startup and shutdown, respectively.
+This ensures that all dependencies are properly +connected when the application starts, and properly disconnected when the application +shuts down.
+If no injector is provided, a default injector is used.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
app |
+
+ FastAPI
+ |
+
+
+
+ The FastAPI application + |
+ + required + | +
injector |
+
+ DependencyInjector
+ |
+
+
+
+ The injector to use for dependency injection. + If not provided, a default injector will be used. + |
+
+ None
+ |
+
use_deprecated_events |
+
+ bool
+ |
+
+
+
+ Indicate whether the app should be injected + with starlette events (which are deprecated) + or use app lifespans. + Important: Use this flag only + if you still use app events, + because if lifespans are defined, + events will be ignored by Starlette. + |
+
+ False
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
FastAPI |
+ FastAPI
+ |
+
+
+
+ The FastAPI application with dependencies injected. + |
+
src/magic_di/fastapi/_app.py
34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 |
|
healthcheck
+
+
+DependenciesHealthcheck
+
+
+
+ dataclass
+
+
+
+ Bases: Connectable
Injectable Healthcheck component that pings all injected dependencies +that implement the PingableProtocol
+Example usage:
+from app.components.services.health import DependenciesHealthcheck
+
+async def main(redis: Redis, deps_healthcheck: DependenciesHealthcheck) -> None:
+ await deps_healthcheck.ping_dependencies() # redis will be pinged if it has method __ping__
+
+inject_and_run(main)
+
+
+ src/magic_di/healthcheck.py
14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 |
|
ping(dependency: PingableProtocol) -> None
+
+
+ async
+
+
+Ping a single dependency
+:param dependency: Dependency to ping
+ +src/magic_di/healthcheck.py
62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 |
|
ping_dependencies(max_concurrency: int = 1) -> None
+
+
+ async
+
+
+Ping all dependencies that implement the PingableProtocol
+:param max_concurrency: Maximum number of concurrent pings
+ +src/magic_di/healthcheck.py
34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 |
|
testing
+
+
+InjectableMock
+
+
+
+ Bases: AsyncMock
You can use this mock to override dependencies in tests +and use AsyncMock instead of a real class instance
+Example:
+@pytest.fixture()
+def client():
+ injector = DependencyInjector()
+
+ with injector.override({Service: InjectableMock().mock_cls}):
+ with TestClient(app) as client:
+ yield client
+
+def test_http_handler(client):
+ resp = client.post('/hello-world')
+
+ assert resp.status_code == 200
+
+
+ src/magic_di/testing.py
19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 |
|
utils
+
+
+inject_and_run(fn: Callable[..., T], injector: DependencyInjector | None = None) -> T
+
+This function takes a callable, injects dependencies into it using the provided injector, +and then runs the function. If the function is a coroutine, it will be awaited.
+The function itself is not asynchronous, but it uses asyncio.run +to run the internal coroutine, so it is suitable for use in synchronous code.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
fn |
+
+ Callable
+ |
+
+
+
+ The function into which dependencies will be injected. This can be + a regular function or a coroutine function. + |
+ + required + | +
injector |
+
+ DependencyInjector
+ |
+
+
+
+ The injector to use for dependency injection. + If not provided, a default injector will be used. + |
+
+ None
+ |
+
Returns:
+Name | Type | +Description | +
---|---|---|
Any |
+ T
+ |
+
+
+
+ The return value of the function |
+
src/magic_di/utils.py
30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 |
|