Skip to content

Instantly share code, notes, and snippets.

@zomglings
Created October 30, 2019 02:47
Show Gist options
  • Save zomglings/90c756be7f7bbbe76a319eb0edce4464 to your computer and use it in GitHub Desktop.
Save zomglings/90c756be7f7bbbe76a319eb0edce4464 to your computer and use it in GitHub Desktop.
Tutorial: Using Simiotics from Python
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Simiotics from Python: Jupyter notebook\n",
"\n",
"This notebook demonstrates how the Simiotics Python client library (https://pypi.org/project/simiotics/) is used to communicate with Simiotics from a Python environment.\n",
"\n",
"## Installing simiotics\n",
"\n",
"The first step is to install the client library. Here, we use `pip` from the notebook. You can also use it from your command line by typing:\n",
"\n",
"```pip install simiotics```"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import sys"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting simiotics\n",
" Using cached https://files.pythonhosted.org/packages/92/e9/791c5536e46fc050ecc45b88536ee4b9b481b994886a72d89aff923a4d42/simiotics-0.5.2-py3-none-any.whl\n",
"Collecting grpcio<2.0.0,>=1.24.1\n",
" Using cached https://files.pythonhosted.org/packages/b9/ba/254011b066e6675411ba913dafd6e40ce8d3235bebf64fb226a7305f29ac/grpcio-1.24.3-cp37-cp37m-manylinux2010_x86_64.whl\n",
"Collecting grpcio-health-checking<2.0.0,>=1.24.1\n",
" Using cached https://files.pythonhosted.org/packages/40/ed/52c8bb51cac365979a0c9497b9f73b0fd7e0d2e7df3a746353cd660fa079/grpcio-health-checking-1.24.3.tar.gz\n",
"Collecting protobuf\n",
" Using cached https://files.pythonhosted.org/packages/d7/34/02a2083afc14adff644a1e29783f276f12f1f914ca4cab157d73bb3d2fed/protobuf-3.10.0-cp37-cp37m-manylinux1_x86_64.whl\n",
"Requirement already satisfied: six>=1.5.2 in ./.demo/lib/python3.7/site-packages (from grpcio<2.0.0,>=1.24.1->simiotics) (1.12.0)\n",
"Requirement already satisfied: setuptools in ./.demo/lib/python3.7/site-packages (from protobuf->simiotics) (40.8.0)\n",
"Installing collected packages: grpcio, protobuf, grpcio-health-checking, simiotics\n",
" Running setup.py install for grpcio-health-checking ... \u001b[?25l-\b \bdone\n",
"\u001b[?25hSuccessfully installed grpcio-1.24.3 grpcio-health-checking-1.24.3 protobuf-3.10.0 simiotics-0.5.2\n"
]
}
],
"source": [
"!{sys.executable} -m pip install simiotics"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `simiotics` library relies on environment variables to know where the Simiotics APIs are. We will communicate with the public APIs. To do this, we set the following environment variables:\n",
"\n",
"1. `SIMIOTICS_DATA_REGISTRY` to `registry-alpha.simiotics.com:7010`\n",
"\n",
"1. `SIMIOTICS_FUNCTION_REGISTRY` to `registry-alpha.simiotics.com:7011`\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import os"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"os.environ['SIMIOTICS_DATA_REGISTRY'] = 'registry-alpha.simiotics.com:7010'\n",
"os.environ['SIMIOTICS_FUNCTION_REGISTRY'] = 'registry-alpha.simiotics.com:7011'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we create a Simiotics client through which we can dispatch our commands:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from simiotics.client import client_from_env"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"simiotics_client = client_from_env()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To confirm that everything is functioning as expected, let us check that the APIs are up:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"{'data': 'SERVING', 'function': 'SERVING'}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"simiotics_client.health()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The APIs are available and are accepting calls!"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Simiotics Demo environment",
"language": "python",
"name": ".demo"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment