Skip to content

Commit 2fba16f

Browse files
committed
Updated readme
1 parent 5b5095c commit 2fba16f

File tree

1 file changed

+178
-51
lines changed

1 file changed

+178
-51
lines changed

README.md

Lines changed: 178 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Split Python API
1+
# Split Python Admin API
22

33
This 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,55 +7,85 @@ This API wrapper is designed to work with [Split](https://www.split.io), the pla
77
For specific instructions on how to use this API refer to our [official API documentation](https://docs.split.io/reference).
88

99
Install the split-admin-api:
10+
1011
`pip install split-admin-api`
1112

1213
Import the client object and initialize connection using an Admin API Key:
13-
`from splitapiclient.main import get_client
14+
15+
```
16+
from splitapiclient.main import get_client
1417
client = get_client({'apikey': 'ADMIN API KEY'})
15-
`
18+
```
1619
Enable optional logging:
17-
`import logging
20+
21+
```
22+
import logging
1823
logging.basicConfig(level=logging.DEBUG)
19-
`
24+
```
25+
2026
**Workspaces**
27+
2128
Fetch all workspaces:
22-
`for ws in client.workspaces.list():
29+
30+
```
31+
for ws in client.workspaces.list():
2332
print ("\nWorkspace:"+ws.name+", Id: "+ws.id)
24-
`
25-
Find a specific workspaces:
26-
`ws = client.workspaces.find("Defaults")
33+
```
34+
35+
Find a specific workspace:
36+
37+
```
38+
ws = client.workspaces.find("Defaults")
2739
print ("\nWorkspace:"+ws.name+", Id: "+ws.id)
28-
`
40+
```
41+
2942
**Environments**
43+
3044
Fetch all Environments:
31-
`ws = client.workspaces.find("Defaults")
45+
46+
```
47+
ws = client.workspaces.find("Defaults")
3248
for env in client.environments.list(ws.id):
3349
print ("\nEnvironment: "+env.name+", Id: "+env.id)
50+
```
51+
3452
Add new environment:
35-
`ws = client.workspaces.find("Defaults")
53+
54+
```
55+
ws = client.workspaces.find("Defaults")
3656
env = ws.add_environment({'name':'new_environment', 'production':False})
37-
`
57+
```
3858

3959
**Splits**
60+
4061
Fetch all Splits:
41-
`ws = client.workspaces.find("Defaults")
62+
63+
```
64+
ws = client.workspaces.find("Defaults")
4265
for split in client.splits.list(ws.id):
4366
print ("\nSplit: "+split.name+", "+split._workspace_id)
44-
`
67+
```
68+
4569
Add new Split:
46-
`
70+
71+
```
4772
split = ws.add_split({'name':'split_name', 'description':'new UI feature'}, "user")
4873
print(split.name)
49-
`
74+
```
75+
5076
Add tags:
51-
`
77+
78+
```
5279
split.associate_tags(['my_new_tag', 'another_new_tag'])
53-
`
80+
```
81+
5482
Add Split to environment:
55-
`
83+
84+
```
5685
ws = client.workspaces.find("Defaults")
5786
split = client.splits.find("new_feature", ws.id)
5887
env = client.environments.find("Production", ws.id)
88+
5989
tr1 = treatment.Treatment({"name":"on","configurations":""})
6090
tr2 = treatment.Treatment({"name":"off","configurations":""})
6191
bk1 = bucket.Bucket({"treatment":"on","size":50})
@@ -65,106 +95,202 @@ cond = condition.Condition({'matchers':[match.export_dict()]})
6595
rl = rule.Rule({'condition':cond.export_dict(), 'buckets':[bk1.export_dict(), bk2.export_dict()]})
6696
defrl = default_rule.DefaultRule({"treatment":"off","size":100})
6797
data={"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+
6899
splitdef = split.add_to_environment(env.id, data)
69-
`
100+
```
101+
70102
Kill Split:
71-
`
103+
104+
```
72105
ws = client.workspaces.find("Defaults")
73106
env = client.environments.find("Production", ws.id)
74107
splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
75108
splitDef.kill()
76-
`
109+
```
110+
77111
Restore Split:
78-
`
112+
113+
```
79114
splitDef.restore()
80-
`
115+
```
116+
81117
Fetch all Splits in an Environment:
82-
`
118+
119+
```
83120
ws = client.workspaces.find("Defaults")
84121
env = client.environments.find("Production", ws.id)
85122
for spDef in client.split_definitions.list(env.id, ws.id):
86123
print(spDef.name+str(spDef._default_rule))
87-
`
124+
```
125+
88126
Submit a Change request to update a Split definition:
89-
`
127+
128+
```
90129
splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
91130
definition= {"treatments":[ {"name":"on"},{"name":"off"}],
92131
"defaultTreatment":"off", "baselineTreatment": "off",
93132
"rules": [],
94133
"defaultRule":[{"treatment":"off","size":100}],"comment": "updating default rule"
95134
}
96135
splitDef.submit_change_request(definition, 'UPDATE', 'updating default rule', 'comment', ['[email protected]'], '')
97-
`
136+
```
137+
98138
List all change requests:
99-
`
139+
140+
```
100141
for cr in client.change_requests.list():
101142
if cr._split is not None:
102143
print (cr._id+", "+cr._split['name']+", "+cr._title+", "+str(cr._split['environment']['id']))
103144
if cr._segment is not None:
104145
print (cr._id+", "+cr._segment['name']+", "+cr._title)
105-
`
146+
```
147+
106148
Approve specific change request:
107-
`
149+
150+
```
108151
for cr in client.change_requests.list():
109152
if cr._split['name']=='new_feature':
110153
cr.update_status("APPROVED", "done")
111-
`
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+
```
219+
112220
**Users and Groups**
221+
113222
Fetch all Active users:
114-
`
223+
224+
```
115225
for user in client.users.list('ACTIVE'):
116226
print(user.email+", "+user._id)
117-
`
227+
```
228+
118229
Invite new user:
119-
`
230+
231+
```
120232
group = client.groups.find('Administrators')
121233
userData = {'email':'[email protected]', 'groups':[{'id':'', 'type':'group'}]}
122234
userData['groups'][0]['id'] = group._id
123235
client.users.invite_user(userData)
124-
`
236+
```
237+
125238
Delete a pending invite:
126-
`
239+
240+
```
127241
for user in client.users.list('PENDING'):
128242
print(user.email+", "+user._id+", "+user._status)
129243
if user.email == '[email protected]':
130244
client.users.delete(user._id)
131-
`
245+
```
246+
132247
Update user info:
133-
`
248+
249+
```
134250
data = {'name':'new_name', 'email':'[email protected]', '2fa':False, 'status':'ACTIVE'}
135251
user = client.users.find('[email protected]')
136252
user.update_user(user._id, data)
137-
`
253+
```
254+
138255
Fetch all Groups:
139-
`
256+
257+
```
140258
for group in client.groups.list():
141259
print (group._id+", "+group._name)
142-
`
260+
```
261+
143262
Create Group:
144-
`
263+
264+
```
145265
client.groups.create_group({'name':'new_group', 'description':''})
146-
`
266+
```
267+
147268
Delete Group:
148-
`
269+
270+
```
149271
group = client.groups.find('new_group')
150272
client.groups.delete_group(group._id)
151-
`
273+
```
274+
152275
Replace existing user group:
153-
`
276+
277+
```
154278
user = client.users.find('[email protected]')
155279
group = client.groups.find('Administrators')
156280
data = [{'op': 'replace', 'path': '/groups/0', 'value': {'id': '<groupId>', 'type':'group'}}]
157281
data[0]['value']['id'] = group._id
158282
user.update_user_group(data)
159-
`
283+
```
284+
160285
Add user to new group
161-
`
286+
287+
```
162288
user = client.users.find('[email protected]')
163289
group = client.groups.find('Administrators')
164290
data = [{'op': 'add', 'path': '/groups/-', 'value': {'id': '<groupId>', 'type':'group'}}]
165291
data[0]['value']['id'] = group._id
166292
user.update_user_group(data)
167-
`
293+
```
168294

169295
### Commitment to Quality:
170296

@@ -185,3 +311,4 @@ Visit [split.io/product](https://www.split.io/product) for an overview of Split,
185311
**System Status:**
186312

187313
We 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

Comments
 (0)