Skip to content

Commit 49dd11b

Browse files
authored
updated README.md
fixed code blocks
1 parent 2546da8 commit 49dd11b

1 file changed

Lines changed: 119 additions & 81 deletions

File tree

README.md

Lines changed: 119 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,84 @@ This API wrapper is designed to work with [Split](https://www.split.io), the pla
66

77
For 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
1418
client = 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
1926
logging.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")
3042
print ("\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")
3651
for 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")
4259
env = 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")
4867
for 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+
```
5474
split = ws.add_split({'name':'split_name', 'description':'new UI feature'}, "user")
5575
print(split.name)
56-
`
76+
```
5777

58-
Add tags:\
59-
`
78+
Add tags:
79+
80+
```
6081
split.associate_tags(['my_new_tag', 'another_new_tag'])
61-
`
82+
```
83+
84+
Add Split to environment:
6285

63-
Add Split to environment:\
64-
`
86+
```
6587
ws = client.workspaces.find("Defaults")
6688
split = client.splits.find("new_feature", ws.id)
6789
env = client.environments.find("Production", ws.id)
@@ -75,120 +97,136 @@ rl = rule.Rule({'condition':cond.export_dict(), 'buckets':[bk1.export_dict(), bk
7597
defrl = default_rule.DefaultRule({"treatment":"off","size":100})
7698
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"}
7799
splitdef = split.add_to_environment(env.id, data)
78-
`
100+
```
79101

80-
Kill Split:\
81-
`
102+
Kill Split:
103+
104+
```
82105
ws = client.workspaces.find("Defaults")
83106
env = client.environments.find("Production", ws.id)
84107
splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
85108
splitDef.kill()
86-
`
109+
```
110+
111+
Restore Split:
87112

88-
Restore Split:\
89-
`
113+
```
90114
splitDef.restore()
91-
`
115+
```
92116

93-
Fetch all Splits in an Environment:\
94-
`
117+
Fetch all Splits in an Environment:
118+
119+
```
95120
ws = client.workspaces.find("Defaults")
96121
env = client.environments.find("Production", ws.id)
97122
for 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+
```
103129
splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
104130
definition= {"treatments":[ {"name":"on"},{"name":"off"}],
105131
"defaultTreatment":"off", "baselineTreatment": "off",
106132
"rules": [],
107133
"defaultRule":[{"treatment":"off","size":100}],"comment": "updating default rule"
108134
}
109135
splitDef.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+
```
114141
for 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+
```
123151
for 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+
```
131161
for 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+
```
137168
group = client.groups.find('Administrators')
138169
userData = {'email':'user@email.com', 'groups':[{'id':'', 'type':'group'}]}
139170
userData['groups'][0]['id'] = group._id
140171
client.users.invite_user(userData)
141-
`
172+
```
173+
174+
Delete a pending invite:
142175

143-
Delete a pending invite:\
144-
`
176+
```
145177
for 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+
```
153186
data = {'name':'new_name', 'email':'user@email.com', '2fa':False, 'status':'ACTIVE'}
154187
user = client.users.find('user@email.com')
155188
user.update_user(user._id, data)
156-
`
189+
```
190+
191+
Fetch all Groups:
157192

158-
Fetch all Groups:\
159-
`
193+
```
160194
for group in client.groups.list():
161195
print (group._id+", "+group._name)
162-
`
196+
```
163197

164-
Create Group:\
165-
`
198+
Create Group:
199+
200+
```
166201
client.groups.create_group({'name':'new_group', 'description':''})
167-
`
202+
```
203+
204+
Delete Group:
168205

169-
Delete Group:\
170-
`
206+
```
171207
group = client.groups.find('new_group')
172208
client.groups.delete_group(group._id)
173-
`
209+
```
174210

175-
Replace existing user group:\
176-
`
211+
Replace existing user group:
212+
213+
```
177214
user = client.users.find('user@email.com')
178215
group = client.groups.find('Administrators')
179216
data = [{'op': 'replace', 'path': '/groups/0', 'value': {'id': '<groupId>', 'type':'group'}}]
180217
data[0]['value']['id'] = group._id
181218
user.update_user_group(data)
182-
`
219+
```
220+
221+
Add user to new group
183222

184-
Add user to new group\
185-
`
223+
```
186224
user = client.users.find('user@email.com')
187225
group = client.groups.find('Administrators')
188226
data = [{'op': 'add', 'path': '/groups/-', 'value': {'id': '<groupId>', 'type':'group'}}]
189227
data[0]['value']['id'] = group._id
190228
user.update_user_group(data)
191-
`
229+
```
192230

193231
### Commitment to Quality:
194232

0 commit comments

Comments
 (0)