Skip to main content

extends databricks dbutils

Project description

databricks-ddbxutils

dbutils 로 부족한 부분을 확장한 ddbxutils

Feature

  • dbutils.widgets 에 jinja2 template 적용

setup

cd <PROJECT_ROOT>
pip install poetry

venv

poetry shell

Build

poetry build

Run

in databricks w/o init_script(= Serverless)

  • Add Wheel
    • wheel upload 용 Volume 생성 후 upload
      • /Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/ddbxutils-<VERSION>-py3-none-any.whl
    • notebook 의 우측 Environment 에서 Environment version 2로 지정 후 volume 에 upload 한 wheel file 추가 후 Apply
  • Usage
    # dbutils.widgets.text('rawdate', '2025-05-24', 'Raw Date')
    # dbutils.widgets.text('next_day', '{{add_days(rawdate, "%Y-%m-%d", "", 1)}}', 'Next Day')
    import ddbxutils
    next_day = ddbxutils.widgets.get('next_day')
    # next_day: 2025-05-25
    

in databricks w/ init_script

  • Add Wheel
    • wheel upload 용 Volume 생성 후 upload
      • /Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/ddbxutils-<VERSION>-py3-none-any.whl
    • Libraries
      • /Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/ddbxutils-<VERSION>-py3-none-any.whl
  • /Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/init_script_ddbxutils.sh
    #! /bin/bash
    
    STARTUP_SCRIPT=/tmp/pyspark_startup.py
    
    cat >> ${STARTUP_SCRIPT} << EOF
    
    prefix = 'PYTHONSTARTUP_ddbxutils'
    print(f'{prefix} custom startup script loading...')
    try:
      import ddbxutils
      print(f'{prefix} Custom modules [ddbxutils] are loaded.')
    except Exception as e:
      print(f'{prefix} e={e}')
      print(f'{prefix} import ddbxutils failed')
    EOF
    
  • Spark config
    spark.executorEnv.PYTHONSTARTUP /tmp/pyspark_startup.py
    
  • Environment variables
    PYTHONSTARTUP=/tmp/pyspark_startup.py
    
  • Init scripts
    /Volumes/<CATALOG>/<DATABASE>/<VOLUME_NAME>/init_script_ddbxutils.sh
    
  • Usage
    # dbutils.widgets.text('rawdate', '2025-05-24', 'Raw Date')
    # dbutils.widgets.text('next_day', '{{add_days(rawdate, "%Y-%m-%d", "", 1)}}', 'Next Day')
    next_day = ddbxutils.widgets.get('next_day')
    # next_day: 2025-05-25
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

databricks_ddbxutils-0.2.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

databricks_ddbxutils-0.2.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file databricks_ddbxutils-0.2.0.tar.gz.

File metadata

  • Download URL: databricks_ddbxutils-0.2.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for databricks_ddbxutils-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fc0f1e64d66ccb46c2f6a1b8c586952c506ad26bcfadfdeb9283380a3ba9ad07
MD5 13b9ca75219941712c2a774439e2eab7
BLAKE2b-256 2536ea77a03c7fdab748f8a1504497756b34a77ee83a2f8b6fa8adb2da7a060b

See more details on using hashes here.

File details

Details for the file databricks_ddbxutils-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for databricks_ddbxutils-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2eb3cee58de877741f141a6232d79212fbcf5391b867a01e5b3c979fe8e2ae8
MD5 573498c0a8f0678f2d7aeee793a08cdb
BLAKE2b-256 134af60b77ed4f131f0a87ef6d7fb0a46d65a043bf40c2dd9c228ce7c95d6d65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page