Skip to content

Commit 9ebfb2b

Browse files
committed
Reformatted to accomadate pypi site
1 parent d4de279 commit 9ebfb2b

1 file changed

Lines changed: 53 additions & 156 deletions

File tree

README.md

Lines changed: 53 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Split Python Admin API
1+
# Split Python 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,85 +7,63 @@ 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-
11-
`pip install splitapiclient`
10+
`pip install split-admin-api`
1211

1312
Import 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
1714
client = get_client({'apikey': 'ADMIN API KEY'})
18-
```
19-
Enable optional logging:
15+
`
2016

21-
```
22-
import logging
17+
Enable optional logging:
18+
`import logging
2319
logging.basicConfig(level=logging.DEBUG)
24-
```
20+
`
2521

2622
**Workspaces**
27-
2823
Fetch 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")
3930
print ("\nWorkspace:"+ws.name+", Id: "+ws.id)
40-
```
31+
`
4132

4233
**Environments**
43-
4434
Fetch all Environments:
45-
46-
```
47-
ws = client.workspaces.find("Defaults")
35+
`ws = client.workspaces.find("Defaults")
4836
for env in client.environments.list(ws.id):
4937
print ("\nEnvironment: "+env.name+", Id: "+env.id)
50-
```
51-
5238
Add new environment:
53-
54-
```
55-
ws = client.workspaces.find("Defaults")
39+
`ws = client.workspaces.find("Defaults")
5640
env = ws.add_environment({'name':'new_environment', 'production':False})
57-
```
41+
`
5842

5943
**Splits**
6044

6145
Fetch all Splits:
62-
63-
```
64-
ws = client.workspaces.find("Defaults")
46+
`ws = client.workspaces.find("Defaults")
6547
for split in client.splits.list(ws.id):
6648
print ("\nSplit: "+split.name+", "+split._workspace_id)
67-
```
49+
`
6850

6951
Add new Split:
70-
71-
```
52+
`
7253
split = ws.add_split({'name':'split_name', 'description':'new UI feature'}, "user")
7354
print(split.name)
74-
```
55+
`
7556

7657
Add tags:
77-
78-
```
58+
`
7959
split.associate_tags(['my_new_tag', 'another_new_tag'])
80-
```
60+
`
8161

8262
Add Split to environment:
83-
84-
```
63+
`
8564
ws = client.workspaces.find("Defaults")
8665
split = client.splits.find("new_feature", ws.id)
8766
env = client.environments.find("Production", ws.id)
88-
8967
tr1 = treatment.Treatment({"name":"on","configurations":""})
9068
tr2 = treatment.Treatment({"name":"off","configurations":""})
9169
bk1 = bucket.Bucket({"treatment":"on","size":50})
@@ -95,202 +73,122 @@ cond = condition.Condition({'matchers':[match.export_dict()]})
9573
rl = rule.Rule({'condition':cond.export_dict(), 'buckets':[bk1.export_dict(), bk2.export_dict()]})
9674
defrl = default_rule.DefaultRule({"treatment":"off","size":100})
9775
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-
9976
splitdef = split.add_to_environment(env.id, data)
100-
```
77+
`
10178

10279
Kill Split:
103-
104-
```
80+
`
10581
ws = client.workspaces.find("Defaults")
10682
env = client.environments.find("Production", ws.id)
10783
splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
10884
splitDef.kill()
109-
```
85+
`
11086

11187
Restore Split:
112-
113-
```
88+
`
11489
splitDef.restore()
115-
```
90+
`
11691

11792
Fetch all Splits in an Environment:
118-
119-
```
93+
`
12094
ws = client.workspaces.find("Defaults")
12195
env = client.environments.find("Production", ws.id)
12296
for spDef in client.split_definitions.list(env.id, ws.id):
12397
print(spDef.name+str(spDef._default_rule))
124-
```
98+
`
12599

126100
Submit a Change request to update a Split definition:
127-
128-
```
101+
`
129102
splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
130103
definition= {"treatments":[ {"name":"on"},{"name":"off"}],
131104
"defaultTreatment":"off", "baselineTreatment": "off",
132105
"rules": [],
133106
"defaultRule":[{"treatment":"off","size":100}],"comment": "updating default rule"
134107
}
135108
splitDef.submit_change_request(definition, 'UPDATE', 'updating default rule', 'comment', ['user@email.com'], '')
136-
```
109+
`
137110

138111
List all change requests:
139-
140-
```
112+
`
141113
for 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

148120
Approve specific change request:
149-
150-
```
121+
`
151122
for 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

222129
Fetch all Active users:
223-
224-
```
130+
`
225131
for user in client.users.list('ACTIVE'):
226132
print(user.email+", "+user._id)
227-
```
133+
`
228134

229135
Invite new user:
230-
231-
```
136+
`
232137
group = client.groups.find('Administrators')
233138
userData = {'email':'user@email.com', 'groups':[{'id':'', 'type':'group'}]}
234139
userData['groups'][0]['id'] = group._id
235140
client.users.invite_user(userData)
236-
```
141+
`
237142

238143
Delete a pending invite:
239-
240-
```
144+
`
241145
for 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

247151
Update user info:
248-
249-
```
152+
`
250153
data = {'name':'new_name', 'email':'user@email.com', '2fa':False, 'status':'ACTIVE'}
251154
user = client.users.find('user@email.com')
252155
user.update_user(user._id, data)
253-
```
156+
`
254157

255158
Fetch all Groups:
256-
257-
```
159+
`
258160
for group in client.groups.list():
259161
print (group._id+", "+group._name)
260-
```
162+
`
261163

262164
Create Group:
263-
264-
```
165+
`
265166
client.groups.create_group({'name':'new_group', 'description':''})
266-
```
167+
`
267168

268169
Delete Group:
269-
270-
```
170+
`
271171
group = client.groups.find('new_group')
272172
client.groups.delete_group(group._id)
273-
```
173+
`
274174

275175
Replace existing user group:
276-
277-
```
176+
`
278177
user = client.users.find('user@email.com')
279178
group = client.groups.find('Administrators')
280179
data = [{'op': 'replace', 'path': '/groups/0', 'value': {'id': '<groupId>', 'type':'group'}}]
281180
data[0]['value']['id'] = group._id
282181
user.update_user_group(data)
283-
```
182+
`
284183

285184
Add user to new group
286-
287-
```
185+
`
288186
user = client.users.find('user@email.com')
289187
group = client.groups.find('Administrators')
290188
data = [{'op': 'add', 'path': '/groups/-', 'value': {'id': '<groupId>', 'type':'group'}}]
291189
data[0]['value']['id'] = group._id
292190
user.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

313211
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)