Find cell no. of script func. called: Jupyter Notebook

Is there an API for the some_IPython_history_class_api.get_current_cell()?

Finding the Cell Number from Which a Function is Called in a Jupyter Notebook

If you have a Python script with a one function called my_func() inside, and you import this script into a Jupyter Notebook to run my_func() in the cells, how can you find which cell number it is called from?

An API exists to do this, which can be used in the definition of my_func() as follows:

# my_script.py

def my_func():
    # find which cell this is called from
    cell_number_called_from = some_IPython_history_class_api.get_current_cell()

    # log the cell number and do the rest of my things

The API in question is some_IPython_history_class_api.get_current_cell().

There is no API for some_IPython_history_class_api.get_current_cell(). This is just a hypothetical example used to illustrate how you could find the cell number from which a function is called in a Jupyter Notebook.