@@ -6,62 +6,84 @@ This API wrapper is designed to work with [Split](https://www.split.io), the pla
66
77For specific instructions on how to use this API refer to our [ official API documentation] ( https://docs.split.io/reference ) .
88
9- Install the split-admin-api:\
10- ` pip install split-admin-api `
9+ Install the split-admin-api:
10+ ```
11+ pip install split-admin-api
12+ ```
1113
12- Import the client object and initialize connection using an Admin API Key:\
13- `from splitapiclient.main import get_client
14+ Import the client object and initialize connection using an Admin API Key:
15+
16+ ```
17+ from splitapiclient.main import get_client
1418client = get_client({'apikey': 'ADMIN API KEY'})
15- `
19+ ```
20+
21+
22+ Enable optional logging:
1623
17- Enable optional logging: \
18- ` import logging
24+ ```
25+ import logging
1926logging.basicConfig(level=logging.DEBUG)
20- `
27+ ```
28+
29+ ** Workspaces**
30+
31+ Fetch all workspaces:
2132
22- ** Workspaces** \
23- Fetch all workspaces:\
24- `for ws in client.workspaces.list():
33+ ```
34+ for ws in client.workspaces.list():
2535 print ("\nWorkspace:"+ws.name+", Id: "+ws.id)
26- `
36+ ```
2737
28- Find a specific workspaces:\
29- `ws = client.workspaces.find("Defaults")
38+ Find a specific workspaces:
39+
40+ ```
41+ ws = client.workspaces.find("Defaults")
3042print ("\nWorkspace:"+ws.name+", Id: "+ws.id)
31- `
43+ ```
44+
45+ ** Environments**
46+
47+ Fetch all Environments:
3248
33- ** Environments** \
34- Fetch all Environments:\
35- `ws = client.workspaces.find("Defaults")
49+ ```
50+ ws = client.workspaces.find("Defaults")
3651for env in client.environments.list(ws.id):
3752 print ("\nEnvironment: "+env.name+", Id: "+env.id)
38- `
53+ ```
54+
55+ Add new environment:
3956
40- Add new environment: \
41- ` ws = client.workspaces.find("Defaults")
57+ ```
58+ ws = client.workspaces.find("Defaults")
4259env = ws.add_environment({'name':'new_environment', 'production':False})
43- `
60+ ```
61+
62+ ** Splits**
63+ Fetch all Splits:
4464
45- ** Splits** \
46- Fetch all Splits:\
47- `ws = client.workspaces.find("Defaults")
65+ ```
66+ ws = client.workspaces.find("Defaults")
4867for split in client.splits.list(ws.id):
4968 print ("\nSplit: "+split.name+", "+split._workspace_id)
50- `
69+ ```
70+
71+ Add new Split:
5172
52- Add new Split:\
53- `
73+ ```
5474split = ws.add_split({'name':'split_name', 'description':'new UI feature'}, "user")
5575print(split.name)
56- `
76+ ```
5777
58- Add tags:\
59- `
78+ Add tags:
79+
80+ ```
6081split.associate_tags(['my_new_tag', 'another_new_tag'])
61- `
82+ ```
83+
84+ Add Split to environment:
6285
63- Add Split to environment:\
64- `
86+ ```
6587ws = client.workspaces.find("Defaults")
6688split = client.splits.find("new_feature", ws.id)
6789env = client.environments.find("Production", ws.id)
@@ -75,120 +97,136 @@ rl = rule.Rule({'condition':cond.export_dict(), 'buckets':[bk1.export_dict(), bk
7597defrl = default_rule.DefaultRule({"treatment":"off","size":100})
7698data={"treatments":[tr1.export_dict() ,tr2.export_dict()],"defaultTreatment":"off", "baselineTreatment": "off","rules":[rl.export_dict()],"defaultRule":[defrl.export_dict()], "comment": "adding split to production"}
7799splitdef = split.add_to_environment(env.id, data)
78- `
100+ ```
79101
80- Kill Split:\
81- `
102+ Kill Split:
103+
104+ ```
82105ws = client.workspaces.find("Defaults")
83106env = client.environments.find("Production", ws.id)
84107splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
85108splitDef.kill()
86- `
109+ ```
110+
111+ Restore Split:
87112
88- Restore Split:\
89- `
113+ ```
90114splitDef.restore()
91- `
115+ ```
92116
93- Fetch all Splits in an Environment:\
94- `
117+ Fetch all Splits in an Environment:
118+
119+ ```
95120ws = client.workspaces.find("Defaults")
96121env = client.environments.find("Production", ws.id)
97122for spDef in client.split_definitions.list(env.id, ws.id):
98123 print(spDef.name+str(spDef._default_rule))
99- `
124+ ```
125+
126+ Submit a Change request to update a Split definition:
100127
101- Submit a Change request to update a Split definition:\
102- `
128+ ```
103129splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
104130definition= {"treatments":[ {"name":"on"},{"name":"off"}],
105131 "defaultTreatment":"off", "baselineTreatment": "off",
106132 "rules": [],
107133 "defaultRule":[{"treatment":"off","size":100}],"comment": "updating default rule"
108134}
109135splitDef.submit_change_request(definition, 'UPDATE', 'updating default rule', 'comment', ['user@email.com'], '')
110- `
136+ ```
111137
112- List all change requests:\
113- `
138+ List all change requests:
139+
140+ ```
114141for cr in client.change_requests.list():
115142 if cr._split is not None:
116143 print (cr._id+", "+cr._split['name']+", "+cr._title+", "+str(cr._split['environment']['id']))
117144 if cr._segment is not None:
118145 print (cr._id+", "+cr._segment['name']+", "+cr._title)
119- `
146+ ```
147+
148+ Approve specific change request:
120149
121- Approve specific change request:\
122- `
150+ ```
123151for cr in client.change_requests.list():
124152 if cr._split['name']=='new_feature':
125153 cr.update_status("APPROVED", "done")
126- `
154+ ```
155+
156+ ** Users and Groups**
157+
158+ Fetch all Active users:
127159
128- ** Users and Groups** \
129- Fetch all Active users:\
130- `
160+ ```
131161for user in client.users.list('ACTIVE'):
132162 print(user.email+", "+user._id)
133- `
163+ ```
134164
135- Invite new user:\
136- `
165+ Invite new user:
166+
167+ ```
137168group = client.groups.find('Administrators')
138169userData = {'email':'user@email.com', 'groups':[{'id':'', 'type':'group'}]}
139170userData['groups'][0]['id'] = group._id
140171client.users.invite_user(userData)
141- `
172+ ```
173+
174+ Delete a pending invite:
142175
143- Delete a pending invite:\
144- `
176+ ```
145177for user in client.users.list('PENDING'):
146178 print(user.email+", "+user._id+", "+user._status)
147179 if user.email == 'user@email.com':
148180 client.users.delete(user._id)
149- `
181+ ```
150182
151- Update user info:\
152- `
183+ Update user info:
184+
185+ ```
153186data = {'name':'new_name', 'email':'user@email.com', '2fa':False, 'status':'ACTIVE'}
154187user = client.users.find('user@email.com')
155188user.update_user(user._id, data)
156- `
189+ ```
190+
191+ Fetch all Groups:
157192
158- Fetch all Groups:\
159- `
193+ ```
160194for group in client.groups.list():
161195 print (group._id+", "+group._name)
162- `
196+ ```
163197
164- Create Group:\
165- `
198+ Create Group:
199+
200+ ```
166201client.groups.create_group({'name':'new_group', 'description':''})
167- `
202+ ```
203+
204+ Delete Group:
168205
169- Delete Group:\
170- `
206+ ```
171207group = client.groups.find('new_group')
172208client.groups.delete_group(group._id)
173- `
209+ ```
174210
175- Replace existing user group:\
176- `
211+ Replace existing user group:
212+
213+ ```
177214user = client.users.find('user@email.com')
178215group = client.groups.find('Administrators')
179216data = [{'op': 'replace', 'path': '/groups/0', 'value': {'id': '<groupId>', 'type':'group'}}]
180217data[0]['value']['id'] = group._id
181218user.update_user_group(data)
182- `
219+ ```
220+
221+ Add user to new group
183222
184- Add user to new group\
185- `
223+ ```
186224user = client.users.find('user@email.com')
187225group = client.groups.find('Administrators')
188226data = [{'op': 'add', 'path': '/groups/-', 'value': {'id': '<groupId>', 'type':'group'}}]
189227data[0]['value']['id'] = group._id
190228user.update_user_group(data)
191- `
229+ ```
192230
193231### Commitment to Quality:
194232
0 commit comments