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.3.0.tar.gz (8.8 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.3.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: databricks_ddbxutils-0.3.0.tar.gz
  • Upload date:
  • Size: 8.8 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.3.0.tar.gz
Algorithm Hash digest
SHA256 492e9b93d6eece82da98a6ada7fe89491f8caa5d5ff8212fecc576376852efc0
MD5 42a12a7478f8471b5e01c2427476d61a
BLAKE2b-256 8432fe5b34b3fa56559c5734ad2c8b2c2f430c4865baf8a4f7c668beca0aa23d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databricks_ddbxutils-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 620c3a8bab6b98c7bcc5b2a013166b0e710441405c656576b41ca46cf6e1d637
MD5 91cf604dba4d6f0a86ad7618ef92d4ec
BLAKE2b-256 0e37e2e28fe69700e3725d71eef4a67b2d520f6767ed3981cfc3e1c9616e78d9

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