{"id":23448305,"url":"https://github.com/triton-inference-server/pytriton","last_synced_at":"2025-05-15T12:07:09.622Z","repository":{"id":150148017,"uuid":"563462295","full_name":"triton-inference-server/pytriton","owner":"triton-inference-server","description":"PyTriton is a Flask/FastAPI-like interface that simplifies Triton's deployment in Python environments.","archived":false,"fork":false,"pushed_at":"2025-02-12T10:34:50.000Z","size":8433,"stargazers_count":790,"open_issues_count":10,"forks_count":53,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-05-15T12:07:03.177Z","etag":null,"topics":["deep-learning","gpu","inference"],"latest_commit_sha":null,"homepage":"https://triton-inference-server.github.io/pytriton/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/triton-inference-server.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-08T17:00:55.000Z","updated_at":"2025-05-05T09:15:12.000Z","dependencies_parsed_at":"2023-06-28T12:15:09.770Z","dependency_job_id":"c26c5ec9-4cd0-4b3a-9b48-fa93d525c10b","html_url":"https://github.com/triton-inference-server/pytriton","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triton-inference-server%2Fpytriton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triton-inference-server%2Fpytriton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triton-inference-server%2Fpytriton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triton-inference-server%2Fpytriton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/triton-inference-server","download_url":"https://codeload.github.com/triton-inference-server/pytriton/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","gpu","inference"],"created_at":"2024-12-23T22:14:55.277Z","updated_at":"2025-05-15T12:07:04.605Z","avatar_url":"https://github.com/triton-inference-server.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003c!--\nCopyright (c) 2022-2023, NVIDIA CORPORATION \u0026 AFFILIATES. All rights reserved.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n--\u003e\n\n# PyTriton\n\nWelcome to PyTriton, a Flask/FastAPI-like framework designed to streamline the use of NVIDIA's [Triton Inference Server](https://github.com/triton-inference-server) within Python environments. PyTriton enables serving Machine Learning models with ease, supporting direct deployment from Python.\n\nFor comprehensive guidance on how to deploy your models, optimize performance, and explore the API, delve into the extensive resources found in our [documentation](https://triton-inference-server.github.io/pytriton).\n\n## Features at a Glance\n\nThe distinct capabilities of PyTriton are summarized in the feature matrix:\n\n| Feature | Description |\n| ------- | ----------- |\n| Native Python support | You can create any [Python function](https://triton-inference-server.github.io/pytriton/latest/inference_callables/) and expose it as an HTTP/gRPC API. |\n| Framework-agnostic | You can run any Python code with any framework of your choice, such as: PyTorch, TensorFlow, or JAX. |\n| Performance optimization | You can benefit from [dynamic batching](https://triton-inference-server.github.io/pytriton/latest/inference_callables/decorators/#batch), response cache, model pipelining, [clusters](https://triton-inference-server.github.io/pytriton/latest/guides/deploying_in_clusters/), performance [tracing](https://triton-inference-server.github.io/pytriton/latest/guides/distributed_tracing/), and GPU/CPU inference.\n| Decorators | You can use batching [decorators](https://triton-inference-server.github.io/pytriton/latest/inference_callables/decorators/) to handle batching and other pre-processing tasks for your inference function. |\n| Easy [installation](https://triton-inference-server.github.io/pytriton/latest/installation/) and setup | You can use a simple and familiar interface based on Flask/FastAPI for easy installation and [setup](https://triton-inference-server.github.io/pytriton/latest/binding_models/).  |\n| [Model clients](https://triton-inference-server.github.io/pytriton/latest/clients)   | You can access high-level model clients for HTTP/gRPC requests with configurable options and both synchronous and [asynchronous](https://triton-inference-server.github.io/pytriton/latest/clients/#asynciomodelclient)  API. |\n| Streaming (alpha) | You can stream partial responses from a model by serving it in a [decoupled mode](https://triton-inference-server.github.io/pytriton/latest/clients/#decoupledmodelclient). |\n\nLearn more about PyTriton's [architecture](https://triton-inference-server.github.io/pytriton/latest/high_level_design/).\n\n\n## Prerequisites\n\nBefore proceeding with the installation of PyTriton, ensure your system meets the following criteria:\n\n- **Operating System**: Compatible with glibc version `2.35` or higher.\n  - Primarily tested on Ubuntu 22.04.\n  - Other supported OS include Debian 11+, Rocky Linux 9+, and Red Hat UBI 9+.\n  - Use `ldd --version` to verify your glibc version.\n- **Python**: Version `3.8` or newer.\n- **pip**: Version `20.3` or newer.\n- **libpython**: Ensure `libpython3.*.so` is installed, corresponding to your Python version.\n\n\n## Install\n\nThe PyTriton can be installed from [pypi.org](https://pypi.org/project/nvidia-pytriton/) by running the following command:\n\n```shell\npip install nvidia-pytriton\n```\n\n**Important**: The Triton Inference Server binary is installed as part of the PyTriton package.\n\nDiscover more about PyTriton's [installation procedures](https://triton-inference-server.github.io/pytriton/latest/installation/), including Docker usage, prerequisites, and insights into [building binaries from source](https://triton-inference-server.github.io/pytriton/latest/guides/building/) to match your specific Triton server versions.\n\n\n## Quick Start\n\nThe quick start presents how to run Python model in Triton Inference Server without need to change the current working\nenvironment. In the example we are using a simple `Linear` model.\n\nThe `infer_fn` is a function that takes an `data` tensor and returns a list with single output tensor. The `@batch` from [batching decorators](https://triton-inference-server.github.io/pytriton/latest/inference_callables/decorators/) is used to handle batching for the model.\n\n```python\nimport numpy as np\nfrom pytriton.decorators import batch\n\n@batch\ndef infer_fn(data):\n    result = data * np.array([[-1]], dtype=np.float32)  # Process inputs and produce result\n    return [result]\n```\n\n\nIn the next step, you can create the binding between the inference callable and Triton Inference Server using the `bind` method from pyTriton. This method takes the model name, the inference callable, the inputs and outputs tensors, and an optional model configuration object.\n\n\u003c!--pytest-codeblocks:cont--\u003e\n\n```python\nfrom pytriton.model_config import Tensor\nfrom pytriton.triton import Triton\ntriton = Triton()\ntriton.bind(\n    model_name=\"Linear\",\n    infer_func=infer_fn,\n    inputs=[Tensor(name=\"data\", dtype=np.float32, shape=(-1,)),],\n    outputs=[Tensor(name=\"result\", dtype=np.float32, shape=(-1,)),],\n)\ntriton.run()\n```\n\nFinally, you can send an inference query to the model using the `ModelClient` class. The `infer_sample` method takes the input data as a numpy array and returns the output data as a numpy array. You can learn more about the `ModelClient` class in the [clients](https://triton-inference-server.github.io/pytriton/latest/clients/) section.\n\n\u003c!--pytest-codeblocks:cont--\u003e\n\n```python\nfrom pytriton.client import ModelClient\n\nclient = ModelClient(\"localhost\", \"Linear\")\ndata = np.array([1, 2, ], dtype=np.float32)\nprint(client.infer_sample(data=data))\n```\nAfter the inference is done, you can stop the Triton Inference Server and close the client:\n\n\u003c!--pytest-codeblocks:cont--\u003e\n\n```python\nclient.close()\ntriton.stop()\n```\n\nThe output of the inference should be:\n\n\u003c!--pytest.mark.skip--\u003e\n```python\n{'result': array([-1., -2.], dtype=float32)}\n```\n\n\nFor the full example, including defining the model and binding it to the Triton server, check out our detailed [Quick Start](https://triton-inference-server.github.io/pytriton/latest/quick_start/) instructions. Get your model up and running, explore how to serve it, and learn how to [invoke it from client applications](https://triton-inference-server.github.io/pytriton/latest/clients/).\n\n\nThe full example code can be found in [examples/linear_random_pytorch](examples/linear_random_pytorch).\n\n## Examples\n\nThe [examples](examples) page presents various cases of serving models using PyTriton. You can find simple examples of running PyTorch, TensorFlow2, JAX, and simple Python models. Additionally, we have prepared more advanced scenarios like online learning, multi-node models, or deployment on Kubernetes using PyTriton. Each example contains instructions describing how to build and run the example. Learn more about how to use PyTriton by reviewing our examples.\n\n\n## Useful Links\n\n- [Changelog](https://triton-inference-server.github.io/pytriton/latest/CHANGELOG/)\n- [Version Management](https://triton-inference-server.github.io/pytriton/latest/CONTRIBUTING/#version-management)\n- [Contributing](https://triton-inference-server.github.io/pytriton/latest/CONTRIBUTING/)\n- [Known Issues](https://triton-inference-server.github.io/pytriton/latest/known_issues/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriton-inference-server%2Fpytriton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftriton-inference-server%2Fpytriton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriton-inference-server%2Fpytriton/lists"}