Skip to main content

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

test GitHub Actions Workflow Status License Version Python Version

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

  1. Import
from dishka import Provider, provide, Scope

class YourProvider(Provider):
    @provide(scope=Scope.REQUEST)
    def create_x(self, request: Request) -> X:
         ...
  1. Create provider.
class YourProvider(Provider):
    @provide(scope=Scope.REQUEST)
    def create_x(self) -> X:
         ...
  1. 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])
        ...
  1. Make container
container = make_async_container(YourProvider())
  1. 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

  1. Steps 1 and 2 is identical to async
  2. In step 3 you need to decorate your handlers with @inject_sync and their parameters should be marked with FromDishka[] as well
from dmr_dishka.integration import inject_sync

class ExampleBlueprint(Controller[MsgspecSerializer]):
    @inject_sync
    def get(self, x: FromDishka[X])
        ...
  1. Step 4 is identical to async
  2. In step 5 need to setup dishka in your wsgi.py instead of asgi.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dmr_dishka-0.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dmr_dishka-0.1.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

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

Hashes for dmr_dishka-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b562d9359ca549b89c892505cba052547549f2a7b541ae0eb34facdd238bff8c
MD5 4dfc3f50d7c9426670eca0a9b571bdad
BLAKE2b-256 f3a82756a7f4c8f403bcad37c6482d96e97133ab72e18309b6092dd0b0a264d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for dmr_dishka-0.1.1.tar.gz:

Publisher: release.yml on arturboyun/dmr-dishka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for dmr_dishka-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 010fd59b06fb6f2d1756e32d5de504b623dd41e0debcc615f63d5c5b78a495da
MD5 6a48937862256e723d4333b44b6cf54f
BLAKE2b-256 48a34d4f4d29ad0baee81a2a8178e6f4befcc3c26d25ebd080357b396bc2dbc9

See more details on using hashes here.

Provenance

The following attestation bundles were made for dmr_dishka-0.1.1-py3-none-any.whl:

Publisher: release.yml on arturboyun/dmr-dishka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page