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

  • Support for SESSION and REQUEST scoped dependencies
  • 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.0.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.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file dmr_dishka-0.1.0.tar.gz.

File metadata

  • Download URL: dmr_dishka-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dmr_dishka-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f64ebfac999ac83af81d70d6936f509040bcb3eb2740ca8264185267ac50becc
MD5 33e8efb32bd26cbd3ab8ce726d8efaa3
BLAKE2b-256 c64950dd65ee26375bcfa7ed672d92131febda87d32cb5cffd1ff71000ad6f37

See more details on using hashes here.

Provenance

The following attestation bundles were made for dmr_dishka-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: dmr_dishka-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dmr_dishka-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fadb22015f9ddd976aa3cb469b97834d5f0ac86b9fe25ad443f87151407fe61a
MD5 2d871feb3da94726f27ecd11984de772
BLAKE2b-256 42574a1b49401cb9895002b6daacaff52f0ab94f5527852aecbb3af803005977

See more details on using hashes here.

Provenance

The following attestation bundles were made for dmr_dishka-0.1.0-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