Retrieve the current username for the notebook

Note

These API calls are not supported by Databricks and can change or be removed at any time.

Problem

You are running a notebook, but do not know the name of the current user.

Solution

You can use dbutils.notebook.getContext.tags to obtain the current username when running an interactive notebook.

dbutils.notebook.getContext.tags("user")
dbutils.notebook.entry_point.getDbutils().notebook().getContext().tags().apply('user')

When running a notebook as a job, you cannot use dbutils.notebook.getContext.tags directly. Instead, you should use a notebook widget, pass the username explicitly as a job parameter, and access the widget’s value from a cell.

dbutils.widgets.get("job_user")