importargparseimportjsonfromoffice365.sharepoint.client_contextimportClientContextfromtests.settingsimportcert_path,cert_thumbprint,client_id,team_site_url,tenantdefmain():argparse.ArgumentParser(description="Export term store groups and term sets to JSON").parse_args()ctx=ClientContext(team_site_url).with_client_certificate(tenant,client_id=client_id,thumbprint=cert_thumbprint,cert_path=cert_path)term_groups=ctx.taxonomy.term_store.term_groups.get().execute_query()forterm_groupinterm_groups:term_group.term_sets.get().execute_query()print(json.dumps(term_groups.to_json(),indent=4))if__name__=="__main__":main()