diff --git a/sgl-router/bindings/python/sglang_router/cli.py b/sgl-router/bindings/python/sglang_router/cli.py index caaf8c99a..ef385078a 100755 --- a/sgl-router/bindings/python/sglang_router/cli.py +++ b/sgl-router/bindings/python/sglang_router/cli.py @@ -15,6 +15,8 @@ import os import sys from typing import List, Optional +from sglang_router.sglang_router_rs import get_short_version_string, get_version_string + def create_parser() -> argparse.ArgumentParser: """Create the main CLI parser with subcommands.""" @@ -51,6 +53,14 @@ def main(argv: Optional[List[str]] = None) -> None: if argv is None: argv = sys.argv[1:] + # Handle version flags before parsing + if argv and argv[0] in ["--version", "-V"]: + if argv[0] == "--version": + print(get_version_string()) + else: + print(get_short_version_string()) + sys.exit(0) + # Handle empty command - show help if not argv or argv[0] not in ["launch", "server", "-h", "--help"]: parser = create_parser() diff --git a/sgl-router/bindings/python/src/lib.rs b/sgl-router/bindings/python/src/lib.rs index e145ca1f9..000734ecc 100644 --- a/sgl-router/bindings/python/src/lib.rs +++ b/sgl-router/bindings/python/src/lib.rs @@ -704,6 +704,18 @@ impl Router { } } +/// Get formatted version information string with full build details +#[pyfunction] +fn get_version_string() -> String { + version::get_version_string() +} + +/// Get short version information string +#[pyfunction] +fn get_short_version_string() -> String { + version::get_short_version_string() +} + #[pymodule] fn sglang_router_rs(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; @@ -712,5 +724,7 @@ fn sglang_router_rs(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_function(wrap_pyfunction!(get_version_string, m)?)?; + m.add_function(wrap_pyfunction!(get_short_version_string, m)?)?; Ok(()) }