https://github.com/hydrospheredata/hydro-serving-python
Python runtime for the Hydrosphere.io project.
https://github.com/hydrospheredata/hydro-serving-python
hydrosphere python python-runtime
Last synced: 9 months ago
JSON representation
Python runtime for the Hydrosphere.io project.
- Host: GitHub
- URL: https://github.com/hydrospheredata/hydro-serving-python
- Owner: Hydrospheredata
- License: apache-2.0
- Created: 2017-12-18T14:25:31.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T05:55:08.000Z (about 3 years ago)
- Last Synced: 2025-03-28T19:11:31.841Z (9 months ago)
- Topics: hydrosphere, python, python-runtime
- Language: Python
- Homepage: http://docs.hydrosphere.io
- Size: 162 KB
- Stars: 3
- Watchers: 10
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hydro-serving-python
Python runtime for [Hydrosphere Serving](https://github.com/Hydrospheredata/hydro-serving).
Provides a GRPC API for Python scripts.
Supported versions are: python-3.7 python-3.8
## Build commands
- `make test`
- `make python-${VERSION}` - build docker runtime with python:${VERSION}-alpine base image
- `make clean` - clean repository from temp files
## Usage
This runtime uses `src/func_main.py` script as an entry point.
You may create any arbitrary Python application within,
just keep in mind that the entry point of your script has to be located in
`src/func_main.py`.
Example of a `func_main.py`:
```python
import pandas as pd
from joblib import load
# Load an ML model during runtime initialisation
clf = load('/model/files/classification_model.joblib')
# This function is called on each request
# Input and output must comply with your model's signature
def predict(**kwargs):
# kwargs is a dict with Numpy arrays or scalars you've specified in a signature
x = pd.DataFrame.from_dict({"request": kwargs}).T
predicted = clf.predict(x)
return {"income": int(predicted)}
```
or if you wish to work with proto messages:
```python
return {"income": TensorProto(int_val=[int(predicted)],
dtype=DT_INT32,
tensor_shape=TensorShapeProto())}
```