Is there a way to get current user through python code?

Hi! I was wondering if there’s a way to get the current user from code with someting like
import tljh (for example)

user = tljh.get_current_user() (mybe)

For example if de url is like /user/antonio123/… i would like to get antonio123 somewhere in my Python code.

Just found the answer.

If i write
import os
user = os.environ[‘JUPYTERHUB_USER’]

i get the current user :slight_smile:

2 Likes

That’s it. You can see the definitions of the available environment variables in the Spawner docs.