katonic-sdk 6.0.0.11rc0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. katonic_sdk-6.0.0.11rc0/LICENSE +21 -0
  2. katonic_sdk-6.0.0.11rc0/PKG-INFO +379 -0
  3. katonic_sdk-6.0.0.11rc0/README.md +300 -0
  4. katonic_sdk-6.0.0.11rc0/pyproject.toml +115 -0
  5. katonic_sdk-6.0.0.11rc0/sdk/katonic/__init__.py +15 -0
  6. katonic_sdk-6.0.0.11rc0/sdk/katonic/genai/__init__.py +0 -0
  7. katonic_sdk-6.0.0.11rc0/sdk/katonic/genai/core.py +2 -0
  8. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/__init__.py +22 -0
  9. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/__version__.py +3 -0
  10. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/completion.py +214 -0
  11. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/logutils.py +57 -0
  12. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/__init__.py +0 -0
  13. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/ai21_llm.py +33 -0
  14. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/alephalpha_llm.py +37 -0
  15. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/anthropic_llm.py +26 -0
  16. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/anyscale_llm.py +28 -0
  17. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/azure_llm.py +32 -0
  18. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/bedrock_llm.py +99 -0
  19. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/cohere_llm.py +32 -0
  20. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/completion.py +76 -0
  21. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/factory.py +151 -0
  22. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/google_llm.py +31 -0
  23. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/groq_llm.py +23 -0
  24. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/huggingface_llm.py +72 -0
  25. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/katonic_llm.py +77 -0
  26. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/lighton_llm.py +2 -0
  27. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/mappings.py +221 -0
  28. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/nvidia_llm.py +34 -0
  29. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/openai_chat_llm.py +30 -0
  30. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/openai_llm.py +43 -0
  31. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/openrouter_llm.py +44 -0
  32. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/perplexity_llm.py +39 -0
  33. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/replicate_llm.py +38 -0
  34. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/sambanova_llm.py +145 -0
  35. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/tgi_llm.py +83 -0
  36. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/togetherai_llm.py +32 -0
  37. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/models/vllm_llm.py +96 -0
  38. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/multimodal/openai_vision.py +44 -0
  39. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/platform_logger.py +383 -0
  40. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/schemas.py +7 -0
  41. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/utilities/__init__.py +14 -0
  42. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/utilities/mongo_init.py +8 -0
  43. katonic_sdk-6.0.0.11rc0/sdk/katonic/llm/utilities/utils.py +24 -0
  44. katonic_sdk-6.0.0.11rc0/sdk/katonic/log/__init__.py +26 -0
  45. katonic_sdk-6.0.0.11rc0/sdk/katonic/log/client.py +383 -0
  46. katonic_sdk-6.0.0.11rc0/sdk/katonic/log/logmodel.py +355 -0
  47. katonic_sdk-6.0.0.11rc0/sdk/katonic/log/utils.py +28 -0
  48. katonic_sdk-6.0.0.11rc0/sdk/katonic/py.typed +0 -0
  49. katonic_sdk-6.0.0.11rc0/sdk/katonic/version.py +17 -0
  50. katonic_sdk-6.0.0.11rc0/sdk/katonic_sdk.egg-info/PKG-INFO +379 -0
  51. katonic_sdk-6.0.0.11rc0/sdk/katonic_sdk.egg-info/SOURCES.txt +54 -0
  52. katonic_sdk-6.0.0.11rc0/sdk/katonic_sdk.egg-info/dependency_links.txt +1 -0
  53. katonic_sdk-6.0.0.11rc0/sdk/katonic_sdk.egg-info/requires.txt +64 -0
  54. katonic_sdk-6.0.0.11rc0/sdk/katonic_sdk.egg-info/top_level.txt +1 -0
  55. katonic_sdk-6.0.0.11rc0/setup.cfg +4 -0
  56. katonic_sdk-6.0.0.11rc0/setup.py +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 katonic-dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,379 @@
1
+ Metadata-Version: 2.4
2
+ Name: katonic-sdk
3
+ Version: 6.0.0.11rc0
4
+ Summary: A modern, enterprise-ready MLOps Python SDK
5
+ Author-email: "Katonic Pty Ltd." <shailesh.kumar@katonic.ai>
6
+ License: MIT
7
+ Project-URL: Homepage, https://www.katonic.ai/
8
+ Project-URL: Documentation, https://docs.katonic.ai/
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: boto3<2.0.0,>=1.19.12
18
+ Requires-Dist: LunarCalendar>=0.0.9
19
+ Requires-Dist: certifi>=2017.4.17
20
+ Requires-Dist: click<9.0.0,>=7.1.1
21
+ Requires-Dist: colorama>=0.4.0
22
+ Requires-Dist: convertdate>=2.1.2
23
+ Requires-Dist: cron-descriptor>=1.2.0
24
+ Requires-Dist: deprecation<3.0.0,>=2.1.0
25
+ Requires-Dist: func-timeout>=4.0.0
26
+ Requires-Dist: greenlet<3.0.0,>=1.1.1
27
+ Requires-Dist: gunicorn<22.0.0,>=20.1.0
28
+ Requires-Dist: humanize>=3.0.0
29
+ Requires-Dist: importlib-metadata>=4.8.1; python_version < "3.10"
30
+ Requires-Dist: isodate>=0.6.0
31
+ Requires-Dist: markdown<4.0.0,>=3.0
32
+ Requires-Dist: mlflow<3.0.0,>=2.0.1
33
+ Requires-Dist: msgpack<2.0.0,>=1.0.0
34
+ Requires-Dist: packaging<25.0.0,>=21.2
35
+ Requires-Dist: parsedatetime>=2.0.0
36
+ Requires-Dist: protobuf<5.0.0,>=3.19.4
37
+ Requires-Dist: pyarrow<15.0.0,>=6.0.0
38
+ Requires-Dist: pydantic<3.0.0,>=1.8.2
39
+ Requires-Dist: pyparsing>=2.0.0
40
+ Requires-Dist: python-dateutil>=2.8.0
41
+ Requires-Dist: python-dotenv>=0.19.0
42
+ Requires-Dist: python-geohash>=0.8.0
43
+ Requires-Dist: pyyaml<7.0.0,>=5.3
44
+ Requires-Dist: requests<3.0.0,>=2.25.0
45
+ Requires-Dist: scikit-learn<2.0.0,>=1.1.3
46
+ Requires-Dist: tqdm<5.0.0,>=4.36.1
47
+ Requires-Dist: typing-extensions<5.0.0,>=3.10.0
48
+ Requires-Dist: zipp<4.0.0,>=3.5.0
49
+ Requires-Dist: fastapi<1.0.0,>=0.95.0
50
+ Requires-Dist: langchain<1.0.0,>=0.1.0
51
+ Requires-Dist: langchain-openai<1.0.0,>=0.0.5
52
+ Requires-Dist: langchain-anthropic<1.0.0,>=0.1.0
53
+ Requires-Dist: langchain-google-genai<3.0.0,>=1.0.0
54
+ Requires-Dist: langchain-groq<1.0.0,>=0.1.0
55
+ Requires-Dist: langchain-together<1.0.0,>=0.1.0
56
+ Requires-Dist: langchain-nvidia-ai-endpoints<1.0.0,>=0.1.0
57
+ Requires-Dist: langchain-community<1.0.0,>=0.0.10
58
+ Requires-Dist: cohere<6.0.0,>=4.0.0
59
+ Requires-Dist: replicate<2.0.0,>=0.8.0
60
+ Requires-Dist: aleph-alpha-client<4.0.0,>=2.0.0
61
+ Requires-Dist: google-api-python-client<3.0.0,>=2.0.0
62
+ Requires-Dist: huggingface-hub<1.0.0,>=0.15.0
63
+ Requires-Dist: transformers<5.0.0,>=4.20.0
64
+ Requires-Dist: tokenizers<1.0.0,>=0.13.0
65
+ Requires-Dist: tiktoken<1.0.0,>=0.3.0
66
+ Requires-Dist: pymongo<5.0.0,>=4.0.0
67
+ Requires-Dist: python-jose[cryptography]<4.0.0,>=3.3.0
68
+ Requires-Dist: cryptography<43.0.0,>=3.0.0
69
+ Requires-Dist: redis<6.0.0,>=4.0.0
70
+ Requires-Dist: loguru<1.0.0,>=0.6.0
71
+ Requires-Dist: openai<2.0.0,>=1.0.0
72
+ Provides-Extra: dev
73
+ Requires-Dist: pytest>=6.0; extra == "dev"
74
+ Requires-Dist: pytest-cov; extra == "dev"
75
+ Requires-Dist: mypy; extra == "dev"
76
+ Requires-Dist: black; extra == "dev"
77
+ Requires-Dist: flake8; extra == "dev"
78
+ Dynamic: license-file
79
+
80
+ <p align="center">
81
+ <a href="https://katonic.ai/">
82
+ <img src="https://katonic.ai/assets/brand/Logo.png" width="550">
83
+ </a>
84
+ </p>
85
+ <br />
86
+
87
+ [![Docs Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://docs.katonic.ai/)
88
+ [![License](https://img.shields.io/badge/License-MIT-blue)](https://github.com/katonic-dev/katonic-sdk/blob/master/LICENSE)
89
+ [![PYPI](https://img.shields.io/pypi/v/katonic.svg)](https://pypi.python.org/pypi/katonic)
90
+
91
+ Katonic Python SDK for Complete ML Model Life Cycle.
92
+
93
+ Katonic Python SDK is a comprehensive package to perform all the Machine Learning and Data Science related operations.
94
+
95
+ For a complete list of examples and notebooks, please take a look at the [Examples](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk).
96
+
97
+ ## Minimum Requirements
98
+ * Katonic Platform 3.3 or Higher.
99
+ * Python 3.8 or Higher.
100
+
101
+ ## Download using pip for the base package.
102
+ ```sh
103
+ pip install katonic
104
+ ```
105
+
106
+ Katonic base package installation consists log packages to log your standard or custom built model in to Katonic model registry, see example below.
107
+
108
+ The topics in this page:
109
+
110
+ - [Connectors](#connectors)
111
+ - [Filemanager](#filemanager)
112
+ - Feature Engineering
113
+ - [Feature Store](#feature-store)
114
+ - [Experiment Operations](#experiment-operations)
115
+ - [Registry Operations](#registry-operations)
116
+ - [Pipeline Operations](#pipeline-operations)
117
+ - [Drift](#drift)
118
+
119
+ ### Connectors
120
+
121
+ A typical AI model life cycle starts with loading the data into your workspace and analyzing it to discover useful insights. for that you can use Katonic's SDK, there are several connectors inside it you can use to load the data and put it where ever you want to work with. Ex. Azure blob, MySql, Postgres etc.
122
+
123
+ ### Install Connectors.
124
+ ```python
125
+ pip install katonic[connectors]
126
+ ```
127
+ ### Connector example to get the data from SNOWFLAKE.
128
+ *snowflake-credentials.json*
129
+
130
+ ```json
131
+ {
132
+ "USER": "username",
133
+ "PASSWORD": "password",
134
+ "ACCOUNT": "id.uae-north.azure",
135
+ "DATABASE": "SNOWFLAKE_SAMPLE_DATA",
136
+ "TABLE_NAME": "CUSTOMER",
137
+ "SCHEMA": "TPCH_SF1",
138
+ "WAREHOUSE": "COMPUTE_WH"
139
+ }
140
+ ```
141
+ ```python
142
+ # Define all your configurations inside a JSON file.
143
+ import json
144
+
145
+ with open('snowflake-credentials.json') as f:
146
+ config = json.load(f)
147
+ ```
148
+ Initializing the SnowFlakeConnector with the provided credentials and configuration.
149
+ ```python
150
+ from katonic.connectors.python.snowflake import SnowFlakeConnector
151
+
152
+ df = SnowFlakeConnector(
153
+ user=config["USER"],
154
+ password=config["PASSWORD"],
155
+ account=config["ACCOUNT"],
156
+ database=config["DATABASE"],
157
+ table_name=config["TABLE_NAME"],
158
+ schema=config["SCHEMA"],
159
+ warehouse=config["WAREHOUSE"],
160
+ query="SELECT * FROM TPCH_SF1.CUSTOMER",
161
+ output="local",
162
+ file_name="driver_data",
163
+ )
164
+ ```
165
+ ```python
166
+ df.get_data()
167
+ ```
168
+
169
+ ```output
170
+ >>> Connection to snowflake established Successfully.
171
+ >>> File saved to your 'local' file system with name 'snowflake_TPCH_SF1_SNOWFLAKE_SAMPLE_DATA_driver_data_2022_04_20_08_46_38.csv' Successfully.
172
+ ```
173
+ You can explore the Connectors examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/connectors).
174
+
175
+ ### Filemanager
176
+
177
+ Once getting the data you can use Katonic Filemanager to Get, Store and Update or manipulate Objects within the file manager with Katonic SDK.
178
+
179
+ ### Install Filemanager.
180
+ ```python
181
+ pip install katonic[filemanager]
182
+ ```
183
+ ### Filemanager example to put/move the object from filemanager's public bucket to private bucket.
184
+
185
+ *filemanager-credentials.json*
186
+
187
+ ```json
188
+ {
189
+ "ACCESS_KEY":"TV6WFGHTR3TFBIBAO0R",
190
+ "SECRET_KEY":"BoW+p+iLAMNS4cbUNsSLVEmscITdTDMLXC8Emfz",
191
+ "PRIVATE_BUCKET":"private-storage-6583",
192
+ "PUBLIC_BUCKET":"shared-storage",
193
+ }
194
+ ```
195
+ ```python
196
+ # Define all your configurations inside a JSON file.
197
+ import json
198
+
199
+ with open('filemanager-credentials.json') as f:
200
+ config = json.load(f)
201
+ ```
202
+ Initializing the Filemanager with the provided credentials and configuration.
203
+ ```python
204
+ from katonic.filemanager.session import Filemanager
205
+
206
+ fm = Filemanager(
207
+ access_key=config["ACCESS_KEY"],
208
+ secret_key=config["SECRET_KEY"],
209
+ )
210
+
211
+ client = fm.clientV1
212
+ ```
213
+ ```python
214
+ client.fput_object(
215
+ config["BUCKET"],
216
+ "/home/data/sample-file.txt",
217
+ "/data/sample-file.txt"
218
+ )
219
+ ```
220
+ You can explore the Filemanager examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/filemanager).
221
+
222
+ ### Feature Store
223
+
224
+ Once you loaded all the necessary data that you want to work with. You'll do the preprocessing of it. Which consists of Handling the missing values, Removing the Outliers, Scaling the Data and Encoding the features etc. Once you've finished preprocessing the data. You need to ingest the data into a Feature store.
225
+
226
+ By uploading the clean data to a feature store, you can share it across the organization. So that other teams and data scientist working on the same problem can make use of it. By this way you can achieve Feature Reusability.
227
+
228
+ Training models and making predictions from the Feature store data will improve the consistency between the training data and serving data otherwise it will lead to training-serving skew.
229
+
230
+ ### Install Feature Store.
231
+ ```python
232
+ pip install katonic[fs]
233
+ ```
234
+
235
+ You can explore the feature store examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/feature-store).
236
+
237
+ ### Experiment Operations
238
+
239
+ Training Machine Learning models just with one or two lines of code, can be done by the Auto ML component inside the Katonic SDK.
240
+
241
+ Even all the metrics for Classification and Regression will get catalouged using SDK. Available Metrices are Accuracy score, F-1 score, Precison, Recall, Log loss, Mean Squared Error, Mean Absolute Error and Root Mean Squared Error.
242
+
243
+ ### Install Auto ML.
244
+ ```python
245
+ pip install katonic[ml]
246
+ ```
247
+ ### Auto ML Examples.
248
+ ```python
249
+ from katonic.ml.client import set_exp
250
+ from katonic.ml.classification import Classifier
251
+
252
+ # Creating a new experiment using set_exp function from ml client.
253
+ exp_name = "customer_churn_prediction"
254
+ set_exp(exp_name)
255
+
256
+ clf = Classifier(X_train,X_test,y_train,y_test, exp_name)
257
+
258
+ clf.GradientBoostingClassifier()
259
+ clf.DecisionTreeClassifier(max_depth=8, criterion="gini")
260
+
261
+ # Get registered models and metrics in Mlflow
262
+ df_runs = clf.search_runs(exp_id)
263
+ print("Number of runs done : ", len(df_runs))
264
+ ```
265
+
266
+ You can explore the automl examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/automl).
267
+
268
+ ### Registry Operations
269
+
270
+ Once you finished training the models with your data. Katonic's SDK will keep track of all the models and store the Model metadata and metrices inside the Experiment Registry. From there you can choose the best model and send it into Model Registy.
271
+
272
+ ### Install Log.
273
+ ```python
274
+ pip install katonic
275
+ ```
276
+ ### Logging ML Model Examples.
277
+ ```python
278
+ from katonic.log.logmodel import LogModel
279
+
280
+ from xgboost import XGBClassifier
281
+
282
+ # Creating a new experiment using set_exp function from log client.
283
+ exp_name = "diabetes_prediction"
284
+ lm = LogModel(exp_name)
285
+
286
+ clf = XGBClassifier(random_state=0)
287
+ clf.fit(X_train, y_train)
288
+
289
+ artifact_path = # define custom artifact path name (str)
290
+ model_mertics = # define custom metric in dictionary form
291
+
292
+ # Logging ML model
293
+ lm.model_logging(
294
+ model_name="xgboost",
295
+ model_type="xgboost",
296
+ model=clf,
297
+ artifact_path=artifact_path,
298
+ current_working_dir="xgboost_model.ipynb",
299
+ metrics=model_mertics
300
+ )
301
+ ```
302
+
303
+ You can explore the logs examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/log).
304
+
305
+ In Model Registy you can store the Best models according to your performance Metrices. By using the model registy you can tag the models with `staging` or `production`. The models that are with the tag `production` can be Deployed to the production and the models with `staging` tag can get a review check from the QA team and get to the further stages.
306
+
307
+ ### Pipeline Operations
308
+
309
+ No Data Scientist want to do the same thing again and again, instead of that Data Scientist want to use the previous work that he had done for the future purposes. We can do the same thing inside an AI Model Life Cycle.
310
+
311
+ We can convert all the work that we had done till now into a Scalable Pipeline. For that you can use the Pipelines component inside the Katonic SDK. If you want to perform the same operations with the different data, you just need to change the data source and run the pipeline. Every thing will get done automatically in a scalable manner.
312
+
313
+ ### Install Pipelines.
314
+ ```python
315
+ pip install katonic[pipeline]
316
+ ```
317
+ ## How to create and execute a pipeline using Katonic SDK.
318
+
319
+ * Create a pipeline function
320
+
321
+ * create a pipeline by defining task inside a pipeline function
322
+ ```python
323
+ from katonic.pipeline.pipeline import dsl, create_component_from_func
324
+
325
+ def print_something(data: str):
326
+ print(data)
327
+
328
+ @dsl.pipeline(
329
+ name='Print Something',
330
+ description='A pipeline that prints some data'
331
+ )
332
+ def pipeline():
333
+ print_something_op = create_component_from_func(func=print_something)
334
+ data = "Hello World!!"
335
+ print_something_op(data)
336
+ ```
337
+ create_component_from_func is used to convert functions to components that is stored inside print_something, data is passed inside print_something_op to print it.
338
+
339
+ Compiling And Running: Here pipeline experiment name, function is defined.
340
+ ```python
341
+ from datetime import datetime
342
+ import uuid
343
+
344
+ EXPERIMENT_NAME = "Print_Something"
345
+ pipeline_func = pipeline
346
+ ```
347
+ using the pipeline funcion and yaml filename the pipeline is compiled that generated the .yaml file.
348
+
349
+ kfp.compiler.Compiler.compile() compiles your Python DSL code into a single static configuration (in YAML format) that the Kubeflow Pipelines service can process.
350
+
351
+ ```python
352
+ from katonic.pipeline.pipeline import compiler
353
+ pipeline_filename = pipeline_func.__name__ + f'{uuid.uuid1()}.pipeline.yaml'
354
+ compiler.Compiler().compile(pipeline_func, pipeline_filename)
355
+ ```
356
+ The pipeline is uploaded using the kfp.client() that contains all the pipeline details.
357
+
358
+ ```python
359
+ from katonic.pipeline.pipeline import Client
360
+
361
+ client = Client()
362
+ experiment = client.create_experiment(EXPERIMENT_NAME)
363
+ run_name = pipeline_func.__name__ + str(datetime.now().strftime("%d-%m-%Y-%H-%M-%S"))
364
+ client.upload_pipeline(pipeline_filename)
365
+ run_result = client.run_pipeline(experiment.id, run_name, pipeline_filename)
366
+ ```
367
+
368
+ You can explore the pipeline examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/pipeline).
369
+
370
+ ### Drift
371
+
372
+ An AI model life cycle will not end with the model deployment. You need to monitor the model's performance continuously in order to detect the model detoriation or model degradation. Drift component from Katonic's SDK will help you to find the Drift inside your data. It will perform certain statistical analysis upon the data in order to check if the upcoming data has any Outliers or the data is abnormal it will let you know through a Visual representaion.
373
+
374
+ ### Install Drift.
375
+ ```python
376
+ pip install katonic[drift]
377
+ ```
378
+
379
+ You can explore the drift examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/drift).
@@ -0,0 +1,300 @@
1
+ <p align="center">
2
+ <a href="https://katonic.ai/">
3
+ <img src="https://katonic.ai/assets/brand/Logo.png" width="550">
4
+ </a>
5
+ </p>
6
+ <br />
7
+
8
+ [![Docs Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://docs.katonic.ai/)
9
+ [![License](https://img.shields.io/badge/License-MIT-blue)](https://github.com/katonic-dev/katonic-sdk/blob/master/LICENSE)
10
+ [![PYPI](https://img.shields.io/pypi/v/katonic.svg)](https://pypi.python.org/pypi/katonic)
11
+
12
+ Katonic Python SDK for Complete ML Model Life Cycle.
13
+
14
+ Katonic Python SDK is a comprehensive package to perform all the Machine Learning and Data Science related operations.
15
+
16
+ For a complete list of examples and notebooks, please take a look at the [Examples](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk).
17
+
18
+ ## Minimum Requirements
19
+ * Katonic Platform 3.3 or Higher.
20
+ * Python 3.8 or Higher.
21
+
22
+ ## Download using pip for the base package.
23
+ ```sh
24
+ pip install katonic
25
+ ```
26
+
27
+ Katonic base package installation consists log packages to log your standard or custom built model in to Katonic model registry, see example below.
28
+
29
+ The topics in this page:
30
+
31
+ - [Connectors](#connectors)
32
+ - [Filemanager](#filemanager)
33
+ - Feature Engineering
34
+ - [Feature Store](#feature-store)
35
+ - [Experiment Operations](#experiment-operations)
36
+ - [Registry Operations](#registry-operations)
37
+ - [Pipeline Operations](#pipeline-operations)
38
+ - [Drift](#drift)
39
+
40
+ ### Connectors
41
+
42
+ A typical AI model life cycle starts with loading the data into your workspace and analyzing it to discover useful insights. for that you can use Katonic's SDK, there are several connectors inside it you can use to load the data and put it where ever you want to work with. Ex. Azure blob, MySql, Postgres etc.
43
+
44
+ ### Install Connectors.
45
+ ```python
46
+ pip install katonic[connectors]
47
+ ```
48
+ ### Connector example to get the data from SNOWFLAKE.
49
+ *snowflake-credentials.json*
50
+
51
+ ```json
52
+ {
53
+ "USER": "username",
54
+ "PASSWORD": "password",
55
+ "ACCOUNT": "id.uae-north.azure",
56
+ "DATABASE": "SNOWFLAKE_SAMPLE_DATA",
57
+ "TABLE_NAME": "CUSTOMER",
58
+ "SCHEMA": "TPCH_SF1",
59
+ "WAREHOUSE": "COMPUTE_WH"
60
+ }
61
+ ```
62
+ ```python
63
+ # Define all your configurations inside a JSON file.
64
+ import json
65
+
66
+ with open('snowflake-credentials.json') as f:
67
+ config = json.load(f)
68
+ ```
69
+ Initializing the SnowFlakeConnector with the provided credentials and configuration.
70
+ ```python
71
+ from katonic.connectors.python.snowflake import SnowFlakeConnector
72
+
73
+ df = SnowFlakeConnector(
74
+ user=config["USER"],
75
+ password=config["PASSWORD"],
76
+ account=config["ACCOUNT"],
77
+ database=config["DATABASE"],
78
+ table_name=config["TABLE_NAME"],
79
+ schema=config["SCHEMA"],
80
+ warehouse=config["WAREHOUSE"],
81
+ query="SELECT * FROM TPCH_SF1.CUSTOMER",
82
+ output="local",
83
+ file_name="driver_data",
84
+ )
85
+ ```
86
+ ```python
87
+ df.get_data()
88
+ ```
89
+
90
+ ```output
91
+ >>> Connection to snowflake established Successfully.
92
+ >>> File saved to your 'local' file system with name 'snowflake_TPCH_SF1_SNOWFLAKE_SAMPLE_DATA_driver_data_2022_04_20_08_46_38.csv' Successfully.
93
+ ```
94
+ You can explore the Connectors examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/connectors).
95
+
96
+ ### Filemanager
97
+
98
+ Once getting the data you can use Katonic Filemanager to Get, Store and Update or manipulate Objects within the file manager with Katonic SDK.
99
+
100
+ ### Install Filemanager.
101
+ ```python
102
+ pip install katonic[filemanager]
103
+ ```
104
+ ### Filemanager example to put/move the object from filemanager's public bucket to private bucket.
105
+
106
+ *filemanager-credentials.json*
107
+
108
+ ```json
109
+ {
110
+ "ACCESS_KEY":"TV6WFGHTR3TFBIBAO0R",
111
+ "SECRET_KEY":"BoW+p+iLAMNS4cbUNsSLVEmscITdTDMLXC8Emfz",
112
+ "PRIVATE_BUCKET":"private-storage-6583",
113
+ "PUBLIC_BUCKET":"shared-storage",
114
+ }
115
+ ```
116
+ ```python
117
+ # Define all your configurations inside a JSON file.
118
+ import json
119
+
120
+ with open('filemanager-credentials.json') as f:
121
+ config = json.load(f)
122
+ ```
123
+ Initializing the Filemanager with the provided credentials and configuration.
124
+ ```python
125
+ from katonic.filemanager.session import Filemanager
126
+
127
+ fm = Filemanager(
128
+ access_key=config["ACCESS_KEY"],
129
+ secret_key=config["SECRET_KEY"],
130
+ )
131
+
132
+ client = fm.clientV1
133
+ ```
134
+ ```python
135
+ client.fput_object(
136
+ config["BUCKET"],
137
+ "/home/data/sample-file.txt",
138
+ "/data/sample-file.txt"
139
+ )
140
+ ```
141
+ You can explore the Filemanager examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/filemanager).
142
+
143
+ ### Feature Store
144
+
145
+ Once you loaded all the necessary data that you want to work with. You'll do the preprocessing of it. Which consists of Handling the missing values, Removing the Outliers, Scaling the Data and Encoding the features etc. Once you've finished preprocessing the data. You need to ingest the data into a Feature store.
146
+
147
+ By uploading the clean data to a feature store, you can share it across the organization. So that other teams and data scientist working on the same problem can make use of it. By this way you can achieve Feature Reusability.
148
+
149
+ Training models and making predictions from the Feature store data will improve the consistency between the training data and serving data otherwise it will lead to training-serving skew.
150
+
151
+ ### Install Feature Store.
152
+ ```python
153
+ pip install katonic[fs]
154
+ ```
155
+
156
+ You can explore the feature store examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/feature-store).
157
+
158
+ ### Experiment Operations
159
+
160
+ Training Machine Learning models just with one or two lines of code, can be done by the Auto ML component inside the Katonic SDK.
161
+
162
+ Even all the metrics for Classification and Regression will get catalouged using SDK. Available Metrices are Accuracy score, F-1 score, Precison, Recall, Log loss, Mean Squared Error, Mean Absolute Error and Root Mean Squared Error.
163
+
164
+ ### Install Auto ML.
165
+ ```python
166
+ pip install katonic[ml]
167
+ ```
168
+ ### Auto ML Examples.
169
+ ```python
170
+ from katonic.ml.client import set_exp
171
+ from katonic.ml.classification import Classifier
172
+
173
+ # Creating a new experiment using set_exp function from ml client.
174
+ exp_name = "customer_churn_prediction"
175
+ set_exp(exp_name)
176
+
177
+ clf = Classifier(X_train,X_test,y_train,y_test, exp_name)
178
+
179
+ clf.GradientBoostingClassifier()
180
+ clf.DecisionTreeClassifier(max_depth=8, criterion="gini")
181
+
182
+ # Get registered models and metrics in Mlflow
183
+ df_runs = clf.search_runs(exp_id)
184
+ print("Number of runs done : ", len(df_runs))
185
+ ```
186
+
187
+ You can explore the automl examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/automl).
188
+
189
+ ### Registry Operations
190
+
191
+ Once you finished training the models with your data. Katonic's SDK will keep track of all the models and store the Model metadata and metrices inside the Experiment Registry. From there you can choose the best model and send it into Model Registy.
192
+
193
+ ### Install Log.
194
+ ```python
195
+ pip install katonic
196
+ ```
197
+ ### Logging ML Model Examples.
198
+ ```python
199
+ from katonic.log.logmodel import LogModel
200
+
201
+ from xgboost import XGBClassifier
202
+
203
+ # Creating a new experiment using set_exp function from log client.
204
+ exp_name = "diabetes_prediction"
205
+ lm = LogModel(exp_name)
206
+
207
+ clf = XGBClassifier(random_state=0)
208
+ clf.fit(X_train, y_train)
209
+
210
+ artifact_path = # define custom artifact path name (str)
211
+ model_mertics = # define custom metric in dictionary form
212
+
213
+ # Logging ML model
214
+ lm.model_logging(
215
+ model_name="xgboost",
216
+ model_type="xgboost",
217
+ model=clf,
218
+ artifact_path=artifact_path,
219
+ current_working_dir="xgboost_model.ipynb",
220
+ metrics=model_mertics
221
+ )
222
+ ```
223
+
224
+ You can explore the logs examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/log).
225
+
226
+ In Model Registy you can store the Best models according to your performance Metrices. By using the model registy you can tag the models with `staging` or `production`. The models that are with the tag `production` can be Deployed to the production and the models with `staging` tag can get a review check from the QA team and get to the further stages.
227
+
228
+ ### Pipeline Operations
229
+
230
+ No Data Scientist want to do the same thing again and again, instead of that Data Scientist want to use the previous work that he had done for the future purposes. We can do the same thing inside an AI Model Life Cycle.
231
+
232
+ We can convert all the work that we had done till now into a Scalable Pipeline. For that you can use the Pipelines component inside the Katonic SDK. If you want to perform the same operations with the different data, you just need to change the data source and run the pipeline. Every thing will get done automatically in a scalable manner.
233
+
234
+ ### Install Pipelines.
235
+ ```python
236
+ pip install katonic[pipeline]
237
+ ```
238
+ ## How to create and execute a pipeline using Katonic SDK.
239
+
240
+ * Create a pipeline function
241
+
242
+ * create a pipeline by defining task inside a pipeline function
243
+ ```python
244
+ from katonic.pipeline.pipeline import dsl, create_component_from_func
245
+
246
+ def print_something(data: str):
247
+ print(data)
248
+
249
+ @dsl.pipeline(
250
+ name='Print Something',
251
+ description='A pipeline that prints some data'
252
+ )
253
+ def pipeline():
254
+ print_something_op = create_component_from_func(func=print_something)
255
+ data = "Hello World!!"
256
+ print_something_op(data)
257
+ ```
258
+ create_component_from_func is used to convert functions to components that is stored inside print_something, data is passed inside print_something_op to print it.
259
+
260
+ Compiling And Running: Here pipeline experiment name, function is defined.
261
+ ```python
262
+ from datetime import datetime
263
+ import uuid
264
+
265
+ EXPERIMENT_NAME = "Print_Something"
266
+ pipeline_func = pipeline
267
+ ```
268
+ using the pipeline funcion and yaml filename the pipeline is compiled that generated the .yaml file.
269
+
270
+ kfp.compiler.Compiler.compile() compiles your Python DSL code into a single static configuration (in YAML format) that the Kubeflow Pipelines service can process.
271
+
272
+ ```python
273
+ from katonic.pipeline.pipeline import compiler
274
+ pipeline_filename = pipeline_func.__name__ + f'{uuid.uuid1()}.pipeline.yaml'
275
+ compiler.Compiler().compile(pipeline_func, pipeline_filename)
276
+ ```
277
+ The pipeline is uploaded using the kfp.client() that contains all the pipeline details.
278
+
279
+ ```python
280
+ from katonic.pipeline.pipeline import Client
281
+
282
+ client = Client()
283
+ experiment = client.create_experiment(EXPERIMENT_NAME)
284
+ run_name = pipeline_func.__name__ + str(datetime.now().strftime("%d-%m-%Y-%H-%M-%S"))
285
+ client.upload_pipeline(pipeline_filename)
286
+ run_result = client.run_pipeline(experiment.id, run_name, pipeline_filename)
287
+ ```
288
+
289
+ You can explore the pipeline examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/pipeline).
290
+
291
+ ### Drift
292
+
293
+ An AI model life cycle will not end with the model deployment. You need to monitor the model's performance continuously in order to detect the model detoriation or model degradation. Drift component from Katonic's SDK will help you to find the Drift inside your data. It will perform certain statistical analysis upon the data in order to check if the upcoming data has any Outliers or the data is abnormal it will let you know through a Visual representaion.
294
+
295
+ ### Install Drift.
296
+ ```python
297
+ pip install katonic[drift]
298
+ ```
299
+
300
+ You can explore the drift examples [here](https://github.com/katonic-dev/Examples/tree/master/katonic-sdk/drift).