Integration of Dishka dependency injection framework and Modern REST framework for Django with types and async support!
Project description
Django Modern REST integration for Dishka
This package provides integration of Dishka dependency injection framework and Modern REST framework for Django with types and async support!
Features
- Automatic REQUEST and SESSION scope management using middleware
- Easy setup and integration with Django Modern REST framework
- Support for both async and sync views
- Support for Django views
Installation
pip install dmr-dishka
uv add dmr-dishka
How to use async
- Import
from dishka import Provider, provide, Scope
class YourProvider(Provider):
@provide(scope=Scope.REQUEST)
def create_x(self, request: Request) -> X:
...
- Create provider.
class YourProvider(Provider):
@provide(scope=Scope.REQUEST)
def create_x(self) -> X:
...
- Mark those of your handlers parameters which are to be injected with
FromDishka[]and decorate them using@inject
from dmr_dishka.integration import inject
class ExampleBlueprint(Controller[MsgspecSerializer]):
@inject
async def get(self, x: FromDishka[X])
...
- Make container
container = make_async_container(YourProvider())
- Setup dishka integration in your
asgi.py
# asgi.py
from dishka import make_async_container
from django_example.app.ioc import AppProvider
from dmr_dishka.integration import setup_dishka
container = make_async_container(AppProvider())
setup_dishka(container)
How to use sync
- Steps 1 and 2 is identical to async
- In step 3 you need to decorate your handlers with
@inject_syncand their parameters should be marked withFromDishka[]as well
from dmr_dishka.integration import inject_sync
class ExampleBlueprint(Controller[MsgspecSerializer]):
@inject_sync
def get(self, x: FromDishka[X])
...
- Step 4 is identical to async
- In step 5 need to setup dishka in your
wsgi.pyinstead ofasgi.py
# wsgi.py
from dishka import make_container
from django_example.app.ioc import AppProvider
from dmr_dishka.integration import setup_dishka
container = make_container(AppProvider())
setup_dishka(container)
| Check src/django_example for more examples of usage and vanila django view support.
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
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 dmr_dishka-0.1.1.tar.gz.
File metadata
- Download URL: dmr_dishka-0.1.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b562d9359ca549b89c892505cba052547549f2a7b541ae0eb34facdd238bff8c
|
|
| MD5 |
4dfc3f50d7c9426670eca0a9b571bdad
|
|
| BLAKE2b-256 |
f3a82756a7f4c8f403bcad37c6482d96e97133ab72e18309b6092dd0b0a264d2
|
Provenance
The following attestation bundles were made for dmr_dishka-0.1.1.tar.gz:
Publisher:
release.yml on arturboyun/dmr-dishka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dmr_dishka-0.1.1.tar.gz -
Subject digest:
b562d9359ca549b89c892505cba052547549f2a7b541ae0eb34facdd238bff8c - Sigstore transparency entry: 1262838554
- Sigstore integration time:
-
Permalink:
arturboyun/dmr-dishka@432e6ce8932291a6d1b8bd069767d769422b67a9 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/arturboyun
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@432e6ce8932291a6d1b8bd069767d769422b67a9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file dmr_dishka-0.1.1-py3-none-any.whl.
File metadata
- Download URL: dmr_dishka-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
010fd59b06fb6f2d1756e32d5de504b623dd41e0debcc615f63d5c5b78a495da
|
|
| MD5 |
6a48937862256e723d4333b44b6cf54f
|
|
| BLAKE2b-256 |
48a34d4f4d29ad0baee81a2a8178e6f4befcc3c26d25ebd080357b396bc2dbc9
|
Provenance
The following attestation bundles were made for dmr_dishka-0.1.1-py3-none-any.whl:
Publisher:
release.yml on arturboyun/dmr-dishka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dmr_dishka-0.1.1-py3-none-any.whl -
Subject digest:
010fd59b06fb6f2d1756e32d5de504b623dd41e0debcc615f63d5c5b78a495da - Sigstore transparency entry: 1262838626
- Sigstore integration time:
-
Permalink:
arturboyun/dmr-dishka@432e6ce8932291a6d1b8bd069767d769422b67a9 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/arturboyun
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@432e6ce8932291a6d1b8bd069767d769422b67a9 -
Trigger Event:
release
-
Statement type: