Getting the Space name programmatically

Is there a programmatic way of a Space knowing its own name?

For instance, the restart_space method of the huggingface_hub API requires a repo_id. If, say, I want the Space to restart itself, is there a programmatic way of getting this repo_id (and thus working without requiring changes if the Space is ever renamed) or do I have to hard-code it?

1 Like

Maybe simply by this?

import os
space_id = os.getenv("SPACE_ID", "")          # e.g. "username/space-name"

You are quite right. I somehow missed that part of the documentation. Thank you.

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.