Listing groups in G-Suite

Oddly, you can’t pull a report of all groups from G-Suite like you can for users. The only option is to use the API. Here’s how.

Follow steps 1 and 2 from the quickstart guide but instead of the sample Python script, use this:

from httplib2 import Http

from googleapiclient.discovery import build
from oauth2client import file, client, tools

def main():

def _print_all_groups():
    for group in _all_groups():

def _all_groups():
    Return a list of all group dicts.
    # Build a client with appropriate scope privileges
    service = _service(
        # See
        # for a complete list of scopes.

    # Call the Admin SDK Directory API
    return service.groups().list(
        # "my_customer" is a special alias that admins can use.

def _service(service_name, service_version, scope):
    Return a configured service client for the API.
    # Look for a local token.json file. Remove this if changing the scope.
    store = file.Storage('token.json')
    creds = store.get()
    if not creds or creds.invalid:
        # If no valid creds, open a browser window to complete OAuth flow and save token.
        flow = client.flow_from_clientsecrets('credentials.json', scope)
        creds = tools.run_flow(flow, store)

    return build(

if __name__ == '__main__':

Execute this script to print out a complete list of group email addresses.


Something wrong? Suggest an improvement or add a comment (see article history)
Tagged with: gsuite
Filed in: tips

Previous: Advanced pull-request crafting
Next: Easy to change

Copyright © 2005-2022 David Winterbottom
Content licensed under CC BY-NC-SA 4.0.