Skip to main content

This tools for generating grpc files

Project description

# gRPC tools
This is tool for auto generating *.proto and mapping django model with protobuf.

## Requirements
- Python (2.7, 3.4, 3.5, 3.6, 3.7)
- Django (1.11, 2.0, 2.1, 2.2)

## Installation
Install using pip
```
pip install grpc-tls
```

Add 'grpc_tls' to your INSTALLED_APPS setting.
```
INSTALLED_APPS = (
...
'grpc_tls',
)
```

Update list apps your want migrate to protobuf:
`GRPC_TLS_MODELS_APP=['core']`

Update proto file name:
`GRPC_TLS_BASE_PROTO='app_name'`.

*Note*: This name must be unique if your app run multiple *.proto file

## Usage
Generate *.proto file
```
python manage.py grpc_tls
```

All files will be generated in `grpc_dir/*`

## Example
Let's take a look at a quick example of running gRPC server.

First generate proto files by running command line above.

Then create a django command line: `run_grpc.py`.
```
import grpc
from concurrent import futures
from django.core.management.base import BaseCommand

from grpc_dir import auto_grpc_app, grpc_app_pb2_grpc

class Command(BaseCommand):
help = 'Start gRPC server'

def handle(self, *args, **options):
server = grpc.server(futures.ThreadPoolExecutor(
max_workers=10))
grpc_app_pb2_grpc.add_GRPCAPPServicer_to_server(
auto_grpc_app.AutoGRPC(), server)
server.add_insecure_port('[::]:50051')
server.start()
print('server started on port 50051 ...')
try:
while True:
pass
except KeyboardInterrupt:
server.stop(0)
```

Start gRPC server:
```
python manage.py run_grpc
```
You can now send request at `http://127.0.0.1:50051/`

## Notes
DO NOT FILES IN `grpc_dir`

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

grpc-tls-1.1.12.tar.gz (8.2 kB view details)

Uploaded Source

File details

Details for the file grpc-tls-1.1.12.tar.gz.

File metadata

  • Download URL: grpc-tls-1.1.12.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

File hashes

Hashes for grpc-tls-1.1.12.tar.gz
Algorithm Hash digest
SHA256 0d8293dbb5f54e057a2e50c4a72064e52b9117adc6214f948f476595357214a7
MD5 3e0e097dd528bcd9e8f9bd8bdd5965eb
BLAKE2b-256 0671c54636359cb5d9a8100947fb93728139bbcfef4757d229b27449e199709a

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