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

PyPi version and python version is cached now! Sorry for that.

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.0.1a2.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.0.1a2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file dmr_dishka-0.0.1a2.tar.gz.

File metadata

  • Download URL: dmr_dishka-0.0.1a2.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.0.1a2.tar.gz
Algorithm Hash digest
SHA256 d08322f90468595e4d09637c333cbf4f6e0e96298fe88c321f987d2b5970dbd6
MD5 c310fd55236d1fc48e85d8a40065ebee
BLAKE2b-256 125ffcca936ed61a6964cb64f3ac1f2b5c47c4e76de2006fd2afe8fa2d26c9a1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: dmr_dishka-0.0.1a2-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.7

File hashes

Hashes for dmr_dishka-0.0.1a2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab7bfafb05f015e70fdcc4002f16dae8120deb33d043660702e1abe4e03f6ae1
MD5 1d50dd976d2fafb3bedab67be76aac2b
BLAKE2b-256 e321b7c752fdf1d8a70943c29b38d895ff2ebe5bea3e9146c50e479cd5d3a16e

See more details on using hashes here.

Provenance

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