# Accessing user groups from pre\_spawn\_hook

**URL:** <https://discourse.jupyter.org/t/accessing-user-groups-from-pre-spawn-hook/9723>\
**Category:** Zero to JupyterHub on Kubernetes\
**Tags:** how-to, help-wanted\
**Created:** [June 23, 2021, 5:08pm UTC](https://discourse.jupyter.org/t/accessing-user-groups-from-pre-spawn-hook/9723 "2021-06-23T17:08:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidan](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@aidan](https://discourse.jupyter.org/u/aidan)\
**Post date:** [June 23, 2021, 5:08pm UTC](https://discourse.jupyter.org/t/accessing-user-groups-from-pre-spawn-hook/9723/1 "2021-06-23T17:08:21Z")

</div>

For a high level overview, I am writing a web app which allows users to access a hosted version of jupyterhub (I’m using z2jh with an aws cluster (not eks)). I would like my users to select their compute requirements (small, medium, and large) on my website and be directly taken to a server. Through the REST API, I’ve created groups (small, medium, and large) and now wish to spawn servers of the appropriate size given this group. I would like my pre\_spawn\_hook to look something like this:

```auto
 async def set_resources_hook(spawner):
              groups = [group['name'] in spawner.user.groups]
              if "small" in groups:
                      spawner.cpu_limit = 2.0
                      spawner.cpu_guarantee = 1.0
                      spawner.mem_limit = "2G"
                      spawner.mem_guarantee = "1G"
              if {...more code...}
                      ...
      c.KubeSpawner.pre_spawn_hook = set_resources_hook

```

However, I have not figured out how to access the user groups from the pre\_spawn\_hook and would appreciate any pointers.

---

<div class="post-metadata">

**Author:** ![aidan](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@aidan](https://discourse.jupyter.org/u/aidan)\
**Post date:** [June 23, 2021, 11:50pm UTC](https://discourse.jupyter.org/t/accessing-user-groups-from-pre-spawn-hook/9723/2 "2021-06-23T23:50:10Z")

</div>

I fixed this with `[group.name for group in spawner.user.groups]`

```auto
[group.name for group in spawner.user.groups]

```

–facepalm
