Skip to main content
https://img.shields.io/pypi/v/djangogrpcframework.svg https://readthedocs.org/projects/djangogrpcframework/badge/?version=latest https://travis-ci.org/fengsp/django-grpc-framework.svg?branch=master https://img.shields.io/pypi/pyversions/djangogrpcframework https://img.shields.io/pypi/l/djangogrpcframework

Django gRPC framework is a toolkit for building gRPC services, inspired by djangorestframework.

Requirements

  • Python (3.6, 3.7, 3.8)

  • Django (2.2, 3.0), Django REST Framework (3.10.x, 3.11.x)

  • gRPC, gRPC tools, proto3

Installation

$ pip install djangogrpcframework

Add django_grpc_framework to INSTALLED_APPS setting:

INSTALLED_APPS = [
    ...
    'django_grpc_framework',
]

Demo

Here is a quick example of using gRPC framework to build a simple model-backed service for accessing users, startup a new project:

$ django-admin startproject demo
$ python manage.py migrate

Generate .proto file demo.proto:

python manage.py generateproto --model django.contrib.auth.models.User --fields id,username,email --file demo.proto

Generate gRPC code:

python -m grpc_tools.protoc --proto_path=./ --python_out=./ --grpc_python_out=./ ./demo.proto

Now edit the demo/urls.py module:

from django.contrib.auth.models import User
from django_grpc_framework import generics, proto_serializers
import demo_pb2
import demo_pb2_grpc


class UserProtoSerializer(proto_serializers.ModelProtoSerializer):
    class Meta:
        model = User
        proto_class = demo_pb2.User
        fields = ['id', 'username', 'email']


class UserService(generics.ModelService):
    queryset = User.objects.all()
    serializer_class = UserProtoSerializer


urlpatterns = []
def grpc_handlers(server):
    demo_pb2_grpc.add_UserControllerServicer_to_server(UserService.as_servicer(), server)

That’s it, we’re done!

$ python manage.py grpcrunserver --dev

You can now run a gRPC client to access the service:

with grpc.insecure_channel('localhost:50051') as channel:
    stub = demo_pb2_grpc.UserControllerStub(channel)
    for user in stub.List(demo_pb2.UserListRequest()):
        print(user, end='')

Metadata

Release files for djangogrpcframework 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djangogrpcframework 0.2.1
File Size Uploaded
djangogrpcframework-0.2.1.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for djangogrpcframework 0.2.1
File Interpreter ABI Platform
djangogrpcframework-0.2.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 35.0 kB

Release files / djangogrpcframework-0.2.1.tar.gz

Download URL djangogrpcframework-0.2.1.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f96ae98d463f02745dbac5c18899801b738c79efd198e8cc709a7476533aec97
BLAKE2b-256 checksum
How to use checksums
96d974504f99dbfe1955a3f5e0ca2952cc4a7decee156822f18f0d0cf3c58328
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.3

Release files / djangogrpcframework-0.2.1-py2.py3-none-any.whl

Download URL djangogrpcframework-0.2.1-py2.py3-none-any.whl
Size 21.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c1835bd87ac9bdbdbdb631cd1c12720e711260d316303d19e4c63e53896ff0e6
BLAKE2b-256 checksum
How to use checksums
ae899a475e234786ba14fd3b538a18df0d20e98ce5a51906e1bd4485a74164e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2

2 release files

0.1

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page