Skip to content

Commit 3933d81

Browse files
committed
Clean up
Moved the autogenerated code into a subfolder called protobufs to keep the project structure more organized.
1 parent 878c0ec commit 3933d81

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ Install Grpc Tools
1313
pip3 install grpcio-tools
1414
```
1515

16-
Generate grpc code based on proto file
16+
Generate gRPC code based on proto file
1717
```
18-
python3 -m grpc_tools.protoc -I protos --python_out=. --grpc_python_out=. protos/greet.proto
18+
python3 -m grpc_tools.protoc --python_out=protobufs/ --grpc_python_out=protobufs/ -I protos protos/greet.proto
19+
20+
Options Explained
21+
--python_out: Is where you want the autogenerated gRPC protocol buffers code to go
22+
--grpc_python_out: Is where you want the autogenerated gRPC python protocols code to go
23+
-I: Points to the folder where the protos are stored
24+
25+
The last argument is the exact proto file you want to use within the folder identified in the -I argument
1926
```
2027

2128
Run the Envoy (The Envoy allows a grpc-web app to communicate with the gRPC server)

client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
import greet_pb2_grpc
2-
import greet_pb2
31
import time
42
import grpc
3+
import os
4+
import sys
5+
6+
# Add the protobufs module directory to sys.path
7+
parent_dir = os.path.dirname(os.path.abspath(__file__))
8+
protobuf_dir = os.path.join(parent_dir, 'protobufs')
9+
sys.path.append(protobuf_dir)
10+
11+
from protobufs import greet_pb2
12+
from protobufs import greet_pb2_grpc
513

614
def get_client_stream_requests():
715
while True:
File renamed without changes.
File renamed without changes.

server.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
from concurrent import futures
22
import time
3+
import os
4+
import sys
35

46
import grpc
5-
import greet_pb2
6-
import greet_pb2_grpc
7+
8+
# Add the protobufs module directory to sys.path
9+
parent_dir = os.path.dirname(os.path.abspath(__file__))
10+
protobuf_dir = os.path.join(parent_dir, 'protobufs')
11+
sys.path.append(protobuf_dir)
12+
13+
from protobufs import greet_pb2
14+
from protobufs import greet_pb2_grpc
715

816
class GreeterServicer(greet_pb2_grpc.GreeterServicer):
917
def SayHello(self, request, context):

0 commit comments

Comments
 (0)