gRPC for Django.
Project description
⚠️ 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_grpc_framework_plus-0.2.0.tar.gz.
File metadata
- Download URL: django_grpc_framework_plus-0.2.0.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38bc9f372ada244123a037f0a5d5dffb5f9a0e22915494c9c9fc97f4640369b3
|
|
| MD5 |
c3a057d05848c5b52c57fffe3f995cd3
|
|
| BLAKE2b-256 |
f185d62d53acd037b5359cf674079c67704a3c00e5156263948afd3b65644447
|
File details
Details for the file django_grpc_framework_plus-0.2.0-py2.py3-none-any.whl.
File metadata
- Download URL: django_grpc_framework_plus-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0c3185c324b47074678b5bac81fde868e5cb51a22a34041d70b497dacbde507
|
|
| MD5 |
99fd69b1bb0246b04dde14fd2740a47f
|
|
| BLAKE2b-256 |
6d9e1f057630a372396d38e34034db7f23d5b4af909a182df0dcd509fb0ddb7e
|