1- # Split Python Admin API
1+ # Split Python API
22
33This API wrapper is designed to work with [ Split] ( https://www.split.io ) , the platform for controlled rollouts, serving features to your users via the Split feature flag to manage your complete customer experience.
44
@@ -7,85 +7,63 @@ This API wrapper is designed to work with [Split](https://www.split.io), the pla
77For specific instructions on how to use this API refer to our [ official API documentation] ( https://docs.split.io/reference ) .
88
99Install the split-admin-api:
10-
11- ` pip install splitapiclient `
10+ ` pip install split-admin-api `
1211
1312Import the client object and initialize connection using an Admin API Key:
14-
15- ```
16- from splitapiclient.main import get_client
13+ `from splitapiclient.main import get_client
1714client = get_client({'apikey': 'ADMIN API KEY'})
18- ```
19- Enable optional logging:
15+ `
2016
21- ```
22- import logging
17+ Enable optional logging:
18+ ` import logging
2319logging.basicConfig(level=logging.DEBUG)
24- ```
20+ `
2521
2622** Workspaces**
27-
2823Fetch all workspaces:
29-
30- ```
31- for ws in client.workspaces.list():
24+ `for ws in client.workspaces.list():
3225 print ("\nWorkspace:"+ws.name+", Id: "+ws.id)
33- ```
34-
35- Find a specific workspace:
26+ `
3627
37- ```
38- ws = client.workspaces.find("Defaults")
28+ Find a specific workspaces:
29+ ` ws = client.workspaces.find("Defaults")
3930print ("\nWorkspace:"+ws.name+", Id: "+ws.id)
40- ```
31+ `
4132
4233** Environments**
43-
4434Fetch all Environments:
45-
46- ```
47- ws = client.workspaces.find("Defaults")
35+ `ws = client.workspaces.find("Defaults")
4836for env in client.environments.list(ws.id):
4937 print ("\nEnvironment: "+env.name+", Id: "+env.id)
50- ```
51-
5238Add new environment:
53-
54- ```
55- ws = client.workspaces.find("Defaults")
39+ `ws = client.workspaces.find("Defaults")
5640env = ws.add_environment({'name':'new_environment', 'production': False })
57- ```
41+ `
5842
5943** Splits**
6044
6145Fetch all Splits:
62-
63- ```
64- ws = client.workspaces.find("Defaults")
46+ `ws = client.workspaces.find("Defaults")
6547for split in client.splits.list(ws.id):
6648 print ("\nSplit: "+split.name+", "+split._ workspace_id)
67- ```
49+ `
6850
6951Add new Split:
70-
71- ```
52+ `
7253split = ws.add_split({'name':'split_name', 'description':'new UI feature'}, "user")
7354print(split.name)
74- ```
55+ `
7556
7657Add tags:
77-
78- ```
58+ `
7959split.associate_tags([ 'my_new_tag', 'another_new_tag'] )
80- ```
60+ `
8161
8262Add Split to environment:
83-
84- ```
63+ `
8564ws = client.workspaces.find("Defaults")
8665split = client.splits.find("new_feature", ws.id)
8766env = client.environments.find("Production", ws.id)
88-
8967tr1 = treatment.Treatment({"name":"on","configurations":""})
9068tr2 = treatment.Treatment({"name":"off","configurations":""})
9169bk1 = bucket.Bucket({"treatment":"on","size":50})
@@ -95,202 +73,122 @@ cond = condition.Condition({'matchers':[match.export_dict()]})
9573rl = rule.Rule({'condition': cond .export_dict(), 'buckets':[ bk1.export_dict(), bk2.export_dict()] })
9674defrl = default_rule.DefaultRule({"treatment":"off","size":100})
9775data={"treatments":[ tr1.export_dict() ,tr2.export_dict()] ,"defaultTreatment":"off", "baselineTreatment": "off","rules":[ rl.export_dict()] ,"defaultRule":[ defrl.export_dict()] , "comment": "adding split to production"}
98-
9976splitdef = split.add_to_environment(env.id, data)
100- ```
77+ `
10178
10279Kill Split:
103-
104- ```
80+ `
10581ws = client.workspaces.find("Defaults")
10682env = client.environments.find("Production", ws.id)
10783splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
10884splitDef.kill()
109- ```
85+ `
11086
11187Restore Split:
112-
113- ```
88+ `
11489splitDef.restore()
115- ```
90+ `
11691
11792Fetch all Splits in an Environment:
118-
119- ```
93+ `
12094ws = client.workspaces.find("Defaults")
12195env = client.environments.find("Production", ws.id)
12296for spDef in client.split_definitions.list(env.id, ws.id):
12397 print(spDef.name+str(spDef._ default_rule))
124- ```
98+ `
12599
126100Submit a Change request to update a Split definition:
127-
128- ```
101+ `
129102splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
130103definition= {"treatments":[ {"name":"on"},{"name":"off"}] ,
131104 "defaultTreatment":"off", "baselineTreatment": "off",
132105 "rules": [ ] ,
133106 "defaultRule":[ {"treatment":"off","size":100}] ,"comment": "updating default rule"
134107}
135108splitDef.submit_change_request(definition, 'UPDATE', 'updating default rule', 'comment', [ 'user@email.com '] , '')
136- ```
109+ `
137110
138111List all change requests:
139-
140- ```
112+ `
141113for cr in client.change_requests.list():
142114 if cr._ split is not None:
143115 print (cr._ id+", "+cr._ split[ 'name'] +", "+cr._ title+", "+str(cr._ split[ 'environment'] [ 'id' ] ))
144116 if cr._ segment is not None:
145117 print (cr._ id+", "+cr._ segment[ 'name'] +", "+cr._ title)
146- ```
118+ `
147119
148120Approve specific change request:
149-
150- ```
121+ `
151122for cr in client.change_requests.list():
152123 if cr._ split[ 'name'] =='new_feature':
153124 cr.update_status("APPROVED", "done")
154- ```
155-
156- ** Segments**
157-
158- Fetch all Segments:
159-
160- ```
161- ws = client.workspaces.find("Defaults")
162- for seg in client.segments.list(ws.id):
163- print (seg.name)
164- ```
165-
166- Fecth all Segments in an Environment:
167-
168- ```
169- ws = client.workspaces.find("Defaults")
170- env = client.environments.find("Production", ws.id)
171- for segDef in client.segment_definitions.list(env.id, ws.id):
172- print(segDef.name+", "+segDef._trafficType.name)
173-
174- ```
175-
176- Add new Segment:
177-
178- ```
179- ws = client.workspaces.find("Defaults")
180- seg = ws.add_segment({'name':'segment_from_python', 'description':'users'}, "user")
181- ```
182-
183- Add Segment to an Environment:
184-
185- ```
186- ws = client.workspaces.find("Defaults")
187- env = client.environments.find("Production", ws.id)
188- seg = client.segments.find("admin_api_test",ws.id)
189- segDef = seg.add_to_environment(env.id)
190- ```
191-
192- Add Segment Keys:
193-
194- ```
195- ws = client.workspaces.find("Defaults")
196- env = client.environments.find("Production", ws.id)
197- segDef = client.segment_definitions.find("admin_api_test", env.id, ws.id)
198- segDef.import_keys_from_json("false", {"keys":["id4", "id5", "id6"], "comment":"a comment"})
199- ```
200-
201- List Segment Keys:
202-
203- ```
204- ws = client.workspaces.find("Defaults")
205- env = client.environments.find("Production", ws.id)
206- segDef = client.segment_definitions.find("admin_api_test", env.id, ws.id)
207- for key in segDef.get_keys():
208- print(key)
209- ```
210-
211- Export Segment Keys to csv:
212-
213- ```
214- ws = client.workspaces.find("Defaults")
215- env = client.environments.find("Production", ws.id)
216- segDef = client.segment_definitions.find("admin_api_test", env.id, ws.id)
217- segDef.export_keys_to_csv("seg.csv")
218- ```
125+ `
219126
220127** Users and Groups**
221128
222129Fetch all Active users:
223-
224- ```
130+ `
225131for user in client.users.list('ACTIVE'):
226132 print(user.email+", "+user._ id)
227- ```
133+ `
228134
229135Invite new user:
230-
231- ```
136+ `
232137group = client.groups.find('Administrators')
233138userData = {'email':'user@email.com ', 'groups':[ {'id':'', 'type':'group'}] }
234139userData[ 'groups'] [ 0 ] [ 'id'] = group._ id
235140client.users.invite_user(userData)
236- ```
141+ `
237142
238143Delete a pending invite:
239-
240- ```
144+ `
241145for user in client.users.list('PENDING'):
242146 print(user.email+", "+user._ id+", "+user._ status)
243147 if user.email == 'user@email.com ':
244148 client.users.delete(user._ id)
245- ```
149+ `
246150
247151Update user info:
248-
249- ```
152+ `
250153data = {'name':'new_name', 'email':'user@email.com ', '2fa': False , 'status':'ACTIVE'}
251154user = client.users.find('user@email.com ')
252155user.update_user(user._ id, data)
253- ```
156+ `
254157
255158Fetch all Groups:
256-
257- ```
159+ `
258160for group in client.groups.list():
259161 print (group._ id+", "+group._ name)
260- ```
162+ `
261163
262164Create Group:
263-
264- ```
165+ `
265166client.groups.create_group({'name':'new_group', 'description':''})
266- ```
167+ `
267168
268169Delete Group:
269-
270- ```
170+ `
271171group = client.groups.find('new_group')
272172client.groups.delete_group(group._ id)
273- ```
173+ `
274174
275175Replace existing user group:
276-
277- ```
176+ `
278177user = client.users.find('user@email.com ')
279178group = client.groups.find('Administrators')
280179data = [ {'op': 'replace', 'path': '/groups/0', 'value': {'id': '<groupId >', 'type':'group'}}]
281180data[ 0] [ 'value' ] [ 'id'] = group._ id
282181user.update_user_group(data)
283- ```
182+ `
284183
285184Add user to new group
286-
287- ```
185+ `
288186user = client.users.find('user@email.com ')
289187group = client.groups.find('Administrators')
290188data = [ {'op': 'add', 'path': '/groups/-', 'value': {'id': '<groupId >', 'type':'group'}}]
291189data[ 0] [ 'value' ] [ 'id'] = group._ id
292190user.update_user_group(data)
293- ```
191+ `
294192
295193### Commitment to Quality:
296194
@@ -311,4 +209,3 @@ Visit [split.io/product](https://www.split.io/product) for an overview of Split,
311209** System Status:**
312210
313211We use a status page to monitor the availability of Split’s various services. You can check the current status at [ status.split.io] ( http://status.split.io ) .
314-
0 commit comments