= user_groups()
:description: Returns the groups a user belongs to as a list of ECMGroup objects (mng.GetUserGroups). Includes internal name and display name for each group.
:keywords: user_groups, mng.GetUserGroups, ECMGroup, user groups
:page-tags: api, security

Returns all groups the given user belongs to.

== Signature

[tabs]
====
Sync::
+
[source,python]
----
ecm.security.user_groups(user_guid: str) -> list[ECMGroup]
----

Async::
+
[source,python]
----
await ecm.security.user_groups(user_guid: str) -> list[ECMGroup]
----
====

== Parameters

[cols="1,1,3"]
|===
|Parameter |Default |Description

|`user_guid`
|—
|GUID of the user whose group memberships should be returned.
|===

== Return value

List of `ECMGroup` instances. Empty list when the user is not a member of any group.

For `ECMGroup` fields — see xref:api/security/groups.adoc[groups()].

== Examples

=== Retrieve groups of a user

[tabs]
====
Sync::
+
[source,python]
----
user = ecm.security.user("john")
if user:
    groups = ecm.security.user_groups(user.guid)
    for group in groups:
        print(group.name)
----

Async::
+
[source,python]
----
user = await ecm.security.user("john")
if user:
    groups = await ecm.security.user_groups(user.guid)
    for group in groups:
        print(group.name)
----
====

=== Check if a user is a member of a specific group

[tabs]
====
Sync::
+
[source,python]
----
user = ecm.security.user("john")
if user:
    groups = ecm.security.user_groups(user.guid)
    is_admin = any(g.name == "Administrators" for g in groups)
    print(f"john is admin: {is_admin}")
----

Async::
+
[source,python]
----
user = await ecm.security.user("john")
if user:
    groups = await ecm.security.user_groups(user.guid)
    is_admin = any(g.name == "Administrators" for g in groups)
    print(f"john is admin: {is_admin}")
----
====

== See also

* xref:api/security/users.adoc[users()] — All users including group list (`extended_info=True`)
* xref:api/security/groups.adoc[groups()] — All groups on the server
* xref:api/security/group_members.adoc[group_members()] — Members of a group
