SDK StillDeep — Client Python
Client Python : grpcio-tools, génération du code, premier panier.
Prerequis
- Python 3.11+
pip install grpcio grpcio-tools
Setup
mkdir my-pos-client && cd my-pos-client
python -m venv .venv && source .venv/bin/activate # Windows : .venv\Scripts\activate
pip install grpcio grpcio-tools
cp -r ../waxpos/src/public/StillDeep.Intelligence.Contracts/protos ./protos
mkdir generated
python -m grpc_tools.protoc \
-I./protos \
--python_out=./generated \
--grpc_python_out=./generated \
./protos/common.proto ./protos/sales.proto ./protos/catalog.proto \
./protos/member.proto ./protos/device.proto ./protos/events.proto
Exemple
import uuid
import grpc
import sys; sys.path.insert(0, './generated')
import sales_pb2, sales_pb2_grpc
with grpc.insecure_channel('localhost:50051') as channel:
stub = sales_pb2_grpc.SalesServiceStub(channel)
resp = stub.CreateCart(sales_pb2.CreateCartRequest(
post_id='post-1',
cashier_user_id='user-1',
idempotency_key=str(uuid.uuid4()),
))
print(resp)
Stream des events
import events_pb2, events_pb2_grpc
with grpc.insecure_channel('localhost:50051') as channel:
stub = events_pb2_grpc.EventServiceStub(channel)
for ev in stub.Subscribe(events_pb2.SubscribeRequest(subscriber_id='kiosk-1')):
print(ev.WhichOneof('payload'), ev)