databricks-ddbxutils 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

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.
@@ -0,0 +1,104 @@
1
+ Metadata-Version: 2.1
2
+ Name: databricks-ddbxutils
3
+ Version: 0.2.0
4
+ Summary: extends databricks dbutils
5
+ Author: Haneul Kim
6
+ Author-email: haneul.kim@data-dynamics.io
7
+ Requires-Python: >=3.11,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Dist: databricks-sdk (>=0.57.0,<0.58.0)
12
+ Requires-Dist: dotenv (>=0.9.9,<0.10.0)
13
+ Requires-Dist: jinja2 (>=3.1.6,<4.0.0)
14
+ Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
15
+ Description-Content-Type: text/markdown
16
+
17
+ # databricks-ddbxutils
18
+
19
+ dbutils 로 부족한 부분을 확장한 ddbxutils
20
+
21
+ ## Feature
22
+
23
+ * [x] `dbutils.widgets` 에 jinja2 template 적용
24
+
25
+ ## setup
26
+
27
+ ```shell
28
+ cd <PROJECT_ROOT>
29
+ pip install poetry
30
+ ```
31
+
32
+ ## venv
33
+
34
+ ```shell
35
+ poetry shell
36
+ ```
37
+
38
+ ## Build
39
+
40
+ ```shell
41
+ poetry build
42
+ ```
43
+
44
+ ## Run
45
+
46
+ ### in databricks w/o init_script(= Serverless)
47
+
48
+ * Add Wheel
49
+ * wheel upload 용 Volume 생성 후 upload
50
+ * `/Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/ddbxutils-<VERSION>-py3-none-any.whl`
51
+ * notebook 의 우측 Environment 에서 Environment version 2로 지정 후 volume 에 upload 한 wheel file 추가 후 Apply
52
+ * Usage
53
+ ```python
54
+ # dbutils.widgets.text('rawdate', '2025-05-24', 'Raw Date')
55
+ # dbutils.widgets.text('next_day', '{{add_days(rawdate, "%Y-%m-%d", "", 1)}}', 'Next Day')
56
+ import ddbxutils
57
+ next_day = ddbxutils.widgets.get('next_day')
58
+ # next_day: 2025-05-25
59
+ ```
60
+
61
+ ### in databricks w/ init_script
62
+
63
+ * Add Wheel
64
+ * wheel upload 용 Volume 생성 후 upload
65
+ * `/Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/ddbxutils-<VERSION>-py3-none-any.whl`
66
+ * Libraries
67
+ * `/Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/ddbxutils-<VERSION>-py3-none-any.whl`
68
+ * `/Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/init_script_ddbxutils.sh`
69
+ ```shell
70
+ #! /bin/bash
71
+
72
+ STARTUP_SCRIPT=/tmp/pyspark_startup.py
73
+
74
+ cat >> ${STARTUP_SCRIPT} << EOF
75
+
76
+ prefix = 'PYTHONSTARTUP_ddbxutils'
77
+ print(f'{prefix} custom startup script loading...')
78
+ try:
79
+ import ddbxutils
80
+ print(f'{prefix} Custom modules [ddbxutils] are loaded.')
81
+ except Exception as e:
82
+ print(f'{prefix} e={e}')
83
+ print(f'{prefix} import ddbxutils failed')
84
+ EOF
85
+ ```
86
+ * Spark config
87
+ ```text
88
+ spark.executorEnv.PYTHONSTARTUP /tmp/pyspark_startup.py
89
+ ```
90
+ * Environment variables
91
+ ```shell
92
+ PYTHONSTARTUP=/tmp/pyspark_startup.py
93
+ ```
94
+ * Init scripts
95
+ ```text
96
+ /Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/init_script_ddbxutils.sh
97
+ ```
98
+ * Usage
99
+ ```python
100
+ # dbutils.widgets.text('rawdate', '2025-05-24', 'Raw Date')
101
+ # dbutils.widgets.text('next_day', '{{add_days(rawdate, "%Y-%m-%d", "", 1)}}', 'Next Day')
102
+ next_day = ddbxutils.widgets.get('next_day')
103
+ # next_day: 2025-05-25
104
+ ```
@@ -0,0 +1,9 @@
1
+ ddbxutils/__init__.py,sha256=ElK7lAZwcQh50qAVQ16t9Cfk0caZAYLJtKkDJDkLljk,158
2
+ ddbxutils/functions.py,sha256=eb1cM5tpJKB1MuzJ8ncTpGxTjZA70kDj_gJFQC6y7zg,1567
3
+ ddbxutils/main.py,sha256=9pjd5VXAQOj-_lZsTojv-A4LUiZ-SLuK5oMgNwO4Fzc,488
4
+ ddbxutils/widgets/__init__.py,sha256=aeFsmeixYUPaFFw4DqgvuQreBlkNwmBM4v2bCZUB2zU,1364
5
+ ddbxutils/widgets/core.py,sha256=uBhbq5KKSyFT5CLRPsTw4zzeWYxGuJvImEQgh_iiEqk,989
6
+ databricks_ddbxutils-0.2.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
+ databricks_ddbxutils-0.2.0.dist-info/METADATA,sha256=QQsJYSPRCg-fUKeCF05fCFLuozonYeTvX0KYyc0-XwM,2724
8
+ databricks_ddbxutils-0.2.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
+ databricks_ddbxutils-0.2.0.dist-info/RECORD,,
ddbxutils/__init__.py CHANGED
@@ -1,6 +1,4 @@
1
- from databricks.sdk import WorkspaceClient
2
-
3
1
  from . import widgets
4
2
 
5
- w = WorkspaceClient()
6
- widgets.init(w.dbutils)
3
+ # lazy evaluation 위해 () 로 감싸서 generator 를 return 하도록 변경
4
+ generator = (widgets.get_instance() for x in range(1))
ddbxutils/main.py CHANGED
@@ -2,13 +2,13 @@
2
2
  import ddbxutils
3
3
 
4
4
  # 'next_day' 위젯의 기본값 가져오기
5
- initial_value = ddbxutils.widgets.get("next_day")
6
- print(f"초기 'next_day' 값: {initial_value}")
5
+ initial_value = ddbxutils.widgets.get('next_day')
6
+ print(f'초기 next_day 값: {initial_value}')
7
7
 
8
8
  # 변경된 값 다시 가져오기
9
- updated_value = ddbxutils.widgets.get("next_day")
10
- print(f"업데이트된 'next_day' 값: {updated_value}")
9
+ updated_value = ddbxutils.widgets.get('next_day')
10
+ print(f'업데이트된 next_day 값: {updated_value}')
11
11
 
12
12
  # 존재하지 않는 위젯 가져오기
13
- other_value = ddbxutils.widgets.get("another_widget")
14
- print(f"'another_widget' 값: {other_value}")
13
+ other_value = ddbxutils.widgets.get('another_widget')
14
+ print(f'another_widget 값: {other_value}')
@@ -3,16 +3,17 @@ from .core import WidgetImpl
3
3
  _widget_impl_instance: WidgetImpl = None
4
4
 
5
5
 
6
- def init(dbutils):
6
+ def get_instance():
7
7
  """
8
8
  widgets 모듈을 초기화합니다.
9
9
  이 함수는 반드시 dbutils 객체와 함께 한 번 호출되어야 합니다.
10
10
 
11
- :param dbutils: dbutils
12
11
  :return: None
13
12
  """
14
13
  global _widget_impl_instance
15
- _widget_impl_instance = WidgetImpl(dbutils)
14
+ if _widget_impl_instance is None:
15
+ _widget_impl_instance = WidgetImpl()
16
+ return _widget_impl_instance
16
17
 
17
18
 
18
19
  def get(widget_name: str):
@@ -23,20 +24,22 @@ def get(widget_name: str):
23
24
  :param widget_name: widget key
24
25
  :return: resolved widget value
25
26
  """
26
- if _widget_impl_instance is None:
27
- raise RuntimeError('ddbxutils.widgets가 초기화되지 않았습니다. `ddbxutils.widgets.init(dbutils)`를 먼저 호출하세요.')
28
- return _widget_impl_instance.get(widget_name)
27
+ widget_impl = get_instance()
28
+ # if _widget_impl_instance is None:
29
+ # raise RuntimeError('ddbxutils.widgets가 초기화되지 않았습니다. `ddbxutils.widgets.init(dbutils)`를 먼저 호출하세요.')
30
+ return widget_impl.get(widget_name)
29
31
 
30
32
 
31
- def refresh(dbutils):
33
+ def refresh():
32
34
  """
33
35
  위젯 값을 새로 고칩니다.
34
36
 
35
37
  :param dbutils: dbutils
36
38
  :return: None
37
39
  """
38
- if _widget_impl_instance is None:
39
- raise RuntimeError('ddbxutils.widgets가 초기화되지 않았습니다. `ddbxutils.widgets.init(dbutils)`를 먼저 호출하세요.')
40
- if dbutils is None:
41
- raise RuntimeError('dbutils is required.')
42
- _widget_impl_instance.refresh(dbutils)
40
+ widget_impl = get_instance()
41
+ # if _widget_impl_instance is None:
42
+ # raise RuntimeError('ddbxutils.widgets가 초기화되지 않았습니다. `ddbxutils.widgets.init(dbutils)`를 먼저 호출하세요.')
43
+ # if dbutils is None:
44
+ # raise RuntimeError('dbutils is required.')
45
+ widget_impl.refresh()
ddbxutils/widgets/core.py CHANGED
@@ -1,6 +1,8 @@
1
- from ddbxutils.functions import add_days, add_datetime
1
+ from databricks.sdk import WorkspaceClient
2
2
  from jinja2 import Environment
3
3
 
4
+ from ddbxutils.functions import add_days, add_datetime
5
+
4
6
  environment = Environment()
5
7
  environment.globals['add_days'] = add_days
6
8
  environment.globals['add_datetime'] = add_datetime
@@ -10,14 +12,15 @@ class WidgetImpl:
10
12
  dbutils = None
11
13
  rendered_widget_values = None
12
14
 
13
- def __init__(self, dbutils):
14
- self.refresh(dbutils)
15
+ def __init__(self):
16
+ self.refresh()
15
17
 
16
- def refresh(self, dbutils):
18
+ def refresh(self):
17
19
  """
18
20
  위젯의 값을 설정하거나 추가합니다.
19
21
  """
20
- self.dbutils = dbutils
22
+ if self.dbutils is None:
23
+ self.dbutils = WorkspaceClient().dbutils
21
24
  widget_values = self.dbutils.widgets.getAll()
22
25
  self.rendered_widget_values = {key: environment.from_string(value).render(widget_values) for key, value in widget_values.items()}
23
26
 
@@ -1,56 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: databricks-ddbxutils
3
- Version: 0.1.0
4
- Summary: extends databricks dbutils
5
- Author: Haneul Kim
6
- Author-email: haneul.kim@data-dynamics.io
7
- Requires-Python: >=3.11,<4.0
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.11
10
- Classifier: Programming Language :: Python :: 3.12
11
- Requires-Dist: databricks-sdk (>=0.57.0,<0.58.0)
12
- Requires-Dist: dotenv (>=0.9.9,<0.10.0)
13
- Requires-Dist: jinja2 (>=3.1.6,<4.0.0)
14
- Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
15
- Description-Content-Type: text/markdown
16
-
17
- # databricks-ddbxutils
18
-
19
- dbutils 로 부족한 부분을 확장한 ddbxutils
20
-
21
- ## Feature
22
-
23
- * [x] `dbutils.widgets` 에 jinja2 template 적용
24
-
25
- ## setup
26
-
27
- ```shell
28
- cd <PROJECT_ROOT>
29
- pip install poetry
30
- ```
31
-
32
- ## venv
33
-
34
- ```shell
35
- poetry shell
36
- ```
37
-
38
- ## Build
39
-
40
- ```shell
41
- poetry build
42
- ```
43
-
44
- ## Run
45
-
46
- ### in databricks w/o init_script
47
-
48
- * Add Wheel
49
- * wheel upload 용 Volume 생성 후 upload
50
- * `/Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/ddbxutils-<VERSION>-py3-none-any.whl`
51
- * notebook 의 우측 Environment 에서 Environment version 2로 지정 후 volume 에 upload 한 wheel file 추가 후 Apply
52
-
53
- ### in databricks w/ init_script
54
-
55
- [//]: # (TODO)
56
-
@@ -1,9 +0,0 @@
1
- ddbxutils/__init__.py,sha256=PKtRu9A6hvfLvcB8DLqtt1IN6ozJqb9rUA3mueiaSpc,113
2
- ddbxutils/functions.py,sha256=eb1cM5tpJKB1MuzJ8ncTpGxTjZA70kDj_gJFQC6y7zg,1567
3
- ddbxutils/main.py,sha256=Hfo0I4lyOZKSUHJplqQnNFNrElb54XHGAZFTJdxQ9LE,494
4
- ddbxutils/widgets/__init__.py,sha256=yZQLYkRtXTBISZlbIJlBx5e9xpgikCzSvr8B6KWj5hw,1279
5
- ddbxutils/widgets/core.py,sha256=b2SciKS2TEUQS7HjOK8FAvjR228hv8-k0P5CxnnZpHA,915
6
- databricks_ddbxutils-0.1.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
- databricks_ddbxutils-0.1.0.dist-info/METADATA,sha256=FxItGiTlCDR9QXPHZisMdl-P7L0V_5stGom3XggUoeU,1208
8
- databricks_ddbxutils-0.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
- databricks_ddbxutils-0.1.0.dist-info/RECORD,,