Repository navigation
feat(grpc): add smg-grpc-proto Python package for proto definitions #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
468b55d
Add smg-grpc-proto Python package for proto definitions
CatherineSue 7a45373
Add smg-grpc-proto to version sync targets
CatherineSue d47844a
Improve setup.py proto generation to match vLLM patterns
CatherineSue b13bcdf
Fix smg-grpc-proto version to match SMG (0.3.2)
CatherineSue 8ac659b
fix: clarify README dev instructions - symlink vs CI copy
CatherineSue c13a279
fix: include .pyi stubs in package-data, fail build if no protos found
CatherineSue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Generated stubs (created at build time) | ||
| smg_grpc_proto/generated/ | ||
|
|
||
| # Build artifacts | ||
| dist/ | ||
| *.egg-info/ | ||
| build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # smg-grpc-proto | ||
|
|
||
| Protocol Buffer definitions for SMG (Shepherd Model Gateway) gRPC services. | ||
|
|
||
| This package provides the Python gRPC stubs for: | ||
| - **SGLang** scheduler service | ||
| - **vLLM** engine service | ||
| - **TRT-LLM** service | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install smg-grpc-proto | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```python | ||
| from smg_grpc_proto import sglang_scheduler_pb2, sglang_scheduler_pb2_grpc | ||
| from smg_grpc_proto import vllm_engine_pb2, vllm_engine_pb2_grpc | ||
| from smg_grpc_proto import trtllm_service_pb2, trtllm_service_pb2_grpc | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| The proto files are located in `grpc_client/proto/` in the SMG repository. A symlink at `smg_grpc_proto/proto` points to the proto source files. Python stubs are generated at build time using `grpcio-tools`. | ||
|
|
||
| To install in editable mode: | ||
|
|
||
| ```bash | ||
| # From repo root (symlink handles proto file discovery) | ||
| pip install -e grpc_client/python/ | ||
| ``` | ||
|
|
||
| For CI or environments where symlinks don't work: | ||
|
|
||
| ```bash | ||
| mkdir -p grpc_client/python/smg_grpc_proto/proto | ||
| cp grpc_client/proto/*.proto grpc_client/python/smg_grpc_proto/proto/ | ||
| pip install -e grpc_client/python/ | ||
| ``` | ||
|
|
||
| ## License | ||
|
|
||
| Apache-2.0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| [build-system] | ||
| requires = ["setuptools>=68.0", "grpcio-tools>=1.62.0"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [project] | ||
| name = "smg-grpc-proto" | ||
| version = "0.3.2" | ||
| description = "SMG gRPC proto definitions for SGLang, vLLM, and TRT-LLM" | ||
| requires-python = ">=3.10" | ||
| dependencies = [ | ||
| "grpcio>=1.62.0", | ||
| "protobuf>=5.26.0", | ||
| ] | ||
| readme = "README.md" | ||
| license = { text = "Apache-2.0" } | ||
| authors = [ | ||
| {name = "Simo Lin", email = "linsimo.mark@gmail.com"}, | ||
| {name = "Chang Su", email = "mckvtl@gmail.com"}, | ||
| {name = "Keyang Ru", email = "rukeyang@gmail.com"} | ||
| ] | ||
| classifiers = [ | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.10", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
| "License :: OSI Approved :: Apache Software License", | ||
| "Operating System :: OS Independent", | ||
| ] | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/lightseekorg/smg" | ||
| Repository = "https://github.com/lightseekorg/smg" | ||
|
|
||
| [tool.setuptools.packages.find] | ||
| where = ["."] | ||
| include = ["smg_grpc_proto*"] | ||
|
|
||
| [tool.setuptools.package-data] | ||
| smg_grpc_proto = ["proto/*.proto", "generated/*.py", "generated/*.pyi"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| """ | ||
| Custom setup.py to generate protobuf stubs at build time. | ||
| The generated files are NOT committed to git — they're created fresh during pip install. | ||
| """ | ||
| from pathlib import Path | ||
|
|
||
| from setuptools import setup | ||
| from setuptools.command.build_py import build_py | ||
| from setuptools.command.develop import develop | ||
|
|
||
|
|
||
| def compile_grpc_protos(): | ||
| """Generate Python gRPC stubs from .proto files.""" | ||
| package_dir = Path(__file__).parent | ||
| proto_dir = package_dir / "smg_grpc_proto" / "proto" | ||
| output_dir = package_dir / "smg_grpc_proto" / "generated" | ||
|
|
||
| output_dir.mkdir(parents=True, exist_ok=True) | ||
| (output_dir / "__init__.py").write_text( | ||
| '"""Auto-generated protobuf stubs. Do not edit."""\n' | ||
| ) | ||
|
|
||
| proto_files = list(proto_dir.glob("*.proto")) | ||
| if not proto_files: | ||
| raise FileNotFoundError(f"No .proto files found in {proto_dir}") | ||
|
|
||
| # Use grpc_tools.protoc Python API (same approach as vLLM) | ||
| try: | ||
| from grpc_tools import protoc | ||
|
|
||
| args = [ | ||
| "grpc_tools.protoc", | ||
| f"--proto_path={proto_dir}", | ||
| f"--python_out={output_dir}", | ||
| f"--grpc_python_out={output_dir}", | ||
| f"--pyi_out={output_dir}", # Generate type stubs | ||
| ] + [str(f) for f in proto_files] | ||
|
|
||
| print(f"Generating protobuf stubs from {len(proto_files)} proto files...") | ||
| result = protoc.main(args) | ||
|
|
||
| if result != 0: | ||
| raise RuntimeError(f"protoc returned non-zero exit code: {result}") | ||
|
|
||
| except ImportError: | ||
| raise RuntimeError( | ||
| "grpcio-tools not installed. Install with: pip install grpcio-tools" | ||
| ) | ||
|
|
||
| # Fix imports in generated files (grpcio-tools generates absolute imports) | ||
| # Also add mypy ignore-errors comment for generated code | ||
| mypy_header = "# mypy: ignore-errors\n" | ||
|
|
||
| for py_file in output_dir.glob("*_pb2*.py"): | ||
| content = py_file.read_text() | ||
|
|
||
| # Fix imports to be relative | ||
| for proto_file in proto_files: | ||
| module_name = proto_file.stem + "_pb2" | ||
| content = content.replace( | ||
| f"import {module_name}", f"from . import {module_name}" | ||
| ) | ||
|
|
||
| # Add mypy ignore-errors if not already present | ||
| if not content.startswith("# mypy:"): | ||
| content = mypy_header + content | ||
|
|
||
| py_file.write_text(content) | ||
|
|
||
| # Also add mypy header to .pyi files | ||
| for pyi_file in output_dir.glob("*_pb2*.pyi"): | ||
| content = pyi_file.read_text() | ||
| if not content.startswith("# mypy:"): | ||
| pyi_file.write_text(mypy_header + content) | ||
|
|
||
| generated_count = len(list(output_dir.glob("*.py"))) + len( | ||
| list(output_dir.glob("*.pyi")) | ||
| ) | ||
| print(f"Generated {generated_count} files (including type stubs)") | ||
|
|
||
|
|
||
| class BuildPyWithProto(build_py): | ||
| """Custom build_py that generates protobuf stubs before building.""" | ||
|
|
||
| def run(self): | ||
| compile_grpc_protos() | ||
| super().run() | ||
|
|
||
|
|
||
| class DevelopWithProto(develop): | ||
| """Custom develop that generates protobuf stubs for editable installs.""" | ||
|
|
||
| def run(self): | ||
| compile_grpc_protos() | ||
| super().run() | ||
|
|
||
|
|
||
| setup( | ||
| cmdclass={ | ||
| "build_py": BuildPyWithProto, | ||
| "develop": DevelopWithProto, | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """SMG gRPC Proto - Protocol definitions for SGLang, vLLM, and TRT-LLM.""" | ||
|
|
||
| __version__ = "0.3.2" | ||
|
|
||
| # Re-export generated modules for convenient access | ||
| # These imports will work after the package is built (stubs generated at build time) | ||
| try: | ||
| from smg_grpc_proto.generated import ( | ||
| sglang_scheduler_pb2, | ||
| sglang_scheduler_pb2_grpc, | ||
| trtllm_service_pb2, | ||
| trtllm_service_pb2_grpc, | ||
| vllm_engine_pb2, | ||
| vllm_engine_pb2_grpc, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "sglang_scheduler_pb2", | ||
| "sglang_scheduler_pb2_grpc", | ||
| "vllm_engine_pb2", | ||
| "vllm_engine_pb2_grpc", | ||
| "trtllm_service_pb2", | ||
| "trtllm_service_pb2_grpc", | ||
| ] | ||
| except ImportError: | ||
| # During development/build, generated modules may not exist yet | ||
| __all__ = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../proto | ||
|
CatherineSue marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.