modern-di integration for Flask
Project description
modern-di-flask
Modern-DI integration for Flask.
Quickstart
import typing
from flask import Flask
from modern_di import Container, Group, Scope, providers
from modern_di_flask import FromDI, inject, setup_di
class Settings:
def __init__(self) -> None:
self.greeting = "hello"
class Dependencies(Group):
settings = providers.Factory(scope=Scope.APP, creator=Settings)
app = Flask(__name__)
@app.route("/hello/<name>")
@inject
def hello(name: str, settings: typing.Annotated[Settings, FromDI(Dependencies.settings)]) -> str:
return f"{settings.greeting}, {name}"
# call setup_di AFTER registering routes (required for auto_inject)
setup_di(app, Container(groups=[Dependencies], validate=True))
Pass auto_inject=True to setup_di to inject every view without a per-view
@inject. See the documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
modern_di_flask-2.0.0.tar.gz
(3.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file modern_di_flask-2.0.0.tar.gz.
File metadata
- Download URL: modern_di_flask-2.0.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22900701a6028c3b1e76bd062fdd90170926f70165c253f79a170d971743fcab
|
|
| MD5 |
f0168cfbffa287447f0250b084c46e7e
|
|
| BLAKE2b-256 |
36059b938d95c02891db41aca13df8a6285db3e845f35866206ffd62a8b0ac08
|
File details
Details for the file modern_di_flask-2.0.0-py3-none-any.whl.
File metadata
- Download URL: modern_di_flask-2.0.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0d67d03d7fb6d0eedd314c8524b9252b6d3243e9936d24295b5b232d08bfe62
|
|
| MD5 |
1725810b2a2d926e40f938103eff4da3
|
|
| BLAKE2b-256 |
640665e450214c94033caf636d9a7e28d8bd3ce25168addffacc7f346a565d76
|