Skip to content

feat(grpc): add smg-grpc-proto Python package for proto definitions - #385

Merged
slin1237 merged 6 commits into
mainfrom
feat/grpc-proto-package
Feb 9, 2026
Merged

slin1237 merged 6 commits into
mainfrom
feat/grpc-proto-package

Conversation

@CatherineSue

@CatherineSue CatherineSue commented Feb 9, 2026 •

Copy link
Copy Markdown
Member

Description

Problem

Proto definitions for gRPC services (SGLang, vLLM, TRT-LLM) are currently duplicated across SMG and upstream repos. Keeping them in sync is error-prone and creates maintenance burden. SMG should be the single source of truth for these protos.

Solution

Add a pip-installable package smg-grpc-proto that:

  • Provides SMG-owned proto definitions as a Python package
  • Generates gRPC stubs at build time using grpcio-tools
  • Publishes to PyPI with version synced to SMG releases
  • Allows upstream repos to pip install smg-grpc-proto instead of maintaining their own copies

Changes

  • Add grpc_client/python/ package structure:
    • pyproject.toml - package metadata
    • setup.py - build-time proto generation (matches vLLM patterns)
    • smg_grpc_proto/__init__.py - re-exports generated modules
    • Symlink to grpc_client/proto/ for proto source files
  • Update Makefile to include new files in bump-version target

Test Plan

# Build locally
mkdir -p grpc_client/python/smg_grpc_proto/proto
cp grpc_client/proto/*.proto grpc_client/python/smg_grpc_proto/proto/
pip install build grpcio-tools
cd grpc_client/python && python -m build

# Test import
pip install dist/*.whl
python -c "from smg_grpc_proto import sglang_scheduler_pb2; print('OK')"
Checklist
  • cargo +nightly fmt passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • (Optional) Documentation updated

Summary by CodeRabbit

  • New Features

    • Python gRPC proto package available for installation; package exposes generated proto modules.
    • Protobuf stubs are automatically generated during build/develop/install workflows.
  • Documentation

    • Added README with installation, usage, development and license information for the Python gRPC package.
  • Chores

    • Version display and bumping now include the Python gRPC components.
    • Gitignore updated to exclude generated and build artifacts.

This package provides Python gRPC stubs for SGLang, vLLM, and TRT-LLM.
Stubs are generated at build/install time using grpcio-tools, not committed.
The proto source symlinks to grpc_client/proto/ (the source of truth).
Include grpc_client/python/pyproject.toml and __init__.py in
bump-version and show-version Makefile targets to keep the
package version in sync with SMG releases.
- Use protoc.main() Python API instead of subprocess
- Generate .pyi type stubs with --pyi_out
- Add mypy ignore-errors header to generated files
- Support editable installs via DevelopWithProto class
@github-actions github-actions Bot added documentation Improvements or additions to documentation dependencies Dependency updates grpc gRPC client and router changes labels Feb 9, 2026
@coderabbitai

coderabbitai Bot commented Feb 9, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a Python gRPC proto package (smg-grpc-proto) with packaging/README/.gitignore, build-time protobuf stub generation integrated into setup.py, and extends Makefile version display/bump targets to include the new gRPC Python package files.

Changes

Cohort / File(s) Summary
Version Tracking Updates
Makefile
Add grpc_client/python/pyproject.toml and grpc_client/python/smg_grpc_proto/__init__.py to VERSION_FILES; update show-version and bump-version outputs to print/update these grpc client Python versions and adjust help text.
Python Package Metadata
grpc_client/python/pyproject.toml
New pyproject for smg-grpc-proto with project metadata, build-system (setuptools + grpcio-tools), dependencies (grpcio, protobuf), package discovery, and package-data including proto/generated files.
Proto build integration
grpc_client/python/setup.py
New compile_grpc_protos() to locate proto files, invoke grpc_tools.protoc to generate Python and .pyi stubs into smg_grpc_proto/generated, convert absolute imports to relative, prepend mypy-ignore headers, and report counts. Adds BuildPyWithProto and DevelopWithProto cmdclasses to run generation before build/develop.
Package init & proto pointer
grpc_client/python/smg_grpc_proto/__init__.py, grpc_client/python/smg_grpc_proto/proto
New package __init__ with __version__ = "0.3.2" and conditional re-exports of generated modules (__all__); proto file points to shared ../../proto.
Docs & VCS
grpc_client/python/README.md, grpc_client/python/.gitignore
Add README with install/development instructions and Apache-2.0 license note; add .gitignore to exclude smg_grpc_proto/generated/, build artefacts (dist/, build/, *.egg-info/).

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant Setup as setup.py (BuildPyWithProto)
    participant Protoc as grpc_tools.protoc
    participant Gen as smg_grpc_proto/generated
    participant Build as build/install

    Dev->>Setup: run `python setup.py build` or `pip install -e .`
    Setup->>Protoc: discover proto files and invoke protoc
    Protoc-->>Gen: emit *_pb2.py, *_pb2_grpc.py and .pyi files
    Setup->>Gen: post-process (make imports relative, add mypy-ignore headers)
    Setup->>Build: proceed with standard build/develop (include generated files)
    Build-->>Dev: build/install completes
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Poem

🐰 I hopped through proto paths and code,

I coaxed the stubs from every node,
Versions noted, packages made,
Generated files neatly laid,
Hop along — the build's in mode! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing a new pip-installable Python gRPC proto package named smg-grpc-proto for proto definitions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/grpc-proto-package

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
grpc_client/python/setup.py (1)

54-68: Import rewriting handles the common case correctly.

The replacement targets import {stem}_pb2 patterns, which covers the typical case where gRPC stubs import their corresponding message modules. One edge case: if a _pb2_grpc module imports another _pb2_grpc module directly (rare in practice), that import wouldn't be converted to a relative import. This is unlikely to cause issues since gRPC service stubs typically only import their own _pb2 message module.

♻️ Optional: extend to handle _pb2_grpc cross-imports
         for proto_file in proto_files:
             module_name = proto_file.stem + "_pb2"
             content = content.replace(
                 f"import {module_name}", f"from . import {module_name}"
             )
+            # Also handle _pb2_grpc cross-imports (rare but possible)
+            grpc_module_name = proto_file.stem + "_pb2_grpc"
+            content = content.replace(
+                f"import {grpc_module_name}", f"from . import {grpc_module_name}"
+            )

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @CatherineSue, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses the issue of duplicated gRPC proto definitions across various repositories by introducing a new, pip-installable Python package named smg-grpc-proto. This package centralizes the proto definitions for services like SGLang, vLLM, and TRT-LLM, and automatically generates the necessary Python gRPC stubs at build time. This change streamlines dependency management, ensures consistency, and simplifies the consumption of these proto definitions by other projects.

Highlights

  • New Python Package: Introduced a new Python package, smg-grpc-proto, to centralize gRPC proto definitions for SGLang, vLLM, and TRT-LLM services.
  • Automated Stub Generation: Implemented automated generation of Python gRPC stubs during the package build process using grpcio-tools, ensuring up-to-date bindings.
  • Version Management Integration: Integrated the new package's versioning into the existing Makefile targets for show-version and bump-version, maintaining consistent versioning across the project.
  • Single Source of Truth: Established a single source of truth for proto definitions, aiming to reduce duplication and maintenance burden across SMG and upstream repositories.
Changelog
  • Makefile
    • Updated VERSION_FILES to include grpc_client/python/pyproject.toml and grpc_client/python/smg_grpc_proto/__init__.py.
    • Modified show-version and bump-version targets to correctly display and update the version for the newly added Python package files.
  • grpc_client/python/.gitignore
    • Added rules to ignore generated gRPC stubs (smg_grpc_proto/generated/) and Python build artifacts (dist/, *.egg-info/, build/), ensuring these temporary files are not committed to the repository.
  • grpc_client/python/README.md
    • Created a comprehensive README file for the smg-grpc-proto package, detailing its purpose, installation instructions, usage examples, and development guidelines.
  • grpc_client/python/pyproject.toml
    • Added a pyproject.toml file to define the build system, project metadata (name, version, description, dependencies), authors, license, and classifiers for the smg-grpc-proto Python package.
  • grpc_client/python/setup.py
    • Implemented a custom setup.py script that orchestrates the generation of Python gRPC stubs from .proto files using grpcio-tools during the build_py and develop phases.
    • Included logic to adjust import paths in generated files from absolute to relative and to add mypy: ignore-errors comments.
  • grpc_client/python/smg_grpc_proto/init.py
    • Initialized the smg_grpc_proto package, setting its __version__ and conditionally re-exporting the generated gRPC modules for easy access after the package is built.
  • grpc_client/python/smg_grpc_proto/proto
    • Created a symbolic link (or similar mechanism) to include the core .proto definition files from grpc_client/proto/ within the new Python package structure, making them accessible for stub generation.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@CatherineSue CatherineSue changed the title Add smg-grpc-proto Python package for proto definitions feat(grpc): add smg-grpc-proto Python package for proto definitions Feb 9, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Python package smg-grpc-proto to centralize the gRPC proto definitions, which is a great step towards reducing code duplication and improving maintainability. The package is well-structured, using a modern pyproject.toml for configuration and a custom setup.py to handle protobuf code generation at build time. The changes to the Makefile for version management are consistent with the existing project structure. My main feedback is a point of clarification in the README.md regarding the local development setup, which seems to contradict the symlink-based approach used in the build script.

Comment thread grpc_client/python/README.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@grpc_client/python/pyproject.toml`:
- Around line 39-40: The package-data for the smg_grpc_proto package only lists
generated/*.py which omits the generated type stubs; update the
[tool.setuptools.package-data] entry for smg_grpc_proto to also include
generated/*.pyi so the built wheel ships the .pyi stubs (i.e., add
generated/*.pyi alongside generated/*.py in the smg_grpc_proto package-data
list).

In `@grpc_client/python/setup.py`:
- Around line 23-26: Replace the silent return when no .proto files are found
with a hard failure: in setup.py where proto_files =
list(proto_dir.glob("*.proto")) is checked, remove the print + return and raise
a RuntimeError (or SystemExit) with a clear message that no .proto files were
found for proto_dir so the build fails loudly; alternatively gate the check
behind an explicit opt-in dev flag and raise the same error unless that flag is
set. Ensure the error references proto_dir and proto_files in the message so
it’s easy to debug.

In `@grpc_client/python/smg_grpc_proto/proto`:
- Line 1: The repo currently points smg_grpc_proto/proto at an external symlink
("../../proto"), which breaks sdist/wheel and Windows installs; replace the
symlink by vendoring or copying the actual .proto files into the package
directory and ensure packaging includes them. Update your build/packaging step
(e.g., pyproject.toml build-backend hook or setup.py/build_ext hook) to copy all
.proto files into smg_grpc_proto/proto at build time, add those files to
package_data/include-package-data so they ship in sdist/wheel, and remove
reliance on the "../../proto" symlink so stub generation (and tools that read
smg_grpc_proto/proto) work on Windows and in built distributions.
🧹 Nitpick comments (1)
grpc_client/python/setup.py (1)

18-22: Clean stale generated stubs before regeneration.

If a proto is removed, old *_pb2*.py/pyi files remain and can be packaged. Consider clearing the generated folder (or at least stale _pb2* files) before running protoc.

♻️ Proposed refactor
     output_dir.mkdir(parents=True, exist_ok=True)
+    for stale in output_dir.glob("*_pb2*.*"):
+        stale.unlink(missing_ok=True)
     (output_dir / "__init__.py").write_text(
         '"""Auto-generated protobuf stubs. Do not edit."""\n'
     )

Comment thread grpc_client/python/pyproject.toml Outdated
Comment thread grpc_client/python/setup.py Outdated
Comment thread grpc_client/python/smg_grpc_proto/proto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Dependency updates documentation Improvements or additions to documentation grpc gRPC client and router changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants