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.3.0.tar.gz (19.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.3.0-py2.py3-none-any.whl (22.7 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for django_grpc_framework_plus-0.3.0.tar.gz
Algorithm Hash digest
SHA256 90dd7a9a1a74bf9fae35c975841a0203060efab38cb7f69623a9bb5f32aa57b0
MD5 83c18ca8cdb888ef36ecd0124f9db5cb
BLAKE2b-256 0fe0c1e62b798c2aa999766254a6136f0dd9ac4ae63b845c8691cab661d9cd5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_grpc_framework_plus-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d56a0e0190a21750c5f38e85032b13f28d64ea3cac9b808ab61daac0a82d4d42
MD5 a8a525ce752ae3c4f0746f5bd6405631
BLAKE2b-256 0d739490c739f1441991cecee5550e36971b80b1dda1ada9fcebf1e66ba71796

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