Skip to content

Commit f84636a

Browse files
committed
updated readme
1 parent 5bc3463 commit f84636a

1 file changed

Lines changed: 226 additions & 60 deletions

File tree

README.md

Lines changed: 226 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ For specific instructions on how to use Split Admin REST API refer to our [offic
66

77
Full documentation on this Python wrapper is available in [this link](https://help.split.io/hc/en-us/articles/4412331052685-Python-PyPi-library-for-Split-REST-Admin-API).
88

9-
### Quick setup
9+
## Quick Setup
1010

1111
Install the splitapiclient:
1212
```
@@ -20,6 +20,217 @@ from splitapiclient.main import get_client
2020
client = get_client({'apikey': 'ADMIN API KEY'})
2121
```
2222

23+
Enable optional logging:
24+
25+
```python
26+
import logging
27+
logging.basicConfig(level=logging.DEBUG)
28+
```
29+
30+
## Standard Split API Usage
31+
32+
### Workspaces
33+
34+
Fetch all workspaces:
35+
36+
```python
37+
for ws in client.workspaces.list():
38+
print("\nWorkspace:" + ws.name + ", Id: " + ws.id)
39+
```
40+
41+
Find a specific workspace:
42+
43+
```python
44+
ws = client.workspaces.find("Defaults")
45+
print("\nWorkspace:" + ws.name + ", Id: " + ws.id)
46+
```
47+
48+
### Environments
49+
50+
Fetch all Environments:
51+
52+
```python
53+
ws = client.workspaces.find("Defaults")
54+
for env in client.environments.list(ws.id):
55+
print("\nEnvironment: " + env.name + ", Id: " + env.id)
56+
```
57+
58+
Add new environment:
59+
60+
```python
61+
ws = client.workspaces.find("Defaults")
62+
env = ws.add_environment({'name': 'new_environment', 'production': False})
63+
```
64+
65+
### Splits
66+
Fetch all Splits:
67+
68+
```python
69+
ws = client.workspaces.find("Defaults")
70+
for split in client.splits.list(ws.id):
71+
print("\nSplit: " + split.name + ", " + split._workspace_id)
72+
```
73+
74+
Add new Split:
75+
76+
```python
77+
split = ws.add_split({'name': 'split_name', 'description': 'new UI feature'}, "user")
78+
print(split.name)
79+
```
80+
81+
Add tags:
82+
83+
```python
84+
split.associate_tags(['my_new_tag', 'another_new_tag'])
85+
```
86+
87+
Add Split to environment:
88+
89+
```python
90+
ws = client.workspaces.find("Defaults")
91+
split = client.splits.find("new_feature", ws.id)
92+
env = client.environments.find("Production", ws.id)
93+
tr1 = treatment.Treatment({"name":"on","configurations":""})
94+
tr2 = treatment.Treatment({"name":"off","configurations":""})
95+
bk1 = bucket.Bucket({"treatment":"on","size":50})
96+
bk2 = bucket.Bucket({"treatment":"off","size":50})
97+
match = matcher.Matcher({"attribute":"group","type":"IN_LIST_STRING","strings":["employees"]})
98+
cond = condition.Condition({'matchers':[match.export_dict()]})
99+
rl = rule.Rule({'condition':cond.export_dict(), 'buckets':[bk1.export_dict(), bk2.export_dict()]})
100+
defrl = default_rule.DefaultRule({"treatment":"off","size":100})
101+
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"}
102+
splitdef = split.add_to_environment(env.id, data)
103+
```
104+
105+
Kill Split:
106+
107+
```python
108+
ws = client.workspaces.find("Defaults")
109+
env = client.environments.find("Production", ws.id)
110+
splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
111+
splitDef.kill()
112+
```
113+
114+
Restore Split:
115+
116+
```python
117+
splitDef.restore()
118+
```
119+
120+
Fetch all Splits in an Environment:
121+
122+
```python
123+
ws = client.workspaces.find("Defaults")
124+
env = client.environments.find("Production", ws.id)
125+
for spDef in client.split_definitions.list(env.id, ws.id):
126+
print(spDef.name + str(spDef._default_rule))
127+
```
128+
129+
Submit a Change request to update a Split definition:
130+
131+
```python
132+
splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
133+
definition= {"treatments":[ {"name":"on"},{"name":"off"}],
134+
"defaultTreatment":"off", "baselineTreatment": "off",
135+
"rules": [],
136+
"defaultRule":[{"treatment":"off","size":100}],"comment": "updating default rule"
137+
}
138+
splitDef.submit_change_request(definition, 'UPDATE', 'updating default rule', 'comment', ['user@email.com'], '')
139+
```
140+
141+
List all change requests:
142+
143+
```python
144+
for cr in client.change_requests.list():
145+
if cr._split is not None:
146+
print(cr._id + ", " + cr._split['name'] + ", " + cr._title + ", " + str(cr._split['environment']['id']))
147+
if cr._segment is not None:
148+
print(cr._id + ", " + cr._segment['name'] + ", " + cr._title)
149+
```
150+
151+
Approve specific change request:
152+
153+
```python
154+
for cr in client.change_requests.list():
155+
if cr._split['name'] == 'new_feature':
156+
cr.update_status("APPROVED", "done")
157+
```
158+
159+
### Users and Groups
160+
161+
Fetch all Active users:
162+
163+
```python
164+
for user in client.users.list('ACTIVE'):
165+
print(user.email + ", " + user._id)
166+
```
167+
168+
Invite new user:
169+
170+
```python
171+
group = client.groups.find('Administrators')
172+
userData = {'email': 'user@email.com', 'groups': [{'id': '', 'type': 'group'}]}
173+
userData['groups'][0]['id'] = group._id
174+
client.users.invite_user(userData)
175+
```
176+
177+
Delete a pending invite:
178+
179+
```python
180+
for user in client.users.list('PENDING'):
181+
print(user.email + ", " + user._id + ", " + user._status)
182+
if user.email == 'user@email.com':
183+
client.users.delete(user._id)
184+
```
185+
186+
Update user info:
187+
188+
```python
189+
data = {'name': 'new_name', 'email': 'user@email.com', '2fa': False, 'status': 'ACTIVE'}
190+
user = client.users.find('user@email.com')
191+
user.update_user(user._id, data)
192+
```
193+
194+
Fetch all Groups:
195+
196+
```python
197+
for group in client.groups.list():
198+
print(group._id + ", " + group._name)
199+
```
200+
201+
Create Group:
202+
203+
```python
204+
client.groups.create_group({'name': 'new_group', 'description': ''})
205+
```
206+
207+
Delete Group:
208+
209+
```python
210+
group = client.groups.find('new_group')
211+
client.groups.delete_group(group._id)
212+
```
213+
214+
Replace existing user group:
215+
216+
```python
217+
user = client.users.find('user@email.com')
218+
group = client.groups.find('Administrators')
219+
data = [{'op': 'replace', 'path': '/groups/0', 'value': {'id': '<groupId>', 'type': 'group'}}]
220+
data[0]['value']['id'] = group._id
221+
user.update_user_group(data)
222+
```
223+
224+
Add user to new group
225+
226+
```python
227+
user = client.users.find('user@email.com')
228+
group = client.groups.find('Administrators')
229+
data = [{'op': 'add', 'path': '/groups/-', 'value': {'id': '<groupId>', 'type': 'group'}}]
230+
data[0]['value']['id'] = group._id
231+
user.update_user_group(data)
232+
```
233+
23234
## Using in Harness Mode
24235

25236
Starting with version 3.5.0, the Split API client supports operating in "harness mode" to interact with both Split and Harness Feature Flags APIs.
@@ -70,7 +281,6 @@ client = get_client({
70281
'harness_token': 'YOUR_HARNESS_TOKEN', # Used for both Harness and Split endpoints
71282
'account_identifier': 'YOUR_HARNESS_ACCOUNT_ID'
72283
})
73-
74284
```
75285

76286
### Working with Split Resources in Harness Mode
@@ -120,21 +330,22 @@ service_accounts = client.service_account.list(account_id)
120330
for sa in service_accounts:
121331
print(f"Service Account: {sa.name}, ID: {sa.id}")
122332
```
333+
123334
For most creation, update, and delete endpoints for harness specific resources, you will need to pass through the JSON body directly.
124335

125336
Example:
126337
```python
127338
# Create a new service account
128-
sa_data = {
129-
'name': sa_name,
130-
'identifier': sa_identifier,
131-
'email': "test@harness.io",
132-
'accountIdentifier': account_id,
133-
'description': 'Service account for test',
134-
'tags': {'test': 'test tag'}
135-
}
339+
sa_data = {
340+
'name': sa_name,
341+
'identifier': sa_identifier,
342+
'email': "test@harness.io",
343+
'accountIdentifier': account_id,
344+
'description': 'Service account for test',
345+
'tags': {'test': 'test tag'}
346+
}
136347

137-
new_sa = client.service_account.create(sa_data, account_id)
348+
new_sa = client.service_account.create(sa_data, account_id)
138349
```
139350

140351
For detailed examples and API specifications for each resource, please refer to the [Harness API documentation](https://apidocs.harness.io/).
@@ -156,60 +367,15 @@ tokens = client.token.list() # account_identifier is automatically included
156367
projects = client.harness_project.list() # account_identifier is automatically included
157368
```
158369

159-
### Testing API Endpoints
160-
161-
#### Example: Creating and Managing Split Resources
162-
163-
```python
164-
# Initialize client
165-
client = get_client({
166-
'apikey': 'YOUR_SPLIT_API_KEY'
167-
})
168-
169-
# Create a workspace
170-
workspace_data = {
171-
'name': 'My New Workspace',
172-
'requiresTitleAndComments': True
173-
}
174-
workspace = client.workspaces.create(workspace_data)
175-
176-
# Create an environment in the workspace
177-
environment_data = {
178-
'name': 'Production',
179-
'production': True
180-
}
181-
environment = client.environments.create(workspace.id, environment_data)
182-
183-
# Create a traffic type
184-
traffic_type_data = {
185-
'name': 'user',
186-
'displayAttributeId': 'email'
187-
}
188-
traffic_type = client.traffic_types.create(workspace.id, traffic_type_data)
189-
190-
# Create a split
191-
split_data = {
192-
'name': 'new_feature',
193-
'description': 'A new feature flag'
194-
}
195-
split = client.splits.create(workspace.id, traffic_type.name, split_data)
196-
197-
# Add split to environment
198-
split_definition_data = {
199-
'treatment': 'on',
200-
'keys': ['user_123', 'user_456'],
201-
'rules': []
202-
}
203-
client.splits.add_to_environment(split.name, environment.id, workspace.id, split_definition_data)
204-
```
370+
## About Split
205371

206372
### Commitment to Quality:
207373

208-
Splits APIs are in active development and are constantly tested for quality. Unit tests are developed for each wrapper based on the unique needs of that language, and integration tests, load and performance tests, and behavior consistency tests are running 24/7 via automated bots. In addition, monitoring instrumentation ensures that these wrappers behave under the expected parameters of memory, CPU, and I/O.
374+
Split's APIs are in active development and are constantly tested for quality. Unit tests are developed for each wrapper based on the unique needs of that language, and integration tests, load and performance tests, and behavior consistency tests are running 24/7 via automated bots. In addition, monitoring instrumentation ensures that these wrappers behave under the expected parameters of memory, CPU, and I/O.
209375

210376
### About Split:
211377

212-
Split is the leading platform for intelligent software delivery, helping businesses of all sizes deliver exceptional user experiences, and mitigate risk, by providing an easy, secure way to target features to customers. Companies like WePay, LendingTree and thredUP rely on Split to safely launch and test new features and derive insights on their use. Founded in 2015, Splits team comes from some of the most innovative enterprises in Silicon Valley, including Google, LinkedIn, Salesforce and Splunk. Split is based in Redwood City, California and backed by Accel Partners and Lightspeed Venture Partners. To learn more about Split, contact hello@split.io, or start a 14-day free trial at www.split.io/trial.
378+
Split is the leading platform for intelligent software delivery, helping businesses of all sizes deliver exceptional user experiences, and mitigate risk, by providing an easy, secure way to target features to customers. Companies like WePay, LendingTree and thredUP rely on Split to safely launch and test new features and derive insights on their use. Founded in 2015, Split's team comes from some of the most innovative enterprises in Silicon Valley, including Google, LinkedIn, Salesforce and Splunk. Split is based in Redwood City, California and backed by Accel Partners and Lightspeed Venture Partners. To learn more about Split, contact hello@split.io, or start a 14-day free trial at www.split.io/trial.
213379

214380
**Try Split for Free:**
215381

@@ -221,4 +387,4 @@ Visit [split.io/product](https://www.split.io/product) for an overview of Split,
221387

222388
**System Status:**
223389

224-
We use a status page to monitor the availability of Splits various services. You can check the current status at [status.split.io](http://status.split.io).
390+
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).

0 commit comments

Comments
 (0)