Skip to content

Commit 59b1911

Browse files
committed
change to user group - fix
1 parent 7594715 commit 59b1911

2 files changed

Lines changed: 1 addition & 393 deletions

File tree

README.md

Lines changed: 0 additions & 392 deletions
Original file line numberDiff line numberDiff line change
@@ -1,392 +0,0 @@
1-
# Split Python API
2-
3-
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.
4-
5-
For specific instructions on how to use Split Admin REST API refer to our [official API documentation](https://docs.split.io/reference).
6-
7-
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).
8-
9-
## Using in Harness Mode
10-
11-
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. This is required for usage in environments that have been migrated to Harness and want to use the new features. Existing API keys will continue to work with the non-deprecated endpoints after migration, but new Harness Tokens will be required for Harness mode.
12-
13-
For detailed information about Harness API endpoints, please refer to the [official Harness API documentation](https://apidocs.harness.io/).
14-
15-
### Authentication in Harness Mode
16-
17-
The client supports multiple authentication scenarios:
18-
19-
1. Harness-specific endpoints always use the 'x-api-key' header format
20-
2. Split endpoints will use the 'x-api-key' header when using the harness_token
21-
3. Split endpoints will use the normal 'Authorization' header when using the apikey
22-
4. If both harness_token and apikey are provided, the client will use the harness_token for Harness endpoints and the apikey for Split endpoints
23-
24-
### Base URLs and Endpoints
25-
26-
- Existing, non-deprecated Split endpoints continue to use the Split base URLs
27-
- New Harness-specific endpoints use the Harness base URL (https://app.harness.io/)
28-
29-
### Deprecated Endpoints
30-
31-
The following Split endpoints are deprecated and cannot be used in harness mode:
32-
- `/workspaces`: POST, PATCH, DELETE, PUT verbs are deprecated
33-
- `/apiKeys`: POST verb for apiKeyType == 'admin' is deprecated
34-
- `/users`: all verbs are deprecated
35-
- `/groups`: all verbs are deprecated
36-
- `/restrictions`: all verbs are deprecated
37-
38-
Non-deprecated endpoints will continue to function as they did before the migration.
39-
40-
### Basic Usage
41-
42-
To use the client in harness mode:
43-
44-
```python
45-
from splitapiclient.main import get_client
46-
47-
# Option 1: Use harness_token for Harness endpoints and apikey for Split endpoints
48-
client = get_client({
49-
'harness_mode': True,
50-
'harness_token': 'YOUR_HARNESS_TOKEN', # Used for Harness-specific endpoints
51-
'apikey': 'YOUR_SPLIT_API_KEY', # Used for existing Split endpoints
52-
'account_identifier': 'YOUR_HARNESS_ACCOUNT_ID' # Required for Harness operations
53-
})
54-
55-
# Option 2: Use harness_token for all operations (if apikey is not provided)
56-
client = get_client({
57-
'harness_mode': True,
58-
'harness_token': 'YOUR_HARNESS_TOKEN', # Used for both Harness and Split endpoints
59-
'account_identifier': 'YOUR_HARNESS_ACCOUNT_ID'
60-
})
61-
```
62-
63-
### Working with Split Resources in Harness Mode
64-
65-
You can still access standard Split resources with some restrictions:
66-
67-
```python
68-
# List workspaces (read-only in harness mode)
69-
for ws in client.workspaces.list():
70-
print(f"Workspace: {ws.name}, Id: {ws.id}")
71-
72-
# Find a specific workspace
73-
ws = client.workspaces.find("Default")
74-
75-
# List environments in a workspace
76-
for env in client.environments.list(ws.id):
77-
print(f"Environment: {env.name}, Id: {env.id}")
78-
```
79-
80-
### Working with Harness-specific Resources
81-
82-
Harness mode provides access to several Harness-specific resources through dedicated microclients:
83-
84-
- token
85-
- harness_apikey
86-
- service_account
87-
- harness_user
88-
- harness_group
89-
- role
90-
- resource_group
91-
- role_assignment
92-
- harness_project
93-
94-
Basic example:
95-
96-
```python
97-
# Account identifier is required for all Harness operations
98-
account_id = 'YOUR_ACCOUNT_IDENTIFIER'
99-
100-
# List all tokens
101-
tokens = client.token.list(account_id)
102-
for token in tokens:
103-
print(f"Token: {token.name}, ID: {token.id}")
104-
105-
# List service accounts
106-
service_accounts = client.service_account.list(account_id)
107-
for sa in service_accounts:
108-
print(f"Service Account: {sa.name}, ID: {sa.id}")
109-
```
110-
111-
For most creation, update, and delete endpoints for harness specific resources, you will need to pass through the JSON body directly.
112-
113-
Example:
114-
```python
115-
# Create a new service account
116-
sa_data = {
117-
'name': sa_name,
118-
'identifier': sa_identifier,
119-
'email': "test@harness.io",
120-
'accountIdentifier': account_id,
121-
'description': 'Service account for test',
122-
'tags': {'test': 'test tag'}
123-
}
124-
125-
new_sa = client.service_account.create(sa_data, account_id)
126-
```
127-
128-
For detailed examples and API specifications for each resource, please refer to the [Harness API documentation](https://apidocs.harness.io/).
129-
130-
### Setting Default Account Identifier
131-
132-
To avoid specifying the account identifier with every request:
133-
134-
```python
135-
# Set default account identifier when creating the client
136-
client = get_client({
137-
'harness_mode': True,
138-
'harness_token': 'YOUR_HARNESS_TOKEN',
139-
'account_identifier': 'YOUR_ACCOUNT_IDENTIFIER'
140-
})
141-
142-
# Now you can make calls without specifying account_identifier in each request
143-
tokens = client.token.list() # account_identifier is automatically included
144-
projects = client.harness_project.list() # account_identifier is automatically included
145-
```
146-
147-
## Quick Setup
148-
149-
Install the splitapiclient:
150-
```
151-
pip install splitapiclient
152-
```
153-
154-
Import the client object and initialize connection using an Admin API Key:
155-
156-
```python
157-
from splitapiclient.main import get_client
158-
client = get_client({'apikey': 'ADMIN API KEY'})
159-
```
160-
161-
Enable optional logging:
162-
163-
```python
164-
import logging
165-
logging.basicConfig(level=logging.DEBUG)
166-
```
167-
168-
## Standard Split API Usage
169-
170-
### Workspaces
171-
172-
Fetch all workspaces:
173-
174-
```python
175-
for ws in client.workspaces.list():
176-
print("\nWorkspace:" + ws.name + ", Id: " + ws.id)
177-
```
178-
179-
Find a specific workspace:
180-
181-
```python
182-
ws = client.workspaces.find("Defaults")
183-
print("\nWorkspace:" + ws.name + ", Id: " + ws.id)
184-
```
185-
186-
### Environments
187-
188-
Fetch all Environments:
189-
190-
```python
191-
ws = client.workspaces.find("Defaults")
192-
for env in client.environments.list(ws.id):
193-
print("\nEnvironment: " + env.name + ", Id: " + env.id)
194-
```
195-
196-
Add new environment:
197-
198-
```python
199-
ws = client.workspaces.find("Defaults")
200-
env = ws.add_environment({'name': 'new_environment', 'production': False})
201-
```
202-
203-
### Splits
204-
Fetch all Splits:
205-
206-
```python
207-
ws = client.workspaces.find("Defaults")
208-
for split in client.splits.list(ws.id):
209-
print("\nSplit: " + split.name + ", " + split._workspace_id)
210-
```
211-
212-
Add new Split:
213-
214-
```python
215-
split = ws.add_split({'name': 'split_name', 'description': 'new UI feature'}, "user")
216-
print(split.name)
217-
```
218-
219-
Add tags:
220-
221-
```python
222-
split.associate_tags(['my_new_tag', 'another_new_tag'])
223-
```
224-
225-
Add Split to environment:
226-
227-
```python
228-
ws = client.workspaces.find("Defaults")
229-
split = client.splits.find("new_feature", ws.id)
230-
env = client.environments.find("Production", ws.id)
231-
tr1 = treatment.Treatment({"name":"on","configurations":""})
232-
tr2 = treatment.Treatment({"name":"off","configurations":""})
233-
bk1 = bucket.Bucket({"treatment":"on","size":50})
234-
bk2 = bucket.Bucket({"treatment":"off","size":50})
235-
match = matcher.Matcher({"attribute":"group","type":"IN_LIST_STRING","strings":["employees"]})
236-
cond = condition.Condition({'matchers':[match.export_dict()]})
237-
rl = rule.Rule({'condition':cond.export_dict(), 'buckets':[bk1.export_dict(), bk2.export_dict()]})
238-
defrl = default_rule.DefaultRule({"treatment":"off","size":100})
239-
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"}
240-
splitdef = split.add_to_environment(env.id, data)
241-
```
242-
243-
Kill Split:
244-
245-
```python
246-
ws = client.workspaces.find("Defaults")
247-
env = client.environments.find("Production", ws.id)
248-
splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
249-
splitDef.kill()
250-
```
251-
252-
Restore Split:
253-
254-
```python
255-
splitDef.restore()
256-
```
257-
258-
Fetch all Splits in an Environment:
259-
260-
```python
261-
ws = client.workspaces.find("Defaults")
262-
env = client.environments.find("Production", ws.id)
263-
for spDef in client.split_definitions.list(env.id, ws.id):
264-
print(spDef.name + str(spDef._default_rule))
265-
```
266-
267-
Submit a Change request to update a Split definition:
268-
269-
```python
270-
splitDef = client.split_definitions.find("new_feature", env.id, ws.id)
271-
definition= {"treatments":[ {"name":"on"},{"name":"off"}],
272-
"defaultTreatment":"off", "baselineTreatment": "off",
273-
"rules": [],
274-
"defaultRule":[{"treatment":"off","size":100}],"comment": "updating default rule"
275-
}
276-
splitDef.submit_change_request(definition, 'UPDATE', 'updating default rule', 'comment', ['user@email.com'], '')
277-
```
278-
279-
List all change requests:
280-
281-
```python
282-
for cr in client.change_requests.list():
283-
if cr._split is not None:
284-
print(cr._id + ", " + cr._split['name'] + ", " + cr._title + ", " + str(cr._split['environment']['id']))
285-
if cr._segment is not None:
286-
print(cr._id + ", " + cr._segment['name'] + ", " + cr._title)
287-
```
288-
289-
Approve specific change request:
290-
291-
```python
292-
for cr in client.change_requests.list():
293-
if cr._split['name'] == 'new_feature':
294-
cr.update_status("APPROVED", "done")
295-
```
296-
297-
### Users and Groups
298-
299-
Fetch all Active users:
300-
301-
```python
302-
for user in client.users.list('ACTIVE'):
303-
print(user.email + ", " + user._id)
304-
```
305-
306-
Invite new user:
307-
308-
```python
309-
group = client.groups.find('Administrators')
310-
userData = {'email': 'user@email.com', 'groups': [{'id': '', 'type': 'group'}]}
311-
userData['groups'][0]['id'] = group._id
312-
client.users.invite_user(userData)
313-
```
314-
315-
Delete a pending invite:
316-
317-
```python
318-
for user in client.users.list('PENDING'):
319-
print(user.email + ", " + user._id + ", " + user._status)
320-
if user.email == 'user@email.com':
321-
client.users.delete(user._id)
322-
```
323-
324-
Update user info:
325-
326-
```python
327-
data = {'name': 'new_name', 'email': 'user@email.com', '2fa': False, 'status': 'ACTIVE'}
328-
user = client.users.find('user@email.com')
329-
user.update_user(user._id, data)
330-
```
331-
332-
Fetch all Groups:
333-
334-
```python
335-
for group in client.groups.list():
336-
print(group._id + ", " + group._name)
337-
```
338-
339-
Create Group:
340-
341-
```python
342-
client.groups.create_group({'name': 'new_group', 'description': ''})
343-
```
344-
345-
Delete Group:
346-
347-
```python
348-
group = client.groups.find('new_group')
349-
client.groups.delete_group(group._id)
350-
```
351-
352-
Replace existing user group:
353-
354-
```python
355-
user = client.users.find('user@email.com')
356-
group = client.groups.find('Administrators')
357-
data = [{'op': 'replace', 'path': '/groups/0', 'value': {'id': '<groupId>', 'type': 'group'}}]
358-
data[0]['value']['id'] = group._id
359-
user.update_user_group(data)
360-
```
361-
362-
Add user to new group
363-
364-
```python
365-
user = client.users.find('user@email.com')
366-
group = client.groups.find('Administrators')
367-
data = [{'op': 'add', 'path': '/groups/-', 'value': {'id': '<groupId>', 'type': 'group'}}]
368-
data[0]['value']['id'] = group._id
369-
user.update_user_group(data)
370-
```
371-
372-
## About Split
373-
374-
### Commitment to Quality:
375-
376-
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.
377-
378-
### About Split:
379-
380-
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.
381-
382-
**Try Split for Free:**
383-
384-
Split is available as a 14-day free trial. To create an account, visit [split.io/trial](https://www.split.io/trial).
385-
386-
**Learn more about Split:**
387-
388-
Visit [split.io/product](https://www.split.io/product) for an overview of Split, or visit our documentation at [docs.split.io](http://docs.split.io) for more detailed information.
389-
390-
**System Status:**
391-
392-
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)