Get Device Groups in Zenoss with ZenDMD

import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
DMD = ZenScriptBase(connect=True).dmd
   
for Group in DMD.Groups.getSubOrganizers():
    print Group.getPrimaryId()

Get all Devices in specific Group

for Device in Group.devices():
    print Device.getPrimaryId()