Skip to main content

gRPC for Django.

Project description

https://img.shields.io/pypi/v/django-grpc-framework-plus.svg https://readthedocs.org/projects/django-grpc-framework-plus/badge/?version=latest https://img.shields.io/pypi/pyversions/django-grpc-framework-plus https://img.shields.io/pypi/l/django-grpc-framework-plus

⚠️ Note: Django gRPC Framework Plus is a fork of [Django gRPC Framework](https://github.com/fengsp/django-grpc-framework) with additional features such as advanced filtering for gRPC. Some new features may be experimental and documentation may be incomplete.

Overview

Django gRPC Framework Plus allows building gRPC services in Django while providing better support for client-server interactions.

### Additional Features

  • Advanced gRPC filtering support (experimental)

  • Pagination support for gRPC responses

  • Extended authentication options

  • Client-focused enhancements

Requirements

  • Python (3.6, 3.7, 3.8, 3.9, 3.10)

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

  • gRPC, gRPC tools, proto3

Installation

$ pip install django-grpc-framework-plus

Add django_grpc_framework_plus to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'django_grpc_framework_plus',
]

Demo

Create a new Django project:

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

Generate a .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

Edit demo/urls.py:

from django.contrib.auth.models import User
from django_grpc_framework_plus 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)

Run the gRPC server:

$ python manage.py grpcrunserver --dev

Run a gRPC client:

import grpc
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='')

Release Notes

  • Fork of Django gRPC Framework

  • Added experimental gRPC filtering, pagination, and client-focused enhancements

  • Some features are experimental and may be updated in future releases

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

django_grpc_framework_plus-0.1.1.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

django_grpc_framework_plus-0.1.1-py2.py3-none-any.whl (21.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django_grpc_framework_plus-0.1.1.tar.gz.

File metadata

File hashes

Hashes for django_grpc_framework_plus-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ae8380f3a4a6bca7aa16c75df1c8b3c955186350e7c4659ed0afae5563d1b99f
MD5 74a1cec09de5985771fd07aa13b8c526
BLAKE2b-256 675b6ad10201ab2a0730fd5359d0ed63724640622a05f3a1870a0a88a176e7cf

See more details on using hashes here.

File details

Details for the file django_grpc_framework_plus-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_grpc_framework_plus-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a9b873a4de54496c733f5b9425d9f44d06b40ac5201cb07f117a149b49be4e34
MD5 4265458e6b852a8bd05217580795e73f
BLAKE2b-256 34c4cd07f9642cb88e9d6d4256511db6afb2261a11330c6ec04b8258a0e65c46

See more details on using hashes here.

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