This code works in Scala only, there is no implementation for it in the Python runtime. And the information I got from a Databricks employee via email, those are internal APIs and they may change without notice.
@hanspetter you can get the info via the command context:
dbutils.notebook.getContext.currentRunId
Besides of that, the following methods (vals) are available in the context:
jobGroup: Option[String] - unique command identifier that is injected by ...