Skip to main content

SMG Python Bindings

This directory contains the Python bindings for SMG (Shepherd Model Gateway), built using maturin and PyO3.

Quick Start

Installation

pip install maturin
cd smg/bindings/python
maturin develop --features vendored-openssl

Usage

The smg serve command launches backend workers and the SMG router in a single command:

# sglang with gRPC (default)
smg serve --backend sglang --model-path /path/to/model --port 8080

# sglang with HTTP
smg serve --backend sglang --model-path /path/to/model --port 8080 --connection-mode http

# vLLM (gRPC only)
smg serve --backend vllm --model /path/to/model --port 8080

# TensorRT-LLM (gRPC only)
smg serve --backend trtllm --model /path/to/model --port 8080

# Multiple workers (data parallel)
smg serve --backend sglang --model-path /path/to/model --port 8080 --dp-size 4

Serve Options

Option Default Description
--backend sglang Backend to use: sglang, vllm, or trtllm
--connection-mode grpc Connection mode: grpc, http, or zmq. trtllm only supports grpc; tokenspeed only zmq; zmq (a same-host direct engine connection) is available for vllm, tokenspeed, and sglang. Over zmq the router waits for the engine's startup handshake, whose READY comes only once the engine has loaded its model: the router's --zmq-startup-timeout-secs (--router-zmq-startup-timeout-secs here; default 3600) bounds how long any one stage of it may stay silent, and must cover the engine's whole init
--host 127.0.0.1 Host for the router
--port 8080 Port for the router
--dp-size 1 Data parallel size (number of worker replicas)
--worker-host 127.0.0.1 Host for worker processes
--worker-base-port 31000 Base port for workers
--worker-startup-timeout 300 Seconds to wait for workers to become healthy

Backend-specific options (e.g., --tensor-parallel-size, --quantization) are passed through to the backend.

Secrets from the environment or files

The serving keys and the store URLs need not be on the command line, where other processes can read them (/proc/<pid>/cmdline, process listings, a Deployment's args). Each is also read from an environment variable, or from a file such as a mounted Secret, by the Python launcher (smg launch, smg serve with the --router- prefix) and by the Rust binary alike:

Setting Flag Environment File flag File environment
Shared API key --api-key SMG_API_KEY --api-key-file SMG_API_KEY_FILE
Per-tenant API keys --tenant-api-key (repeatable) SMG_TENANT_API_KEYS --tenant-api-keys-file SMG_TENANT_API_KEYS_FILE
PostgreSQL URL --postgres-db-url SMG_POSTGRES_DB_URL --postgres-db-url-file SMG_POSTGRES_DB_URL_FILE
Redis URL --redis-url SMG_REDIS_URL --redis-url-file SMG_REDIS_URL_FILE
Oracle credentials --oracle-connect-descriptor, --oracle-username, --oracle-password ATP_DSN, ATP_USER, ATP_PASSWORD – –
  • The flag beats the environment. A value (from the flag or the environment) together with a file for the same secret is refused at start-up rather than ranked: the second source of one secret is a stale one about to be honoured.
  • A single-value file holds the value alone; the surrounding whitespace (a trailing newline) is dropped, and so is the whitespace around a single value from the environment (a Secret made from a file carries the editor's newline into both); the ATP_* values are the exception, see below. An empty file, or one with more than one line, is refused.
  • SMG_TENANT_API_KEYS holds tenant_id:key entries separated by , or a newline; the file holds one entry per line, blank lines and lines starting with # skipped. A source that is set but holds no entry is refused.
  • A store URL file is read for the selected --history-backend alone. The launcher still reads the older POSTGRES_DB_URL and REDIS_URL names when the SMG_ names are unset.
  • The Oracle credentials have no file source; the launcher and the binary (--oracle-dsn, --oracle-user, --oracle-password) read the ATP_* variables when the flags are absent, as they always did, and use them exactly as set, with no trimming: a Secret for them is made with --from-literal, or from a file that ends without a newline (a password that ends in one is a wrong password to the database).
  • No value is echoed: a refusal names the sources and the path, and --help shows no value of a variable. The Rust binary's start-up record (CREDENTIAL SOURCES) names each secret's source as flag, env or file; the Python launcher emits no such record.

Directory Structure

bindings/python/
├── src/                    # Source code (src layout)
│   ├── lib.rs              # Rust/PyO3 bindings implementation
│   └── smg/                # Python source code
│       ├── __init__.py
│       ├── cli.py          # CLI entry point
│       ├── serve.py        # smg serve implementation
│       ├── launch_router.py
│       ├── router.py
│       └── router_args.py
├── tests/                  # Python unit tests
├── Cargo.toml              # Rust package configuration
├── pyproject.toml          # Python package configuration
└── README.md               # This file

Building

Development Build

pip install maturin
cd smg/bindings/python
maturin develop --features vendored-openssl

Production Build

cd smg/bindings/python
maturin build --release --out dist --features vendored-openssl
pip install dist/smg-*.whl

Testing

cd smg/bindings/python
pytest tests/

Adding a router flag

A flag lives in a few places, and the tests pin them against each other:

  1. model_gateway/src/main.rs: the clap flag, in its group of CliArgs. The Rust CLI is the reference: tests/test_cli_parity.py fails on a flag that exists on one side only.
  2. src/smg/router_args.py: a RouterArgs field, and its option in add_cli_args under the matching help group. The field goes at its alphabetical place among the keyword-only fields (every field after worker_urls, host, port), never at the tail: tests/test_arg_parser.py pins the order and says where a misplaced field belongs.
  3. src/lib.rs: the Router struct field, the #[pyo3(signature)] entry with the flag's default, the parameter of new and the field of the literal new builds, each at the same alphabetical place among the keyword-only parameters (every parameter after worker_urls, policy, host, port; pyo3 wants the signature and the parameters in one order), plus the line that hands the value to the router configuration in to_router_config. tests/test_router_config.py pins the order; tests/test_router_args_parity.py fails on a dataclass field the constructor does not take, and on a parameter the launcher never sets.
  4. The flag's own tests go next to the related ones, or in a file of their own, not at the end of tests/test_arg_parser.py, where every flag's tests would meet.

The keyword-only parameters have no position, so two pull requests that each add a flag change different lines of each file and merge without a conflict.

Metadata

Release files for smg 1.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smg 1.14.0
File Size Uploaded Provenance Actions
smg-1.14.0.tar.gz 10.0 MB Without provenance Details for smg-1.14.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for smg 1.14.0
File Actions
smg-1.14.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details for smg-1.14.0-cp38-abi3-win_amd64.whl
smg-1.14.0-cp38-abi3-musllinux_1_1_x86_64.whl CPython 3.8 abi3 Linux musl 1.1+ x86-64 Details for smg-1.14.0-cp38-abi3-musllinux_1_1_x86_64.whl
smg-1.14.0-cp38-abi3-musllinux_1_1_aarch64.whl CPython 3.8 abi3 Linux musl 1.1+ ARM64 Details for smg-1.14.0-cp38-abi3-musllinux_1_1_aarch64.whl
smg-1.14.0-cp38-abi3-manylinux_2_28_aarch64.whl CPython 3.8 abi3 Linux glibc 2.28+ ARM64 Details for smg-1.14.0-cp38-abi3-manylinux_2_28_aarch64.whl
smg-1.14.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details for smg-1.14.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
smg-1.14.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details for smg-1.14.0-cp38-abi3-macosx_11_0_arm64.whl
smg-1.14.0-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details for smg-1.14.0-cp38-abi3-macosx_10_12_x86_64.whl

Total release size: 361.7 MB

Release files / smg-1.14.0.tar.gz

Download URL smg-1.14.0.tar.gz
Size 10.0 MB
Tags Source
SHA-256 checksum
How to use checksums
d71a38083f5d8dcebd667f15f3b9144417ed223849fdf4240cb53fb76cdc7056
BLAKE2b-256 checksum
How to use checksums
d83800848a9428f8e40b2447523c36871e48940613e0d0dcc4d12fe1323ba686
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / smg-1.14.0-cp38-abi3-win_amd64.whl

Download URL smg-1.14.0-cp38-abi3-win_amd64.whl
Size 50.9 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f6130d5f862a3a84b7d589fdab68776697c64384d2754dddf80312c6e162ed5d
BLAKE2b-256 checksum
How to use checksums
019f66f3e813994f8b7750498b13702366d600405f1c5541eed754fabf48d508
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / smg-1.14.0-cp38-abi3-musllinux_1_1_x86_64.whl

Download URL smg-1.14.0-cp38-abi3-musllinux_1_1_x86_64.whl
Size 51.4 MB
Tags CPython 3.8 Linux musl 1.1+ x86-64 abi3
SHA-256 checksum
How to use checksums
68a6ea7982f47b5ddbb74fa21939d159a46cc2c2cb51e6b1453990bb77a7e502
BLAKE2b-256 checksum
How to use checksums
9842f0e4515f7b15ddab40bc4926cee627031cd74e6ea7320e97de2a19d6cff3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / smg-1.14.0-cp38-abi3-musllinux_1_1_aarch64.whl

Download URL smg-1.14.0-cp38-abi3-musllinux_1_1_aarch64.whl
Size 48.9 MB
Tags CPython 3.8 Linux musl 1.1+ ARM64 abi3
SHA-256 checksum
How to use checksums
8df5821852af499ffa0ccba9ea828d41801e51f1180a005030139cf28f1669f0
BLAKE2b-256 checksum
How to use checksums
bb43c1dfebb34b69520847d603104554362c43efd6f6ef0d1b438205e64f2a65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / smg-1.14.0-cp38-abi3-manylinux_2_28_aarch64.whl

Download URL smg-1.14.0-cp38-abi3-manylinux_2_28_aarch64.whl
Size 51.1 MB
Tags CPython 3.8 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
36d17a745717afae07f638e3fcc316cdf26f2501a6aed4cb6a407b96188394de
BLAKE2b-256 checksum
How to use checksums
8d1977ace90737945757247f86db42789e1fc40156d1a5464e24685a0dfdf014
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / smg-1.14.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL smg-1.14.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 53.4 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
536883cfd1daff55c0b96906707ad3c3b515e44bd44dc2097194816e4f4d336f
BLAKE2b-256 checksum
How to use checksums
9a20146ed3b13e9327e73baa89af936dd9f95755c8e62c9ec369c496ff0b71a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / smg-1.14.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL smg-1.14.0-cp38-abi3-macosx_11_0_arm64.whl
Size 46.7 MB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
72597f5ff5f2702b645ef6bb29acb3e06648c68835f95dd4b4b2bbf25bc8ea21
BLAKE2b-256 checksum
How to use checksums
27514982e600c51a628fbc22006a9658bf9484afcb64da8bd802cad4fb01c65a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / smg-1.14.0-cp38-abi3-macosx_10_12_x86_64.whl

Download URL smg-1.14.0-cp38-abi3-macosx_10_12_x86_64.whl
Size 49.3 MB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e786025878b4f56a6e2a81fe8f6a6d41f908cebb1d16e521bc0319ef8d732263
BLAKE2b-256 checksum
How to use checksums
108d4e9cc8f91465efd0aedf3cdc9937c30e50ed2565df2d842ca0feb8e25c60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Security for smg 1.14.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page