File size: 2,488 Bytes
a402b9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# SGLang Model Gateway Python Bindings

This directory contains the Python bindings for the SGLang Router, built using [maturin](https://github.com/PyO3/maturin) and [PyO3](https://github.com/PyO3/pyo3).

## Directory Structure

```
bindings/python/
β”œβ”€β”€ src/                    # Source code (src layout)
β”‚   β”œβ”€β”€ lib.rs              # Rust/PyO3 bindings implementation
β”‚   └── sglang_router/      # Python source code
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ version.py
β”‚       β”œβ”€β”€ launch_server.py
β”‚       β”œβ”€β”€ launch_router.py
β”‚       β”œβ”€β”€ router.py
β”‚       β”œβ”€β”€ router_args.py
β”‚       └── mini_lb.py
β”œβ”€β”€ tests/                  # Python unit tests
β”‚   β”œβ”€β”€ conftest.py
β”‚   β”œβ”€β”€ test_validation.py
β”‚   β”œβ”€β”€ test_arg_parser.py
β”‚   β”œβ”€β”€ test_router_config.py
β”‚   └── test_startup_sequence.py
β”œβ”€β”€ Cargo.toml              # Rust package configuration for bindings
β”œβ”€β”€ pyproject.toml          # Python package configuration
β”œβ”€β”€ setup.py                # Setup configuration
β”œβ”€β”€ MANIFEST.in             # Package manifest
β”œβ”€β”€ .coveragerc             # Test coverage configuration
└── README.md               # This file
```

## Building

### Development Build

```bash
# Install maturin
pip install maturin

# Build and install in development mode
cd sgl-model-gateway/bindings/python
maturin develop --features vendored-openssl
```

### Production Build

```bash
# Build wheel
cd sgl-model-gateway/bindings/python
maturin build --release --out dist --features vendored-openssl

# Install the built wheel
pip install dist/sglang_router-*.whl
```

## Testing

```bash
# Run Python unit tests (after maturin develop)
cd sgl-model-gateway/bindings/python
pytest tests/
```

## Configuration

- **pyproject.toml**: Defines package metadata, dependencies, and build configuration
- **python-source**: Set to `"src"` indicating Python source uses the src layout
- **module-name**: `sglang_router.sglang_router_rs` - the Rust extension module name

## Notes

- The Rust bindings source code is located in `src/lib.rs`
- The bindings have their own `Cargo.toml` in this directory
- The main sglang-router library is located in `../../` and is used as a dependency
- The package includes both Python code and Rust extensions built with PyO3
- PyO3 types are prefixed with `Py` in Rust but exposed to Python without the prefix using the `name` attribute