triton-inference-sdk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. triton_inference_sdk-0.1.0/LICENSE +21 -0
  2. triton_inference_sdk-0.1.0/PKG-INFO +213 -0
  3. triton_inference_sdk-0.1.0/README.md +183 -0
  4. triton_inference_sdk-0.1.0/pyproject.toml +109 -0
  5. triton_inference_sdk-0.1.0/setup.cfg +4 -0
  6. triton_inference_sdk-0.1.0/triton_inference_sdk.egg-info/PKG-INFO +213 -0
  7. triton_inference_sdk-0.1.0/triton_inference_sdk.egg-info/SOURCES.txt +83 -0
  8. triton_inference_sdk-0.1.0/triton_inference_sdk.egg-info/dependency_links.txt +1 -0
  9. triton_inference_sdk-0.1.0/triton_inference_sdk.egg-info/requires.txt +15 -0
  10. triton_inference_sdk-0.1.0/triton_inference_sdk.egg-info/top_level.txt +1 -0
  11. triton_inference_sdk-0.1.0/triton_sdk/__init__.py +30 -0
  12. triton_inference_sdk-0.1.0/triton_sdk/backends/__init__.py +46 -0
  13. triton_inference_sdk-0.1.0/triton_sdk/backends/base.py +188 -0
  14. triton_inference_sdk-0.1.0/triton_sdk/backends/generic.py +52 -0
  15. triton_inference_sdk-0.1.0/triton_sdk/backends/tensorrt_llm.py +188 -0
  16. triton_inference_sdk-0.1.0/triton_sdk/backends/vllm.py +87 -0
  17. triton_inference_sdk-0.1.0/triton_sdk/chat/__init__.py +5 -0
  18. triton_inference_sdk-0.1.0/triton_sdk/chat/models.py +24 -0
  19. triton_inference_sdk-0.1.0/triton_sdk/chat/templates.py +88 -0
  20. triton_inference_sdk-0.1.0/triton_sdk/client/__init__.py +5 -0
  21. triton_inference_sdk-0.1.0/triton_sdk/client/async_client.py +289 -0
  22. triton_inference_sdk-0.1.0/triton_sdk/client/base.py +140 -0
  23. triton_inference_sdk-0.1.0/triton_sdk/client/sync_client.py +213 -0
  24. triton_inference_sdk-0.1.0/triton_sdk/config/__init__.py +4 -0
  25. triton_inference_sdk-0.1.0/triton_sdk/config/environment/__init__.py +1 -0
  26. triton_inference_sdk-0.1.0/triton_sdk/config/environment/local.py +25 -0
  27. triton_inference_sdk-0.1.0/triton_sdk/config/logging.py +37 -0
  28. triton_inference_sdk-0.1.0/triton_sdk/core/__init__.py +1 -0
  29. triton_inference_sdk-0.1.0/triton_sdk/core/constants/__init__.py +35 -0
  30. triton_inference_sdk-0.1.0/triton_sdk/core/constants/backend_kind.py +9 -0
  31. triton_inference_sdk-0.1.0/triton_sdk/core/constants/endpoints.py +34 -0
  32. triton_inference_sdk-0.1.0/triton_sdk/core/constants/grpc_status.py +15 -0
  33. triton_inference_sdk-0.1.0/triton_sdk/core/constants/http_codes_message.py +12 -0
  34. triton_inference_sdk-0.1.0/triton_sdk/core/constants/log_color.py +7 -0
  35. triton_inference_sdk-0.1.0/triton_sdk/core/constants/protocol.py +9 -0
  36. triton_inference_sdk-0.1.0/triton_sdk/core/constants/retry_statuses.py +1 -0
  37. triton_inference_sdk-0.1.0/triton_sdk/core/constants/tensor_names.py +33 -0
  38. triton_inference_sdk-0.1.0/triton_sdk/core/models/__init__.py +29 -0
  39. triton_inference_sdk-0.1.0/triton_sdk/core/models/model_info.py +107 -0
  40. triton_inference_sdk-0.1.0/triton_sdk/core/models/request.py +44 -0
  41. triton_inference_sdk-0.1.0/triton_sdk/core/models/response.py +82 -0
  42. triton_inference_sdk-0.1.0/triton_sdk/core/models/tensors.py +129 -0
  43. triton_inference_sdk-0.1.0/triton_sdk/core/optional.py +42 -0
  44. triton_inference_sdk-0.1.0/triton_sdk/core/sync_runner.py +64 -0
  45. triton_inference_sdk-0.1.0/triton_sdk/core/utils.py +111 -0
  46. triton_inference_sdk-0.1.0/triton_sdk/exceptions.py +94 -0
  47. triton_inference_sdk-0.1.0/triton_sdk/openai/__init__.py +33 -0
  48. triton_inference_sdk-0.1.0/triton_sdk/openai/client/__init__.py +17 -0
  49. triton_inference_sdk-0.1.0/triton_sdk/openai/client/async_client.py +123 -0
  50. triton_inference_sdk-0.1.0/triton_sdk/openai/client/sync_client.py +74 -0
  51. triton_inference_sdk-0.1.0/triton_sdk/openai/convert.py +197 -0
  52. triton_inference_sdk-0.1.0/triton_sdk/openai/engines/__init__.py +8 -0
  53. triton_inference_sdk-0.1.0/triton_sdk/openai/engines/base.py +72 -0
  54. triton_inference_sdk-0.1.0/triton_sdk/openai/engines/frontend.py +116 -0
  55. triton_inference_sdk-0.1.0/triton_sdk/openai/engines/native.py +135 -0
  56. triton_inference_sdk-0.1.0/triton_sdk/openai/frontend.py +183 -0
  57. triton_inference_sdk-0.1.0/triton_sdk/openai/resources/__init__.py +17 -0
  58. triton_inference_sdk-0.1.0/triton_sdk/openai/resources/chat.py +112 -0
  59. triton_inference_sdk-0.1.0/triton_sdk/openai/resources/completions.py +85 -0
  60. triton_inference_sdk-0.1.0/triton_sdk/openai/resources/models.py +45 -0
  61. triton_inference_sdk-0.1.0/triton_sdk/openai/streaming/__init__.py +8 -0
  62. triton_inference_sdk-0.1.0/triton_sdk/openai/streaming/base.py +65 -0
  63. triton_inference_sdk-0.1.0/triton_sdk/openai/streaming/chat.py +57 -0
  64. triton_inference_sdk-0.1.0/triton_sdk/openai/streaming/completion.py +49 -0
  65. triton_inference_sdk-0.1.0/triton_sdk/openai/types.py +137 -0
  66. triton_inference_sdk-0.1.0/triton_sdk/py.typed +0 -0
  67. triton_inference_sdk-0.1.0/triton_sdk/settings.py +48 -0
  68. triton_inference_sdk-0.1.0/triton_sdk/transport/__init__.py +24 -0
  69. triton_inference_sdk-0.1.0/triton_sdk/transport/base.py +156 -0
  70. triton_inference_sdk-0.1.0/triton_sdk/transport/grpc.py +270 -0
  71. triton_inference_sdk-0.1.0/triton_sdk/transport/grpc_codec.py +268 -0
  72. triton_inference_sdk-0.1.0/triton_sdk/transport/http.py +317 -0
  73. triton_inference_sdk-0.1.0/triton_sdk/transport/kserve_json.py +138 -0
  74. triton_inference_sdk-0.1.0/triton_sdk/transport/protos/__init__.py +7 -0
  75. triton_inference_sdk-0.1.0/triton_sdk/transport/protos/grpc_service_pb2.py +211 -0
  76. triton_inference_sdk-0.1.0/triton_sdk/transport/protos/grpc_service_pb2.pyi +625 -0
  77. triton_inference_sdk-0.1.0/triton_sdk/transport/protos/grpc_service_pb2_grpc.py +1036 -0
  78. triton_inference_sdk-0.1.0/triton_sdk/transport/protos/health_pb2.py +42 -0
  79. triton_inference_sdk-0.1.0/triton_sdk/transport/protos/health_pb2.pyi +28 -0
  80. triton_inference_sdk-0.1.0/triton_sdk/transport/protos/health_pb2_grpc.py +117 -0
  81. triton_inference_sdk-0.1.0/triton_sdk/transport/protos/model_config_pb2.py +188 -0
  82. triton_inference_sdk-0.1.0/triton_sdk/transport/protos/model_config_pb2.pyi +666 -0
  83. triton_inference_sdk-0.1.0/triton_sdk/transport/protos/model_config_pb2_grpc.py +24 -0
  84. triton_inference_sdk-0.1.0/triton_sdk/transport/sse.py +42 -0
  85. triton_inference_sdk-0.1.0/triton_sdk/transport/tls.py +130 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vadim Shubin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,213 @@
1
+ Metadata-Version: 2.4
2
+ Name: triton-inference-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for NVIDIA Triton Inference Server focused on LLM workloads (TensorRT-LLM, vLLM)
5
+ Author-email: Shubin Vadim <midavnibush@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Shubin-vadim/triron_sdk
8
+ Project-URL: Repository, https://github.com/Shubin-vadim/triron_sdk
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Requires-Python: >=3.12
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: httpx~=0.28.1
18
+ Requires-Dist: pydantic~=2.12.3
19
+ Requires-Dist: pydantic-settings~=2.12.0
20
+ Requires-Dist: tenacity>=9.0.0
21
+ Provides-Extra: grpc
22
+ Requires-Dist: grpcio>=1.66; extra == "grpc"
23
+ Requires-Dist: protobuf>=5.28; extra == "grpc"
24
+ Provides-Extra: chat
25
+ Requires-Dist: transformers>=4.45; extra == "chat"
26
+ Requires-Dist: jinja2~=3.1.6; extra == "chat"
27
+ Provides-Extra: all
28
+ Requires-Dist: triton-inference-sdk[chat,grpc]; extra == "all"
29
+ Dynamic: license-file
30
+
31
+ # Triton-sdk
32
+
33
+ Python SDK for NVIDIA Triton Inference Server, focused on LLM workloads
34
+ (TensorRT-LLM and vLLM backends). One public API — `generate` / `stream` / `chat`,
35
+ with backend and transport (HTTP / gRPC) differences hidden inside.
36
+
37
+ Key features:
38
+
39
+ - **One LLM API across supported backends:** `generate`, `stream`, and `chat`
40
+ adapt vLLM and TensorRT-LLM model schemas, including backend-specific inputs
41
+ and outputs.
42
+ - **OpenAI-style interface for native Triton endpoints:** use
43
+ `chat.completions` and `completions` over HTTP or gRPC without deploying
44
+ Triton's OpenAI frontend. Compatibility is partial; see the limitations below.
45
+
46
+ ## Quick start
47
+
48
+ Clone the repository:
49
+
50
+ ```bash
51
+ git clone https://github.com/Shubin-vadim/triron_sdk.git
52
+ cd triron_sdk
53
+ ```
54
+
55
+ Python 3.12 or newer is required. If `uv` is not installed, install it with pip:
56
+
57
+ ```bash
58
+ python -m pip install uv
59
+ ```
60
+
61
+ Install the SDK, optional dependencies, and development dependencies in one command:
62
+
63
+ ```bash
64
+ uv sync --all-extras --dev
65
+ ```
66
+
67
+ This installs the `triton-inference-sdk` distribution into the project's `.venv`; import it
68
+ in Python as `triton_sdk`. It does **not** install Triton Inference Server or vLLM: the
69
+ SDK is a client, and it sends requests to a Triton server where a model is already
70
+ running. You do not need Triton or vLLM installed on the computer running the SDK.
71
+
72
+ ### Prepare Triton and an LLM model
73
+
74
+ If you do not already have a Triton deployment, follow NVIDIA's
75
+ [Triton Server Quickstart](https://docs.nvidia.com/deeplearning/triton-inference-server/user-guide/docs/getting_started/quickstart.html)
76
+ to install and start the server. A running Triton process alone is not enough: it must
77
+ also have an LLM backend installed and a compatible model configured and loaded in its
78
+ model repository. The SDK cannot install or load these server-side components for you.
79
+
80
+ Choose the backend you plan to use and follow its setup guide:
81
+
82
+ - **vLLM:** NVIDIA's [Triton vLLM backend guide](https://github.com/triton-inference-server/vllm_backend)
83
+ covers the backend-enabled container and sample model repository.
84
+ - **TensorRT-LLM:** NVIDIA's [TensorRT-LLM backend Getting Started guide](https://github.com/triton-inference-server/tensorrtllm_backend#getting-started)
85
+ covers the compatible container, model configuration, and server launch. Match the
86
+ container and NVIDIA driver to your GPU; gated Hugging Face models may require a token.
87
+
88
+ After following the backend guide, confirm the model is loaded and ready in Triton.
89
+ Then use its server address and Triton model name in the example below. The model's input
90
+ schema must be supported by this SDK.
91
+
92
+ ### Connect to your Triton server
93
+
94
+ Once a Triton server is prepared, connect to it and pass the **Triton model name**
95
+ configured on that server. This can be a vLLM model or a TensorRT-LLM ensemble/BLS model
96
+ with a supported text-input schema; it is not necessarily the Hugging Face model ID.
97
+
98
+ ```python
99
+ from triton_sdk import SamplingParams, TritonLLMClient
100
+
101
+ with TritonLLMClient("your-triton-host:8001", protocol="grpc") as client:
102
+ response = client.generate(
103
+ "The capital of France is",
104
+ SamplingParams(max_tokens=32),
105
+ model="your-triton-model-name",
106
+ )
107
+ print(response.text)
108
+
109
+ for chunk in client.stream(
110
+ "Tell me a short story.",
111
+ SamplingParams(max_tokens=64),
112
+ model="your-triton-model-name",
113
+ ):
114
+ print(chunk.text, end="", flush=True)
115
+ ```
116
+
117
+ To run the repository's end-to-end example, set `TRITON_DEFAULT_MODEL` to your Triton
118
+ model name and run:
119
+
120
+ PowerShell:
121
+
122
+ ```powershell
123
+ $env:TRITON_DEFAULT_MODEL = "your-triton-model-name"
124
+ uv run python examples/quickstart.py
125
+ ```
126
+
127
+ On Linux/macOS:
128
+
129
+ ```bash
130
+ export TRITON_DEFAULT_MODEL=your-triton-model-name
131
+ uv run python examples/quickstart.py
132
+ ```
133
+
134
+ The example uses HTTP at `localhost:8000` and gRPC at `localhost:8001` by default; set
135
+ `TRITON_URL` and `TRITON_GRPC_URL` to override them. Set `TRITON_OPENAI_URL` to the
136
+ address of an OpenAI-compatible Triton frontend to exercise that protocol too; otherwise,
137
+ that part of the example is skipped. The example requires both native HTTP and gRPC
138
+ endpoints, and a model configured for streaming (HTTP streaming also requires Triton's
139
+ generate extension). It uses the Qwen2.5-0.5B-Instruct tokenizer by default for chat;
140
+ set `TRITON_CHAT_TEMPLATE_MODEL` to a tokenizer matching your model. The first run may
141
+ download the tokenizer from Hugging Face.
142
+ The SDK reads model configuration from the server to select an adapter.
143
+
144
+ The SDK does not install or launch Triton, backends, or models.
145
+
146
+ ## OpenAI-compatible interface
147
+
148
+ Code written for `openai` is ported by swapping the constructor:
149
+
150
+ ```python
151
+ from triton_sdk.openai import OpenAICompatClient
152
+
153
+ client = OpenAICompatClient("localhost:8001", protocol="grpc", tokenizer="Qwen/Qwen2.5-0.5B-Instruct")
154
+ resp = client.chat.completions.create(model="vllm_model", messages=[{"role": "user", "content": "Hello"}])
155
+ resp.choices[0].message.content, resp.usage.total_tokens
156
+
157
+ for chunk in client.chat.completions.create(model="vllm_model", messages=[...], stream=True):
158
+ chunk.choices[0].delta.content
159
+ ```
160
+
161
+ Two engines behind one interface:
162
+
163
+ - `protocol="http" | "grpc"` — native KServe v2, works with any Triton; the chat template and `usage` are computed on the client.
164
+ - `protocol="openai"` — Triton's OpenAI frontend (`/v1/chat/completions`, port 9000); the template and `usage` are handled by the server,
165
+ `native` is unavailable.
166
+ `usage` is computed by the tokenizer from `tokenizer=` (without it — `None`). `tools`, `response_format`, `n > 1` are not supported
167
+ and raise `UnsupportedParameterError`; `extra_body={"top_k": ...}` forwards backend-specific parameters.
168
+
169
+ To run the standalone example against an already-running OpenAI-compatible Triton frontend
170
+ (defaults to `localhost:9000`, model `vllm_model`):
171
+
172
+ ```bash
173
+ uv run --with openai python examples/openai_sdk.py
174
+ ```
175
+
176
+ Set `TRITON_OPENAI_URL` and `TRITON_DEFAULT_MODEL` first if your frontend or model uses a
177
+ different address or name.
178
+
179
+ ## Structure
180
+
181
+ | Path | Role |
182
+ | ------------------------------ | ----------------------------------------------------------------------------------------------------------- |
183
+ | `triton_sdk/client/` | Public API: `TritonLLMClient` (sync) and `AsyncTritonLLMClient` |
184
+ | `triton_sdk/transport/` | Network layer: `TransportInterface` + `HttpTransport` / `GrpcTransport`, SSE parser, protobuf stubs |
185
+ | `triton_sdk/backends/` | Input/output schema adapters: `tensorrt_llm`, `vllm`, `generic` (generate endpoint) |
186
+ | `triton_sdk/chat/` | Chat templates: message list → raw prompt, token counting |
187
+ | `triton_sdk/openai/` | OpenAI-compatible facade: `chat.completions`, `completions`, `models` with types mirroring `openai` |
188
+ | `triton_sdk/core/models/` | Pydantic models for requests, responses, metadata, tensors |
189
+ | `triton_sdk/core/constants/` | Protocols, KServe v2 paths, error codes, retry statuses |
190
+ | `triton_sdk/settings.py` | `TritonSettings` (`pydantic-settings`, `TRITON_` prefix) |
191
+ | `triton_sdk/exceptions.py` | `TritonError` hierarchy |
192
+ | `triton_sdk/tests/` | `unit/` (transport mocks), `integration/` (live Triton, `integration` marker) |
193
+ | `examples/` | Ready-made usage scenarios |
194
+ | `model_repository/` | Example vLLM model configuration for a Triton deployment |
195
+
196
+ ## Local development and integration tests
197
+
198
+ ```bash
199
+ uv sync --all-extras --dev
200
+ cp triton_sdk/config/environment/env.sh.template env.sh && source env.sh
201
+ ./code_quality_check.sh # ruff + mypy + pytest (unit)
202
+ ```
203
+
204
+ Integration tests require a separately running Triton server and a vLLM model named
205
+ `vllm_model`, with native HTTP and gRPC endpoints. Configure the HTTP server address in
206
+ `env.sh`, then run `pytest -m integration`. The template sets the model name to
207
+ `vllm_model`; change it if your server uses another name. Set `TRITON_GRPC_URL` and
208
+ `TRITON_OPENAI_URL` when those endpoints use non-default addresses. Tests for Triton's
209
+ OpenAI frontend are skipped when the frontend is unavailable.
210
+
211
+ ## License
212
+
213
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,183 @@
1
+ # Triton-sdk
2
+
3
+ Python SDK for NVIDIA Triton Inference Server, focused on LLM workloads
4
+ (TensorRT-LLM and vLLM backends). One public API — `generate` / `stream` / `chat`,
5
+ with backend and transport (HTTP / gRPC) differences hidden inside.
6
+
7
+ Key features:
8
+
9
+ - **One LLM API across supported backends:** `generate`, `stream`, and `chat`
10
+ adapt vLLM and TensorRT-LLM model schemas, including backend-specific inputs
11
+ and outputs.
12
+ - **OpenAI-style interface for native Triton endpoints:** use
13
+ `chat.completions` and `completions` over HTTP or gRPC without deploying
14
+ Triton's OpenAI frontend. Compatibility is partial; see the limitations below.
15
+
16
+ ## Quick start
17
+
18
+ Clone the repository:
19
+
20
+ ```bash
21
+ git clone https://github.com/Shubin-vadim/triron_sdk.git
22
+ cd triron_sdk
23
+ ```
24
+
25
+ Python 3.12 or newer is required. If `uv` is not installed, install it with pip:
26
+
27
+ ```bash
28
+ python -m pip install uv
29
+ ```
30
+
31
+ Install the SDK, optional dependencies, and development dependencies in one command:
32
+
33
+ ```bash
34
+ uv sync --all-extras --dev
35
+ ```
36
+
37
+ This installs the `triton-inference-sdk` distribution into the project's `.venv`; import it
38
+ in Python as `triton_sdk`. It does **not** install Triton Inference Server or vLLM: the
39
+ SDK is a client, and it sends requests to a Triton server where a model is already
40
+ running. You do not need Triton or vLLM installed on the computer running the SDK.
41
+
42
+ ### Prepare Triton and an LLM model
43
+
44
+ If you do not already have a Triton deployment, follow NVIDIA's
45
+ [Triton Server Quickstart](https://docs.nvidia.com/deeplearning/triton-inference-server/user-guide/docs/getting_started/quickstart.html)
46
+ to install and start the server. A running Triton process alone is not enough: it must
47
+ also have an LLM backend installed and a compatible model configured and loaded in its
48
+ model repository. The SDK cannot install or load these server-side components for you.
49
+
50
+ Choose the backend you plan to use and follow its setup guide:
51
+
52
+ - **vLLM:** NVIDIA's [Triton vLLM backend guide](https://github.com/triton-inference-server/vllm_backend)
53
+ covers the backend-enabled container and sample model repository.
54
+ - **TensorRT-LLM:** NVIDIA's [TensorRT-LLM backend Getting Started guide](https://github.com/triton-inference-server/tensorrtllm_backend#getting-started)
55
+ covers the compatible container, model configuration, and server launch. Match the
56
+ container and NVIDIA driver to your GPU; gated Hugging Face models may require a token.
57
+
58
+ After following the backend guide, confirm the model is loaded and ready in Triton.
59
+ Then use its server address and Triton model name in the example below. The model's input
60
+ schema must be supported by this SDK.
61
+
62
+ ### Connect to your Triton server
63
+
64
+ Once a Triton server is prepared, connect to it and pass the **Triton model name**
65
+ configured on that server. This can be a vLLM model or a TensorRT-LLM ensemble/BLS model
66
+ with a supported text-input schema; it is not necessarily the Hugging Face model ID.
67
+
68
+ ```python
69
+ from triton_sdk import SamplingParams, TritonLLMClient
70
+
71
+ with TritonLLMClient("your-triton-host:8001", protocol="grpc") as client:
72
+ response = client.generate(
73
+ "The capital of France is",
74
+ SamplingParams(max_tokens=32),
75
+ model="your-triton-model-name",
76
+ )
77
+ print(response.text)
78
+
79
+ for chunk in client.stream(
80
+ "Tell me a short story.",
81
+ SamplingParams(max_tokens=64),
82
+ model="your-triton-model-name",
83
+ ):
84
+ print(chunk.text, end="", flush=True)
85
+ ```
86
+
87
+ To run the repository's end-to-end example, set `TRITON_DEFAULT_MODEL` to your Triton
88
+ model name and run:
89
+
90
+ PowerShell:
91
+
92
+ ```powershell
93
+ $env:TRITON_DEFAULT_MODEL = "your-triton-model-name"
94
+ uv run python examples/quickstart.py
95
+ ```
96
+
97
+ On Linux/macOS:
98
+
99
+ ```bash
100
+ export TRITON_DEFAULT_MODEL=your-triton-model-name
101
+ uv run python examples/quickstart.py
102
+ ```
103
+
104
+ The example uses HTTP at `localhost:8000` and gRPC at `localhost:8001` by default; set
105
+ `TRITON_URL` and `TRITON_GRPC_URL` to override them. Set `TRITON_OPENAI_URL` to the
106
+ address of an OpenAI-compatible Triton frontend to exercise that protocol too; otherwise,
107
+ that part of the example is skipped. The example requires both native HTTP and gRPC
108
+ endpoints, and a model configured for streaming (HTTP streaming also requires Triton's
109
+ generate extension). It uses the Qwen2.5-0.5B-Instruct tokenizer by default for chat;
110
+ set `TRITON_CHAT_TEMPLATE_MODEL` to a tokenizer matching your model. The first run may
111
+ download the tokenizer from Hugging Face.
112
+ The SDK reads model configuration from the server to select an adapter.
113
+
114
+ The SDK does not install or launch Triton, backends, or models.
115
+
116
+ ## OpenAI-compatible interface
117
+
118
+ Code written for `openai` is ported by swapping the constructor:
119
+
120
+ ```python
121
+ from triton_sdk.openai import OpenAICompatClient
122
+
123
+ client = OpenAICompatClient("localhost:8001", protocol="grpc", tokenizer="Qwen/Qwen2.5-0.5B-Instruct")
124
+ resp = client.chat.completions.create(model="vllm_model", messages=[{"role": "user", "content": "Hello"}])
125
+ resp.choices[0].message.content, resp.usage.total_tokens
126
+
127
+ for chunk in client.chat.completions.create(model="vllm_model", messages=[...], stream=True):
128
+ chunk.choices[0].delta.content
129
+ ```
130
+
131
+ Two engines behind one interface:
132
+
133
+ - `protocol="http" | "grpc"` — native KServe v2, works with any Triton; the chat template and `usage` are computed on the client.
134
+ - `protocol="openai"` — Triton's OpenAI frontend (`/v1/chat/completions`, port 9000); the template and `usage` are handled by the server,
135
+ `native` is unavailable.
136
+ `usage` is computed by the tokenizer from `tokenizer=` (without it — `None`). `tools`, `response_format`, `n > 1` are not supported
137
+ and raise `UnsupportedParameterError`; `extra_body={"top_k": ...}` forwards backend-specific parameters.
138
+
139
+ To run the standalone example against an already-running OpenAI-compatible Triton frontend
140
+ (defaults to `localhost:9000`, model `vllm_model`):
141
+
142
+ ```bash
143
+ uv run --with openai python examples/openai_sdk.py
144
+ ```
145
+
146
+ Set `TRITON_OPENAI_URL` and `TRITON_DEFAULT_MODEL` first if your frontend or model uses a
147
+ different address or name.
148
+
149
+ ## Structure
150
+
151
+ | Path | Role |
152
+ | ------------------------------ | ----------------------------------------------------------------------------------------------------------- |
153
+ | `triton_sdk/client/` | Public API: `TritonLLMClient` (sync) and `AsyncTritonLLMClient` |
154
+ | `triton_sdk/transport/` | Network layer: `TransportInterface` + `HttpTransport` / `GrpcTransport`, SSE parser, protobuf stubs |
155
+ | `triton_sdk/backends/` | Input/output schema adapters: `tensorrt_llm`, `vllm`, `generic` (generate endpoint) |
156
+ | `triton_sdk/chat/` | Chat templates: message list → raw prompt, token counting |
157
+ | `triton_sdk/openai/` | OpenAI-compatible facade: `chat.completions`, `completions`, `models` with types mirroring `openai` |
158
+ | `triton_sdk/core/models/` | Pydantic models for requests, responses, metadata, tensors |
159
+ | `triton_sdk/core/constants/` | Protocols, KServe v2 paths, error codes, retry statuses |
160
+ | `triton_sdk/settings.py` | `TritonSettings` (`pydantic-settings`, `TRITON_` prefix) |
161
+ | `triton_sdk/exceptions.py` | `TritonError` hierarchy |
162
+ | `triton_sdk/tests/` | `unit/` (transport mocks), `integration/` (live Triton, `integration` marker) |
163
+ | `examples/` | Ready-made usage scenarios |
164
+ | `model_repository/` | Example vLLM model configuration for a Triton deployment |
165
+
166
+ ## Local development and integration tests
167
+
168
+ ```bash
169
+ uv sync --all-extras --dev
170
+ cp triton_sdk/config/environment/env.sh.template env.sh && source env.sh
171
+ ./code_quality_check.sh # ruff + mypy + pytest (unit)
172
+ ```
173
+
174
+ Integration tests require a separately running Triton server and a vLLM model named
175
+ `vllm_model`, with native HTTP and gRPC endpoints. Configure the HTTP server address in
176
+ `env.sh`, then run `pytest -m integration`. The template sets the model name to
177
+ `vllm_model`; change it if your server uses another name. Set `TRITON_GRPC_URL` and
178
+ `TRITON_OPENAI_URL` when those endpoints use non-default addresses. Tests for Triton's
179
+ OpenAI frontend are skipped when the frontend is unavailable.
180
+
181
+ ## License
182
+
183
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,109 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.setuptools.packages.find]
6
+ include = ["triton_sdk*"]
7
+ exclude = ["triton_sdk.tests*"]
8
+
9
+ [tool.setuptools.package-data]
10
+ triton_sdk = ["py.typed"]
11
+
12
+ [project]
13
+ name = "triton-inference-sdk"
14
+ version = "0.1.0"
15
+ description = "Python SDK for NVIDIA Triton Inference Server focused on LLM workloads (TensorRT-LLM, vLLM)"
16
+ readme = "README.md"
17
+ requires-python = ">=3.12"
18
+ license = "MIT"
19
+ authors = [
20
+ { name = "Shubin Vadim", email = "midavnibush@gmail.com" },
21
+ ]
22
+ classifiers = [
23
+ "Development Status :: 3 - Alpha",
24
+ "Intended Audience :: Developers",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Topic :: Software Development :: Libraries :: Python Modules",
28
+ ]
29
+ dependencies = [
30
+ "httpx~=0.28.1",
31
+ "pydantic~=2.12.3",
32
+ "pydantic-settings~=2.12.0",
33
+ "tenacity>=9.0.0",
34
+ ]
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/Shubin-vadim/triron_sdk"
38
+ Repository = "https://github.com/Shubin-vadim/triron_sdk"
39
+
40
+ [project.optional-dependencies]
41
+ grpc = ["grpcio>=1.66", "protobuf>=5.28"]
42
+ chat = ["transformers>=4.45", "jinja2~=3.1.6"]
43
+ all = ["triton-inference-sdk[grpc,chat]"]
44
+
45
+ [dependency-groups]
46
+ dev = [
47
+ "colorlog~=6.10.1",
48
+ "grpcio-tools>=1.66",
49
+ "mypy>=1.18.2",
50
+ "pytest>=8.4.2",
51
+ "pytest-asyncio>=1.2.0",
52
+ "pytest-cov>=6.0.0",
53
+ "python-dotenv>=1.0.0",
54
+ "respx>=0.22.0",
55
+ "ruff>=0.14.3",
56
+ "types-protobuf>=5.28",
57
+ ]
58
+
59
+ [tool.ruff]
60
+ line-length = 120
61
+ target-version = "py312"
62
+ extend-exclude = ["triton_sdk/transport/protos"]
63
+
64
+ [tool.ruff.lint]
65
+ select = ["ALL"]
66
+ ignore = [
67
+ "D", "ANN201", "ANN401", "ANN002", "ANN003", "C90", "CPY", "COM812", "ERA", "FIX002",
68
+ "ISC001", "PERF203", "PLR09", "RUF012", "TD002", "TD003", "TRY301", "PLC0415", "PLW1641",
69
+ # SDK-specific: interface stubs with unused args,
70
+ # explicit timeout= parameters in the public async API, no TYPE_CHECKING gymnastics for pydantic models
71
+ "ARG002", "ASYNC109", "TC001", "TC002", "TC003",
72
+ ]
73
+
74
+ [tool.ruff.lint.per-file-ignores]
75
+ "triton_sdk/tests/*" = ["S101", "SLF001"]
76
+ "examples/*" = ["T201", "INP001"]
77
+ "scripts/*" = ["T201", "INP001"]
78
+
79
+ [tool.ruff.format]
80
+ quote-style = "double"
81
+ indent-style = "space"
82
+
83
+ [tool.ruff.lint.isort]
84
+ lines-after-imports = 2
85
+
86
+ [tool.ruff.lint.flake8-tidy-imports]
87
+ ban-relative-imports = "all"
88
+
89
+ [tool.mypy]
90
+ python_version = "3.12"
91
+ no_implicit_optional = true
92
+ warn_redundant_casts = true
93
+ warn_unused_ignores = false
94
+ pretty = true
95
+ show_error_codes = true
96
+ exclude = ["triton_sdk/transport/protos/"]
97
+
98
+ [[tool.mypy.overrides]]
99
+ module = ["triton_sdk.transport.protos.*", "grpc.*", "transformers.*"]
100
+ ignore_missing_imports = true
101
+ ignore_errors = true
102
+
103
+ [tool.pytest.ini_options]
104
+ asyncio_mode = "auto"
105
+ testpaths = ["triton_sdk/tests"]
106
+ addopts = "-m 'not integration'"
107
+ markers = [
108
+ "integration: requires a running Triton Inference Server",
109
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+