Example:
Basic code to use Python and Split REST API to export all feature flags definitions JSON structure in all environments and workspaces to files.
How to use:
- Class wrapper for Admin API can be downloaded from the link: Python Admin API Library Wrapper
- Update your relevant Split Admin API key in code below.
- File name will be [Workspace Name]_[Environment Name]_[Split Name].json
from splitapiclient.main import get_client
#############################################
workspaceName = "Defaults"
environmentName = "Production"
targetFolder="/Users/bilalal-shahwany/Desktop/WeWork/"
#############################################
def SaveToFile(splitDefinition, splitName, workspaceName, environmentName):
reportObj = open(targetFolder+workspaceName+"_"+environmentName+"_"+splitName+".json", "w")
json.dump(splitDefinition, reportObj)
reportObj.close()
ws = client.workspaces.find(workspaceName)
env = client.environments.find(environmentName, ws.id)
for splitDef in client.split_definitions.list(env.id, ws.id):
print ("Exporting Split: "+splitDef._name)
trs = []
for tr in splitDef._treatments:
trs.append(tr.export_dict())
rls = []
for rl in splitDef._rules:
rls.append(rl.export_dict())
drls = []
for drl in splitDef._default_rule:
drls.append(drl.export_dict())
splitDefinition = {"treatments": trs,"defaultTreatment": splitDef._default_treatment, "rules": rls, "defaultRule": drls}
SaveToFile(splitDefinition, splitDef._name, ws._name, env._name)
Comments
0 comments
Please sign in to leave a comment.