Environment:Tensorflow Serving Python Client Environment
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, ML_Serving |
| Last Updated | 2026-02-13 17:00 GMT |
Overview
Python 3.9+ client environment with TensorFlow, gRPC >= 1.24.3, and Protobuf >= 4.21.6 for interacting with TensorFlow Serving APIs.
Description
This environment provides the Python runtime and package dependencies required to use the TensorFlow Serving Python client API (`tensorflow-serving-api` pip package). It includes gRPC for making prediction requests, Protobuf for message serialization, and TensorFlow for tensor manipulation and model export. Example clients also require NumPy and Pillow (for image-based models like ResNet).
Usage
Use this environment when writing Python client code to interact with TensorFlow Serving, including sending prediction requests via gRPC or REST, exporting models with `SavedModelBuilder`, and generating model warmup data. This is the prerequisite for all Python-based example scripts in the repository.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| Python | >= 3.9 | Tested with 3.9, 3.10+ |
| Network | Access to TF Serving endpoint | gRPC (port 8500) or REST (port 8501) |
Dependencies
Python Packages
- `tensorflow` >= 1.2.0, < 3
- `grpcio` >= 1.24.3, < 2.0
- `protobuf` >= 4.21.6
- `tensorflow-serving-api` (this package bundles the above)
- `numpy` (required by example clients)
- `Pillow` (required by ResNet example client for image processing)
- `requests` (required by REST API example client)
Credentials
No credentials required for local serving. For remote endpoints:
- TLS/SSL: Optional `ssl_config_file` for secure gRPC channels
- ALTS: Optional `--use_alts_credentials` for Google ALTS authentication
Quick Install
# Install the TensorFlow Serving Python API
pip install tensorflow-serving-api
# For example clients (additional dependencies)
pip install numpy Pillow requests
Code Evidence
Package dependencies from `setup.py:62-67`:
REQUIRED_PACKAGES = [
# Match versions to what TF needs here:
# https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/pip_package/setup.py.tpl
'grpcio >= 1.24.3, < 2.0',
'protobuf>=4.21.6',
] + _TF_REQ
Python version constraint from `setup.py:83`:
python_requires='>=3.9',
TensorFlow version range from `setup.py:36`:
_TF_VERSION = '>=1.2.0,<3'
gRPC client imports from `mnist_client.py:28-39`:
import grpc
import numpy
import tensorflow as tf
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2_grpc
ResNet client imports from `resnet_client_grpc.py:21-30`:
import grpc
import numpy as np
from PIL import Image
import requests
import tensorflow as tf
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2_grpc
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `ModuleNotFoundError: No module named 'tensorflow_serving'` | tensorflow-serving-api not installed | `pip install tensorflow-serving-api` |
| `grpc._channel._InactiveRpcError` | Server not reachable on specified port | Verify server is running and port matches (default gRPC: 8500) |
| `TypeError: Descriptors cannot not be created directly` | Protobuf version mismatch | Upgrade: `pip install protobuf>=4.21.6` |
Compatibility Notes
- GPU builds prior to TF 2.1: Must use `tensorflow-gpu` package instead of `tensorflow`. From TF 2.1+, the unified `tensorflow` package includes GPU support.
- TF v1 vs v2 API: Example scripts use `tf.compat.v1` APIs. Some examples disable eager execution with `tf.compat.v1.disable_default_session()`.
Related Pages
- Implementation:Tensorflow_Serving_Mnist_Training_Example
- Implementation:Tensorflow_Serving_Mnist_Client_Inference
- Implementation:Tensorflow_Serving_Resnet_Client_GRPC_Inference
- Implementation:Tensorflow_Serving_Build_Signature_Def
- Implementation:Tensorflow_Serving_SavedModelBuilder_Export
- Implementation:Tensorflow_Serving_SavedModelBuilder_Multi_Version