zipher-sdk 0.2.0__tar.gz → 0.4.1__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 (33) hide show
  1. zipher_sdk-0.4.1/PKG-INFO +212 -0
  2. zipher_sdk-0.4.1/README.md +189 -0
  3. {zipher-sdk-0.2.0 → zipher_sdk-0.4.1}/setup.py +9 -4
  4. zipher_sdk-0.4.1/tests/test_acl/__init__.py +0 -0
  5. zipher_sdk-0.4.1/tests/test_acl/sample_job.py +15 -0
  6. zipher_sdk-0.4.1/tests/test_acl/test_acl.py +353 -0
  7. zipher_sdk-0.4.1/zipher/__init__.py +2 -0
  8. zipher_sdk-0.4.1/zipher/acl/__init__.py +0 -0
  9. zipher_sdk-0.4.1/zipher/acl/models.py +49 -0
  10. zipher_sdk-0.4.1/zipher/acl/zipher_installer.py +376 -0
  11. zipher_sdk-0.4.1/zipher/cli.py +153 -0
  12. {zipher-sdk-0.2.0 → zipher_sdk-0.4.1}/zipher/client.py +30 -12
  13. zipher_sdk-0.4.1/zipher/exceptions.py +16 -0
  14. zipher_sdk-0.4.1/zipher/models.py +33 -0
  15. zipher_sdk-0.4.1/zipher/utils.py +67 -0
  16. zipher_sdk-0.4.1/zipher_sdk.egg-info/PKG-INFO +212 -0
  17. {zipher-sdk-0.2.0 → zipher_sdk-0.4.1}/zipher_sdk.egg-info/SOURCES.txt +9 -1
  18. zipher_sdk-0.4.1/zipher_sdk.egg-info/entry_points.txt +2 -0
  19. zipher_sdk-0.4.1/zipher_sdk.egg-info/requires.txt +3 -0
  20. zipher-sdk-0.2.0/PKG-INFO +0 -75
  21. zipher-sdk-0.2.0/README.md +0 -58
  22. zipher-sdk-0.2.0/zipher/__init__.py +0 -1
  23. zipher-sdk-0.2.0/zipher/conf.py +0 -6
  24. zipher-sdk-0.2.0/zipher/exceptions.py +0 -4
  25. zipher-sdk-0.2.0/zipher/models.py +0 -8
  26. zipher-sdk-0.2.0/zipher_sdk.egg-info/PKG-INFO +0 -75
  27. zipher-sdk-0.2.0/zipher_sdk.egg-info/requires.txt +0 -3
  28. {zipher-sdk-0.2.0 → zipher_sdk-0.4.1}/LICENSE +0 -0
  29. {zipher-sdk-0.2.0 → zipher_sdk-0.4.1}/setup.cfg +0 -0
  30. {zipher-sdk-0.2.0 → zipher_sdk-0.4.1}/tests/__init__.py +0 -0
  31. {zipher-sdk-0.2.0 → zipher_sdk-0.4.1}/tests/test_client.py +0 -0
  32. {zipher-sdk-0.2.0 → zipher_sdk-0.4.1}/zipher_sdk.egg-info/dependency_links.txt +0 -0
  33. {zipher-sdk-0.2.0 → zipher_sdk-0.4.1}/zipher_sdk.egg-info/top_level.txt +0 -0
@@ -0,0 +1,212 @@
1
+ Metadata-Version: 2.4
2
+ Name: zipher-sdk
3
+ Version: 0.4.1
4
+ Summary: Python SDK for programmatic access to the Zipher API
5
+ Author: Zipher Inc.
6
+ Author-email: yoav@zipher.cloud
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: pydantic==2.11.3
13
+ Requires-Dist: requests==2.32.3
14
+ Requires-Dist: databricks-sdk==0.52.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: license-file
21
+ Dynamic: requires-dist
22
+ Dynamic: summary
23
+
24
+
25
+ # Zipher SDK
26
+
27
+ The Zipher SDK is a Python library for interacting with Zipher's APIs.
28
+
29
+ - [Package Installation](#package-installation)
30
+ - [Granting access to Zipher](#providing-zipher-with-access-to-databricks-workspace)
31
+ - [Usage](#sdk-usage)
32
+
33
+ ## Package Installation
34
+
35
+ You can install the Zipher SDK using pip:
36
+
37
+ ```bash
38
+ pip install zipher-sdk
39
+ ```
40
+
41
+ ## Providing Zipher with access to Databricks workspace
42
+
43
+ After installing `zipher-sdk` package a cli tool to automatically create all necessary resources for Zipher is available.
44
+
45
+ ### Setting up credentials
46
+
47
+ You need to provide credentials that will be used to create all necessary resources and permissions for Zipher.
48
+
49
+ Here are ways to set up credentials:
50
+ * `.databrickscfg` config (cli tool supports profile choice as an argument)
51
+ * `ZIPHER_DATABRICKS_HOST` and `ZIPHER_DATABRICKS_TOKEN` or `ZIPHER_DATABRICKS_CLIENT_ID`, `ZIPHER_DATABRICKS_CLIENT_SECRET` environment variables
52
+ * providing credentials as arguments to cli tool
53
+
54
+ ### Cli tool usage examples
55
+
56
+ #### Providing Zipher with access to a list of jobs
57
+ ```
58
+ zipher setup --jobs-list 12345678,87654321,12344321,21436587
59
+ ```
60
+
61
+ #### Providing Zipher with access to n jobs from the workspace
62
+ ```
63
+ zipher setup --max-jobs 50
64
+ ```
65
+
66
+ #### Providing Zipher with readonly access to a list of jobs
67
+ ```
68
+ zipher setup --readonly --jobs-list 12345678,87654321,12344321,21436587
69
+ ```
70
+
71
+ ### Full cli tool specification
72
+ ```
73
+ usage: zipher setup [-h] [--workspace-host WORKSPACE_HOST] [--access-token ACCESS_TOKEN] [--client-id CLIENT_ID] [--client-secret CLIENT_SECRET] [--profile PROFILE] [--verbose] [--jobs-list JOBS_LIST] [--max-jobs MAX_JOBS]
74
+ [--max-runs MAX_RUNS] [--days-back DAYS_BACK] [--readonly] [--pat] [--skip-approval]
75
+
76
+ options:
77
+ -h, --help show this help message and exit
78
+ --workspace-host WORKSPACE_HOST
79
+ Databricks workspace host URL.
80
+ --access-token ACCESS_TOKEN
81
+ Databricks workspace access token.
82
+ --client-id CLIENT_ID
83
+ Databricks workspace OAuth client id.
84
+ --client-secret CLIENT_SECRET
85
+ Databricks workspace OAuth client secret.
86
+ --profile PROFILE Profile name from .databrickscfg.
87
+ --verbose Print full error message on fail.
88
+ --jobs-list JOBS_LIST
89
+ Comma-separated list of jobs ids to provide access to.
90
+ --max-jobs MAX_JOBS Maximum number of jobs to consider when iterating over jobs to grant permissions (default: 2000).
91
+ --max-runs MAX_RUNS Maximum number of runs to consider when iterating over runs to grant permissions to relative jobs (default: 2000).
92
+ --days-back DAYS_BACK
93
+ How many days back to fetch relevant job runs for permission updates (default: 7).
94
+ --readonly Provide Zipher with only CAN_VIEW permissions on listed jobs. When not provided will default to CAN_MANAGE permissions.
95
+ --pat Generate Personal Access Token for Zipher instead of default OAuth client creds.
96
+ --skip-approval Skip user input approval.
97
+
98
+ ```
99
+
100
+
101
+ ## SDK Usage
102
+
103
+ Here are some basic examples of how you can use the Zipher SDK to optimize your databricks clusters using Zipher's ML-powered optimization engine:
104
+
105
+ ### Update Existing Configuration
106
+
107
+ You can update an existing configuration by initializing a zipher Client and sending a JSON payload to the `update_existing_conf` function. Here's how you can do it:
108
+
109
+ ```python
110
+ from zipher import Client
111
+
112
+ client = Client(customer_id="my_customer_id") # assuming the zipher API key is stored in ZIPHER_API_KEY environment variable
113
+
114
+ # Your existing cluster config:
115
+ config_payload = {
116
+ "new_cluster": {
117
+ "autoscale": {
118
+ "min_workers": 1,
119
+ "max_workers": 30
120
+ },
121
+ "cluster_name": "my-cluster",
122
+ "spark_version": "10.4.x-scala2.12",
123
+ "spark_conf": {
124
+ "spark.driver.maxResultSize": "4g"
125
+ },
126
+ "aws_attributes": {
127
+ "first_on_demand": 0,
128
+ "availability": "SPOT",
129
+ "zone_id": "auto",
130
+ "spot_bid_price_percent": 100,
131
+ "ebs_volume_count": 0
132
+ },
133
+ "node_type_id": "rd-fleet.2xlarge",
134
+ "driver_node_type_id": "rd-fleet.xlarge",
135
+ "spark_env_vars": {},
136
+ "enable_elastic_disk": "false"
137
+ }
138
+ }
139
+
140
+ # Update configuration
141
+ optimized_cluster = client.update_existing_conf(job_id="my-job-id", existing_conf=config_payload)
142
+
143
+ # Continue with sending the optimized configuration to Databricks via the Databricks python SDK, Airflow operator, etc.
144
+
145
+ ```
146
+
147
+ ### Update Existing Multiple Tasks Configuration
148
+
149
+ You can update multiple databricks tasks by initializing a zipher Client and sending a JSON representing a list of dbx SubmitTask objects to
150
+ the `get_optimized_tasks` function.
151
+
152
+ ```python
153
+ from zipher import Client
154
+
155
+ client = Client(customer_id="my_customer_id") # assuming the zipher API key is stored in ZIPHER_API_KEY environment variable
156
+
157
+ tasks_to_optimize = [
158
+ {
159
+ "task_key": "task_1",
160
+ "description": "Test notebook task",
161
+ "notebook_task": {
162
+ "notebook_path": "/path/to/your/notebook",
163
+ "base_parameters": {
164
+ "param1": "value1"
165
+ }
166
+ },
167
+ "new_cluster": {
168
+ "spark_version": "14.3.x-scala2.12",
169
+ "node_type_id": "m6id.large",
170
+ "driver_node_type_id": "m6id.large",
171
+ "num_workers": 2,
172
+ "aws_attributes": {
173
+ "first_on_demand": 0,
174
+ "availability": "SPOT",
175
+ "zone_id": "auto",
176
+ "spot_bid_price_percent": 100,
177
+ "ebs_volume_count": 0
178
+ },
179
+ "spark_conf": {
180
+ "spark.driver.maxResultSize": "4g"
181
+ }
182
+ }
183
+ },
184
+ {
185
+ "task_key": "task_2",
186
+ "description": "Test Python task",
187
+ "spark_python_task": {
188
+ "python_file": "/path/to/your/python_file.py",
189
+ },
190
+ "new_cluster": {
191
+ "spark_version": "14.3.x-scala2.12",
192
+ "node_type_id": "m6id.large",
193
+ "driver_node_type_id": "m6id.large",
194
+ "num_workers": 2,
195
+ "spark_conf": {
196
+ "spark.driver.maxResultSize": "4g"
197
+ }
198
+ },
199
+ "timeout_seconds": 3600,
200
+ "depends_on": [
201
+ {
202
+ "task_key": "task_1"
203
+ }
204
+ ]
205
+ }
206
+ ]
207
+
208
+ # Update tasks
209
+ optimized_tasks = client.get_optimized_tasks(job_id="my-job-id", tasks=tasks_to_optimize)
210
+
211
+ # Continue with sending the optimized tasks to Databricks via the Databricks python SDK, Airflow operator, etc.
212
+ ```
@@ -0,0 +1,189 @@
1
+
2
+ # Zipher SDK
3
+
4
+ The Zipher SDK is a Python library for interacting with Zipher's APIs.
5
+
6
+ - [Package Installation](#package-installation)
7
+ - [Granting access to Zipher](#providing-zipher-with-access-to-databricks-workspace)
8
+ - [Usage](#sdk-usage)
9
+
10
+ ## Package Installation
11
+
12
+ You can install the Zipher SDK using pip:
13
+
14
+ ```bash
15
+ pip install zipher-sdk
16
+ ```
17
+
18
+ ## Providing Zipher with access to Databricks workspace
19
+
20
+ After installing `zipher-sdk` package a cli tool to automatically create all necessary resources for Zipher is available.
21
+
22
+ ### Setting up credentials
23
+
24
+ You need to provide credentials that will be used to create all necessary resources and permissions for Zipher.
25
+
26
+ Here are ways to set up credentials:
27
+ * `.databrickscfg` config (cli tool supports profile choice as an argument)
28
+ * `ZIPHER_DATABRICKS_HOST` and `ZIPHER_DATABRICKS_TOKEN` or `ZIPHER_DATABRICKS_CLIENT_ID`, `ZIPHER_DATABRICKS_CLIENT_SECRET` environment variables
29
+ * providing credentials as arguments to cli tool
30
+
31
+ ### Cli tool usage examples
32
+
33
+ #### Providing Zipher with access to a list of jobs
34
+ ```
35
+ zipher setup --jobs-list 12345678,87654321,12344321,21436587
36
+ ```
37
+
38
+ #### Providing Zipher with access to n jobs from the workspace
39
+ ```
40
+ zipher setup --max-jobs 50
41
+ ```
42
+
43
+ #### Providing Zipher with readonly access to a list of jobs
44
+ ```
45
+ zipher setup --readonly --jobs-list 12345678,87654321,12344321,21436587
46
+ ```
47
+
48
+ ### Full cli tool specification
49
+ ```
50
+ usage: zipher setup [-h] [--workspace-host WORKSPACE_HOST] [--access-token ACCESS_TOKEN] [--client-id CLIENT_ID] [--client-secret CLIENT_SECRET] [--profile PROFILE] [--verbose] [--jobs-list JOBS_LIST] [--max-jobs MAX_JOBS]
51
+ [--max-runs MAX_RUNS] [--days-back DAYS_BACK] [--readonly] [--pat] [--skip-approval]
52
+
53
+ options:
54
+ -h, --help show this help message and exit
55
+ --workspace-host WORKSPACE_HOST
56
+ Databricks workspace host URL.
57
+ --access-token ACCESS_TOKEN
58
+ Databricks workspace access token.
59
+ --client-id CLIENT_ID
60
+ Databricks workspace OAuth client id.
61
+ --client-secret CLIENT_SECRET
62
+ Databricks workspace OAuth client secret.
63
+ --profile PROFILE Profile name from .databrickscfg.
64
+ --verbose Print full error message on fail.
65
+ --jobs-list JOBS_LIST
66
+ Comma-separated list of jobs ids to provide access to.
67
+ --max-jobs MAX_JOBS Maximum number of jobs to consider when iterating over jobs to grant permissions (default: 2000).
68
+ --max-runs MAX_RUNS Maximum number of runs to consider when iterating over runs to grant permissions to relative jobs (default: 2000).
69
+ --days-back DAYS_BACK
70
+ How many days back to fetch relevant job runs for permission updates (default: 7).
71
+ --readonly Provide Zipher with only CAN_VIEW permissions on listed jobs. When not provided will default to CAN_MANAGE permissions.
72
+ --pat Generate Personal Access Token for Zipher instead of default OAuth client creds.
73
+ --skip-approval Skip user input approval.
74
+
75
+ ```
76
+
77
+
78
+ ## SDK Usage
79
+
80
+ Here are some basic examples of how you can use the Zipher SDK to optimize your databricks clusters using Zipher's ML-powered optimization engine:
81
+
82
+ ### Update Existing Configuration
83
+
84
+ You can update an existing configuration by initializing a zipher Client and sending a JSON payload to the `update_existing_conf` function. Here's how you can do it:
85
+
86
+ ```python
87
+ from zipher import Client
88
+
89
+ client = Client(customer_id="my_customer_id") # assuming the zipher API key is stored in ZIPHER_API_KEY environment variable
90
+
91
+ # Your existing cluster config:
92
+ config_payload = {
93
+ "new_cluster": {
94
+ "autoscale": {
95
+ "min_workers": 1,
96
+ "max_workers": 30
97
+ },
98
+ "cluster_name": "my-cluster",
99
+ "spark_version": "10.4.x-scala2.12",
100
+ "spark_conf": {
101
+ "spark.driver.maxResultSize": "4g"
102
+ },
103
+ "aws_attributes": {
104
+ "first_on_demand": 0,
105
+ "availability": "SPOT",
106
+ "zone_id": "auto",
107
+ "spot_bid_price_percent": 100,
108
+ "ebs_volume_count": 0
109
+ },
110
+ "node_type_id": "rd-fleet.2xlarge",
111
+ "driver_node_type_id": "rd-fleet.xlarge",
112
+ "spark_env_vars": {},
113
+ "enable_elastic_disk": "false"
114
+ }
115
+ }
116
+
117
+ # Update configuration
118
+ optimized_cluster = client.update_existing_conf(job_id="my-job-id", existing_conf=config_payload)
119
+
120
+ # Continue with sending the optimized configuration to Databricks via the Databricks python SDK, Airflow operator, etc.
121
+
122
+ ```
123
+
124
+ ### Update Existing Multiple Tasks Configuration
125
+
126
+ You can update multiple databricks tasks by initializing a zipher Client and sending a JSON representing a list of dbx SubmitTask objects to
127
+ the `get_optimized_tasks` function.
128
+
129
+ ```python
130
+ from zipher import Client
131
+
132
+ client = Client(customer_id="my_customer_id") # assuming the zipher API key is stored in ZIPHER_API_KEY environment variable
133
+
134
+ tasks_to_optimize = [
135
+ {
136
+ "task_key": "task_1",
137
+ "description": "Test notebook task",
138
+ "notebook_task": {
139
+ "notebook_path": "/path/to/your/notebook",
140
+ "base_parameters": {
141
+ "param1": "value1"
142
+ }
143
+ },
144
+ "new_cluster": {
145
+ "spark_version": "14.3.x-scala2.12",
146
+ "node_type_id": "m6id.large",
147
+ "driver_node_type_id": "m6id.large",
148
+ "num_workers": 2,
149
+ "aws_attributes": {
150
+ "first_on_demand": 0,
151
+ "availability": "SPOT",
152
+ "zone_id": "auto",
153
+ "spot_bid_price_percent": 100,
154
+ "ebs_volume_count": 0
155
+ },
156
+ "spark_conf": {
157
+ "spark.driver.maxResultSize": "4g"
158
+ }
159
+ }
160
+ },
161
+ {
162
+ "task_key": "task_2",
163
+ "description": "Test Python task",
164
+ "spark_python_task": {
165
+ "python_file": "/path/to/your/python_file.py",
166
+ },
167
+ "new_cluster": {
168
+ "spark_version": "14.3.x-scala2.12",
169
+ "node_type_id": "m6id.large",
170
+ "driver_node_type_id": "m6id.large",
171
+ "num_workers": 2,
172
+ "spark_conf": {
173
+ "spark.driver.maxResultSize": "4g"
174
+ }
175
+ },
176
+ "timeout_seconds": 3600,
177
+ "depends_on": [
178
+ {
179
+ "task_key": "task_1"
180
+ }
181
+ ]
182
+ }
183
+ ]
184
+
185
+ # Update tasks
186
+ optimized_tasks = client.get_optimized_tasks(job_id="my-job-id", tasks=tasks_to_optimize)
187
+
188
+ # Continue with sending the optimized tasks to Databricks via the Databricks python SDK, Airflow operator, etc.
189
+ ```
@@ -8,7 +8,7 @@ with open('README.md', encoding='utf-8') as f:
8
8
 
9
9
  setup(
10
10
  name='zipher-sdk',
11
- version='0.2.0',
11
+ version='0.4.1',
12
12
  description='Python SDK for programmatic access to the Zipher API',
13
13
  long_description=long_description,
14
14
  long_description_content_type='text/markdown',
@@ -16,10 +16,15 @@ setup(
16
16
  author_email='yoav@zipher.cloud',
17
17
  packages=find_packages(),
18
18
  install_requires=[
19
- "pydantic==2.1.1",
20
- "requests==2.31.0",
21
- "databricks-sdk==0.28.0"
19
+ "pydantic==2.11.3",
20
+ "requests==2.32.3",
21
+ "databricks-sdk==0.52.0"
22
22
  ],
23
+ entry_points={
24
+ "console_scripts": [
25
+ "zipher=zipher.cli:main",
26
+ ]
27
+ },
23
28
  classifiers=[
24
29
  'Programming Language :: Python :: 3',
25
30
  'License :: OSI Approved :: MIT License',
File without changes
@@ -0,0 +1,15 @@
1
+ import os
2
+ from time import sleep
3
+
4
+ print("<<<<<<<< >>>>>>>>> HELLO WORLD <<<<<<<< >>>>>>>>>")
5
+ sleep_time = 20
6
+
7
+ sample_secret_env_var = os.getenv('ZIPHER_API_KEY')
8
+ if sample_secret_env_var and sample_secret_env_var == 'test_key':
9
+ print(f"Successfully retrieved secret from environment variable: {sample_secret_env_var}")
10
+ sleep_time = 90
11
+
12
+
13
+ print(f"About to sleep for {sleep_time} seconds")
14
+ sleep(sleep_time)
15
+ print("<<<<<<<< >>>>>>>>> GOODBYE WORLD <<<<<<<< >>>>>>>>>")