Skip to content

Commit 3fe7d2e

Browse files
authored
Merge pull request #5 from drucker/feature/pipnize-drucker-client
Merged
2 parents 2f43109 + be430ae commit 3fe7d2e

26 files changed

Lines changed: 540 additions & 70 deletions

.gitignore

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ ENV/
103103
# PyCharm
104104
.idea/
105105

106-
# grpc file
107-
drucker_pb2.py
108-
drucker_pb2_grpc.py
109-
110106
# Mac OS temporary file
111-
.DS_Store
107+
.DS_Store
108+
109+
# sqlite
110+
*.sqlite3

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[submodule "drucker-grpc-proto"]
2-
path = drucker-grpc-proto
1+
[submodule "drucker_client/grpc"]
2+
path = drucker_client/grpc
33
url = https://github.com/drucker/drucker-grpc-proto.git
44
branch = master

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ref: https://docs.travis-ci.com/user/languages/python
2+
language: python
3+
dist: trusty
4+
sudo: true
5+
services:
6+
- docker
7+
8+
matrix:
9+
include:
10+
- python: 3.4
11+
env: TOXENV=py34
12+
- python: 3.5
13+
env: TOXENV=py35
14+
- python: 3.6
15+
env: TOXENV=py36
16+
- python: 3.6
17+
env: TOXENV=coverage,codecov
18+
19+
install:
20+
- pip install tox
21+
22+
script:
23+
- tox

README.md

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# drucker-client
2-
Drucker is a framework of serving machine learning module. Drucker makes it easy to serve, manage and integrate your ML models into your existing services. Moreover, Drucker can be used on Kubernetes. This project is a SDK for accessing Drucker service of your ML module. All you need is initializing ```DruckerWorkerClient``` class.
2+
Drucker is a framework of serving machine learning module. Drucker client is a SDK for accessing Drucker.
33

44
## Parent Project
55
https://github.com/drucker/drucker-parent
@@ -10,6 +10,64 @@ https://github.com/drucker/drucker-parent
1010
- [Drucker-client](https://github.com/drucker/drucker-client) (here): SDK for accessing a drucker service.
1111
- [Drucker-example](https://github.com/drucker/drucker-example): Example of how to use drucker.
1212

13+
## Installation
14+
From source:
15+
16+
```
17+
git clone --recursive https://github.com/drucker/drucker-client.git
18+
cd drucker-client
19+
python setup.py install
20+
```
21+
22+
From [PyPi](https://pypi.org/project/drucker_client/) directly:
23+
24+
```
25+
pip install drucker_client
26+
```
27+
28+
## Example
29+
Example is available [here](example/sample.py).
30+
31+
```python
32+
from drucker_client import DruckerWorkerClient
33+
from drucker_client.logger import logger
34+
35+
36+
host = 'localhost:5000'
37+
client = DruckerWorkerClient(logger=logger, host=host)
38+
39+
input = [0,0,0,1,11,0,0,0,0,0,
40+
0,7,8,0,0,0,0,0,1,13,
41+
6,2,2,0,0,0,7,15,0,9,
42+
8,0,0,5,16,10,0,16,6,0,
43+
0,4,15,16,13,16,1,0,0,0,
44+
0,3,15,10,0,0,0,0,0,2,
45+
16,4,0,0]
46+
response = client.run_predict_arrint_arrint(input)
47+
```
48+
49+
If you want to access the Drucker which runs on Kubernetes, try it below.
50+
51+
```python
52+
from drucker_client import DruckerWorkerClient
53+
from drucker_client.logger import logger
54+
55+
56+
domain = 'example.com'
57+
app = 'drucker-sample'
58+
env = 'development'
59+
client = DruckerWorkerClient(logger=logger, domain=domain, app=app, env=env)
60+
61+
input = [0,0,0,1,11,0,0,0,0,0,
62+
0,7,8,0,0,0,0,0,1,13,
63+
6,2,2,0,0,0,7,15,0,9,
64+
8,0,0,5,16,10,0,16,6,0,
65+
0,4,15,16,13,16,1,0,0,0,
66+
0,3,15,10,0,0,0,0,0,2,
67+
16,4,0,0]
68+
response = client.run_predict_arrint_arrint(input)
69+
```
70+
1371
### Available methods of ```DruckerWorkerClient```
1472
You need to use an appropriate method for your Drucker service. The methods are generated according to the input and output formats. *V* is the length of feature vector. *M* is the number of classes. If your algorithm is a binary classifier, you set *M* to 1. If your algorithm is a multi-class classifier, you set *M* to the number of classes.
1573

@@ -47,10 +105,7 @@ The input "option" field needs to be a json format. Any style is Ok but we have
47105
|:---|:---|:---|
48106
|suppress_log_input |bool |True: NOT print the input and output to the log message. <BR>False (default): Print the input and output to the log message.
49107

50-
### Run it
108+
### Test
51109
```
52-
$ sh start.sh
110+
python -m unittest drucker_client/test/test_worker_client.py
53111
```
54-
55-
## Drucker on Kubernetes
56-
https://github.com/drucker/drucker-parent/tree/master/docs/Installation.md

__init__.py

Whitespace-only changes.

core/__init__.py

Whitespace-only changes.

drucker-grpc-proto

Lines changed: 0 additions & 1 deletion
This file was deleted.

drucker_client/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2018 The Drucker Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
__project__ = 'drucker_client'
16+
__version__ = "0.4.0"
17+
18+
from .drucker_worker_client import DruckerWorkerClient
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
#
4-
# DO NOT EDIT HERE!!
3+
54

65
import traceback
76
import types
87
import grpc
98

10-
import drucker_pb2
11-
import drucker_pb2_grpc
12-
13-
from logger.logger_interface import SystemLoggerInterface
9+
from .protobuf import drucker_pb2, drucker_pb2_grpc
10+
from .logger import SystemLoggerInterface
1411

1512

1613
def error_handling(error_response):
@@ -42,9 +39,10 @@ def _wrapper(*args, **kwargs):
4239

4340

4441
class DruckerWorkerClient:
45-
def __init__(self, logger:SystemLoggerInterface,
46-
host:str=None,
47-
domain:str=None, app:str=None, env:str=None, version:int=None):
42+
def __init__(self, logger: SystemLoggerInterface,
43+
host: str = None,
44+
domain: str = None, app: str = None,
45+
env: str = None, version: int = None):
4846
self.logger = logger
4947
self.stub = None
5048
if host is None and (domain is None or app is None or env is None):
@@ -73,11 +71,11 @@ def on_error(self, error: Exception):
7371
self.logger.error(str(error))
7472
self.logger.error(traceback.format_exc())
7573

76-
def __change_domain_app_env(self, domain:str, app:str, env:str, version:str):
74+
def __change_domain_app_env(self, domain: str, app: str, env: str, version: str):
7775
host = "{0}-{1}-{2}.{3}".format(app,version,env,domain)
7876
self.__change_host(host)
7977

80-
def __change_host(self, host:str):
78+
def __change_host(self, host: str):
8179
channel = grpc.insecure_channel(host)
8280
self.stub = drucker_pb2_grpc.DruckerWorkerStub(channel)
8381

drucker_client/grpc

Submodule grpc added at 5e57f2f

0 commit comments

Comments
 (0)