How to identify if the parent command was jupyter lab or jupyter notebook

Is there a way for the server extension to know if the program used to launch it is jupyter notebook or jupyter lab? Use case:

At runtime I want to decide if I should import from jupyter_server or notebook library.

If you’ve defined a load_jupyter_server_extension(serverapp): method/function to extend the server, you can inspect the class of the first argument argument, which is the underlying server application.

For example, something like:

def load_jupyter_sever_extensions(serverapp):
    # Import libraries based on serverapp 
    if isinstance(serverapp, notebook.notebookapp.NotebookApp):
        # Import notebook libraries
    elif isinstance(serverapp, jupyter_server.serverapp.ServerApp):
        # import jupyter_server libraries