# Getting groups for a user using Python SDK

**URL:** <https://devforum.okta.com/t/getting-groups-for-a-user-using-python-sdk/242>\
**Category:** API\
**Tags:** python\
**Created:** [July 19, 2017, 4:11pm UTC](https://devforum.okta.com/t/getting-groups-for-a-user-using-python-sdk/242 "2017-07-19T16:11:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aswin](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@aswin](https://devforum.okta.com/u/aswin)\
**Post date:** [July 19, 2017, 4:11pm UTC](https://devforum.okta.com/t/getting-groups-for-a-user-using-python-sdk/242/1 "2017-07-19T16:11:20Z")

</div>

Hi,

I’m trying to get the groups that a user is a member of using the python SDK. I need to call this API - [Users | Okta Developer](https://developer.okta.com/docs/api/resources/users.html#get-member-groups). How can I do this using the python SDK? I wasn’t able to find anything here - [GitHub - okta/okta-sdk-python](https://developer.okta.com/docs/sdk/core/python_api_sdk/index.html). Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![jmelberg](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/jmelberg/32/154_2.png) [@jmelberg](https://devforum.okta.com/u/jmelberg)\
**Post date:** [July 24, 2017, 11:32pm UTC](https://devforum.okta.com/t/getting-groups-for-a-user-using-python-sdk/242/2 "2017-07-24T23:32:44Z")

</div>

You can use the the method [Add User To Group By ID](https://github.com/okta/okta-sdk-python/blob/master/okta/UserGroupsClient.py#L126-L135):

```
from okta import UserGroupsClient

groups_client = UserGroupsClient("https://{org}.oktapreview.com", "API_KEY")
group = groups_client.get_groups(query="UniqueGroupName")[0]

# Add user to group by ID
groups_client.add_user_to_group_by_id(group.id, user.id)
```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [January 12, 2024, 7:10pm UTC](https://devforum.okta.com/t/getting-groups-for-a-user-using-python-sdk/242/3 "2024-01-12T19:10:32Z")

</div>

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