Python PyPi Library for the Admin API
Learn how to use the Python library for the Admin API.
Overview
The Python library provides full support for Split REST Admin API. It allows you to create, delete, and edit environments, feature flags, feature flag definitions, segments, segment keys, users, groups, API keys, change requests, attributes, and identities.
For more information, see the Split Admin API for more information. The library source is available on the GitHub repository.
Using in Harness Mode
Starting with version 3.5.0, the Split API client supports operating in Harness Mode to interact with both Split and Harness APIs. This allows you to work with Harness resources like tokens, service accounts, and roles using the same client.
Deprecated Endpoints in Harness Mode
The following Split endpoints are deprecated and cannot be used in Harness Mode:
/workspaces:POST,PATCH,DELETE, andPUT/apiKeys:POSTforapiKeyType == 'admin'/users: all methods/groups: all methods/restrictions: all methods
Non-deprecated endpoints will continue to function as before.
Working with Harness Resources
Harness Mode provides access to several Harness-specific resources through dedicated microclients.
tokenharness_apikeyservice_accountharness_userharness_grouproleresource_grouprole_assignmentharness_project
To work with Harness resources, initialize the Split client in Harness Mode:
Example schema for creating resources:
Each microclient supports standard methods such as list(), get(id), create(data), update(id, data), and delete(id).
To learn about specifications for the Harness APIs, see the Harness API reference documentation. For more examples of using Harness resources, see the Python API README.
Common Microclient Methods
Most Harness microclients support the following standard methods:
list(account_identifier=None): Lists all resources of the specified type.get(id, account_identifier=None): Gets a specific resource by ID.create(data, account_identifier=None): Creates a new resource.update(id, data, account_identifier=None): Updates an existing resource.delete(id, account_identifier=None): Deletes a resource.
Language support
The Python lib supports Python 3 (v3.3 or later).
Installation
Install the splitapiclient package using the following command:
Initialization and Logging
Import the client object and initializes a connection using an Admin API key:
Enable optional logging
Default Account Identifier
To avoid specifying the account_id with every call, set the default when creating the client:
Handling Rate Limit
When the library receives a 429 HTTP response because of a limit rate, it waits for five seconds and then retries the HTTP request.
Objects Reference
Workspaces (now called Projects in Split UI)
Class
Workspace
Methods
Array(Workspace) workspaces.list()
Fetches all workspaces in an account and returns an array of Workspace instances.
Parameters: None
Return: List of Workspace objects
Workspace workspaces.find(workspace_name)
Finds a workspace in a given workspace name.
Parameters: Workspace name as string
Return: Workspace instance
Workspace workspaces.add(data)
Adds a new workspace.
Parameters: Data as JSON with workspace info:
{'name': 'string', 'requiresTitleAndComments': boolean, 'type': 'workspace'}Return: Workspace instance
Workspace update(field_name, field_value)
Updates a field in existing workspace.
Parameters:
field_nameas stringfield_valueas string
Return: Workspace instance
Workspace delete()
Delete the current instance for an existing workspace and returns True if successful.
Parameters: None
Return: Boolean
RuleBasedSegment add_rule_based_segment(segment_data, traffic_type)
Adds a new rule-based segment to a workspace.
Parameters:
segment_dataas dicttraffic_typeas string
Return:
RuleBasedSegmentinstance
Segment add_segment(data, traffic_type_name)
Adds a new segment to the Workspace instance.
Parameters:
Data as JSON with segment name and description:
{'name': 'string', 'description': 'string'}traffic_type_nameas string
Return: Segment instance
Boolean delete_segment(segment_name)
Deletes an existing segment from the Workspace instance and returns True if it's successful.
Parameters:
segment_nameas stringReturn: Boolean
LargeSegment add_large_segment(data, traffic_type_name)
Adds a new large segment to the Workspace instance.
Parameters:
Data as JSON with segment name and description:
{'name': 'string', 'description': 'string'}traffic_type_nameas string
Return: Segment instance
Boolean delete_large_segment(segment_name)
Deletes an existing large segment from the Workspace instance and returns True if it's successful.
Parameters:
segment_nameas stringReturn: Boolean
Split add_split(data, traffic_type_name)
Adds a new feature flag to the Workspace instance.
Parameters:
Data as JSON with a feature flag name and production flag:
traffic_type_nameas string
Return: Split instance
Boolean delete_split(split_name)
Deletes an existing feature flag from the Workspace instance and returns True if it's successful.
Parameters:
split_nameas stringReturn: Boolean
Boolean delete_rule_based_segment(segment_name)
Deletes an existing rule-based segment from the Workspace instance and returns True if it's successful.
Parameters:
segment_nameas stringReturn: Boolean
Restrictions
Class
Restriction
Methods
Array(Restriction) restrictions.list(resourceType, resourceId)
Fetches all restrictions for a given resource type and id.
Parameters:
resource_typeas string; for example 'workspace'resource_idas string
Return: List of Restriction objects
Restriction restrictions.add(resourceType, resourceId, data)
Adds a new restriction or overwrite the existing one to a Workspace instance.
Parameters: Data as JSON:
[{'id': 'string', 'type': 'string'}]Return: Restriction instance
Environments
Class
Environment
Methods
Array(Environment) environments.list(workspaceId)
Fetches all environments in a workspace and returns an array of Environment instances.
Parameters:
workspace_idas stringReturn: List of environment objects
Environment environments.find(environment_name, workspace_id)
Finds an environment in a workspace that is given a name.
Parameters:
environment_nameas stringworkspace_idas integer
Return: Environment instance
Environment environments.add(data, workspace_id)
Adds a new environment to the Workspace instance.
Parameters:
Data as JSON with environment schema
workspace_idas string
Return: Environment instance
Boolean environments.delete(environment_id, workspace_id)
Deletes an existing environment from the Workspace instance and returns True if successful.
Parameters:
environment_idas stringworkspace_idas string
Return: Boolean
Environment update(field_name, field_value)
Updates the current environment instance given filed name with the field value, this API call allows to update any field of an environment using JsonPatch.
Parameters:
field_nameas stringfield_valueas string
Return: Environment JSON structure
Traffic Types
Class
TrafficType
Methods
Array(TrafficType) traffictypes.list(workspace_id)
Fetches all traffic types in a workspace and returns an array of TrafficType instances.
Parameters:
workspace_idas stringReturn: List of
TrafficTypeobjects
TrafficType traffictypes.find(traffic_type_name, workspace_id)
Finds a traffic type in a workspace by name.
Parameters:
traffic_type_nameas stringworkspace_idas string
Return: TrafficType object
Array(Attribute) fetch_attributes()
Fetches all attributes of the current traffic type instance.
Parameters: None
Return: List of Attribute objects
Attribute add_attribute(data)
Adds a new attribute to the current traffic type instance.
Parameters: Data as JSON;
{ "id": "string", "displayName": "string", "description": "string", "dataType": "string", "isSearchable": "boolean", "suggestedValues": ["suggested", "values"]}Return: Attribute object
Identity add_identity(data)
Adds a new identity to the current traffic type instance.
Parameters: Data as JSON;
{ key: 'string', values: { 'attribute_id': 'string', … } }Return: Identity object
Identity add_identities(data)
Adds a new identities list to current traffic type instance and returns a tuple with successful and failed items. Successful items are Identity objects. Failed items will contain the Identity object for the failed item together with a status code and a message.
Parameters: Data as JSON;
[{ key: 'string', values: { 'attribute_id': 'string', … } }]Return: Tuple
import_attributes_from_json function
Imports attributes directly from a JSON array of objects.
Parameters: Data as JSON Array. Minimum needed for each attribute is an
idproperty. Other properties can bedisplayName,description,dataType, and an array ofsuggestedValues.Return: boolean, true if successfully imported
Attributes
Class
Attribute
Methods
Array(Attributes) attributes.list(traffic_type_id, workspace_id)
Fetches all attributes in a traffic type for a workspace and returns an array of Attribute instances.
Parameters:
workspace_idas stringtraffic_type_idas string
Return: List of Attribute objects
Attribute attributes.find(attribute_id, traffic_type_name, workspace_id)
Finds an attribute in a traffic type for a workspace.
Parameters:
attribute_idas stringtraffic_type_nameas stringworkspace_idas string
Return: Attribute instance
Attribute save()
Saves the current attribute and overwrite the existing one.
Parameters: None
Return: Attribute instance
Boolean delete()
Deletes the current attribute and returns True if it's successful.
Parameters: None
Return: Boolean
Boolean attributes.delete_by_instance()
Deletes a given attribute and returns True if it's successful.
Parameters: None
Return: Boolean
Properties
traffic_type_id: Set or gettraffic_type_idfor current Attribute objectdisplay_name: Set or getdisplay_namefor current Attribute objectdescription: Set or getdescriptionfor current Attribute objectdata_type: Set or getdisplay_typefor current Attribute objectis_searchable: Set or getis_searchablefor current Attribute object
Identities
Class
Identity
Methods
Identity save()
Saves the current identity and overwrites an existing one if it exists.
Parameters: None
Return: Identity object
Array(Identity) identities.add_identities(data)
Adds a new identities list to current traffic type instance and returns a tuple with successful and failed items. Successful items are Identity objects. Failed items will contain the Identity object for the failed item together with a status code and a message.
Parameters: Data as JSON;
[{ key: 'string', values: { 'attribute_id': 'string', … } , 'environmentId': 'string', 'trafficTypeId': 'string'}, …..]Return: Tuple
Identity update()
Saves the current identity and overwrite the existing one.
Parameters: None
Return: Identity object
Boolean identities.delete(traffic_type_id, environment_id, key)
Deletes an identity object from a user key and returns True if it's successful.
Parameters:
traffic_type_id,environment_id,keyReturn: Boolean
Segments
Class
Segment
Methods
Array(Segment) segments.list(workspace_id)
Fetches all segments in a workspace and returns an array of Segment instances.
Parameters:
workspace_idas stringReturn: List of Segment objects
Segment segments.find(segment_name, workspace_id)
Finds a segment in a workspace given a name.
Parameters:
segment_nameas stringworkspace_idas integer
Return: Segment instance
SegmentDefinition add_to_environment(environment_id)
Adds a current segment object to an environment.
Parameters:
environment_idas integerReturn: SegmentDefinition object
SegmentDefinition remove_from_environment(environment_id)
Removes a current segment object to an environment and returns True if it's successful.
Parameters:
environment_idas integerReturn: Boolean
Class
SegmentDefinition
Methods
Array(SegmentDefinition) segments.list(environment_id, workspace_id)
Fetches all segment definitions in an environment and returns an array of SegmentDefinition instances.
Parameters:
environment_idas integerworkspace_idas integer
Return: List of SegmentDefinition objects
SegmentDefinition segment_definitions.find(segment_name, environment_id, workspace_id)
Finds a segment in an environment.
Parameters:
segment_nameas stringenvironment_idas integerworkspace_idas integer
Return: SegmentDefinition instance
int get_key_count()
Fetches key count of current segment definition object.
Parameters: None
Return: integer
Array(string) get_keys()
Fetches all keys of current segment definition object.
Parameters: None
Return: Array of string
Boolean export_keys_to_csv(csv_file_name)
Exports all segment keys in a current segment definition object to a csv file and returns True if it's successful.
Parameters:
csv_file_nameas stringReturn: Boolean
Boolean import_keys_from_json(replace_keys, json_data)
Imports keys into the current segment definition object from JSON object, with an option to replace all existing keys and returns True if it's successful.
Parameters:
replace_keysas booleanjson_dataas JSON{'keys':['key1, 'key2', 'key3'], 'comment':'a comment'}
Return: Boolean
Boolean remove_keys( json_data)
Removes keys from the current segment definition object stored in JSON object and returns True if it's successful.
Parameters:
json_dataas JSON{'keys':['key1, 'key2', 'key3'], 'comment':'a comment'}Return: Boolean
ChangeRequest submit_change_request(definition, operation_type, title, comment, approvers, rollout_status_id)
Submits adding keys request change for current segment definition object.
Parameters: Definition as JSON;
operation_typeas stringtitleas stringcommentas stringapproversas string array
Return: ChangeRequest object
Splits (now called Feature Flags in Split UI)
Class
Split
Methods
Array(Split) splits.list(workspace_id, tags)
Fetches all feature flags in a workspace and returns an array of Split instances, will also filter by given tags in array of strings.
Parameters:
workspace_idas integertagsas array(string) Optional.
Return: List of split objects
Split splits.find(split_name, workspace_id, tags)
Finds a feature flag in a workspace given a name.
Parameters:
split_nameas stringworkspace_idas integertagsas string (Optional)
Return: Split instance
SplitDefinition add_to_environment(environment_id, json_data)
Adds current Split object to an environment.
Parameters:
environment_idas integerjson_dataas JSON; split definition structure:
Return: SplitDefinition object
Boolean remove_from_environment(environment_id, title, comment)
Removes a current split object to an environment and returns True if it's successful.
Parameters:
environment_id,title(optional),comment(optional)Return: Boolean
Boolean associate_tags(tags)
Associates tags on current split object and overwrites existing ones, and returns True if it's successful.
Parameters:
tagsas string arrayReturn: Boolean
Class
SplitDefinition
Methods
Array(SplitDefinition) split_definitions.list(environment_id, workspace_id)
Fetches all feature flag definitions in an environment and returns an array of SplitDefinition instances.
Parameters:
environment_idas integerworkspace_idas integer
Return: List of SplitDefinition objects
SplitDefinition split_definitions.find(split_name, environment_id, workspace_id)
Finds a feature flag in an environment.
Parameters:
split_nameas stringenvironment_idas integerworkspace_idas integer
Return: SplitDefinition instance
SplitDefinition split_definitions.get_definition(split_name, environment_id, workspace_id)
Get a single split definition directly.
Parameters:
split_nameas stringenvironment_idas integerworkspace_idas integer
Return: SplitDefinition instance
SplitDefinition update_definition(data)
Updates the full feature flag definition for the current SplitDefinition object.
Parameters: Data as JSON; Split Definition structure
Return: SplitDefinition instance
Boolean kill()
Kills a current split object, and returns True if it's successful.
Parameters: None
Return: Boolean
Boolean restore()
Restores a current split object and returns True if it's successful.
Parameters: None
Return: Boolean
ChangeRequest submit_change_request(definition, operation_type, title, comment, approvers, rollout_status_id)
Submits a definition request change for current split definition object.
Parameters: Definition as JSON;
operation_typeas stringtitleas stringcommentas stringapproversas string arrayrollout_status_idas string, optional, use None if not specified.
Return: ChangeRequest object
Class
Bucket
Methods
JSON export_dict()
Exports the current class structure as JSON.
Parameters: None
Return: JSON structure
Class
Condition
Methods
JSON export_dict()
Exports the current class structure as JSON.
Parameters: None
Return: JSON structure
Class
DefaultRule
Methods
JSON export_dict()
Exports the current class structure as JSON.
Parameters: None
Return: JSON structure
Class
Matcher
Methods
JSON export_dict()
Exports the current class structure as JSON.
Parameters: None
Return: JSON structure
Class
Rule
Methods
JSON export_dict()
Exports the current class structure as JSON.
Parameters: None
Return: JSON structure
Class
Treatment
Methods
JSON export_dict()
Exports the current class structure as JSON.
Parameters: None
Return: JSON structure
Change Requests
Class
ChangeRequest
Methods
Array(ChangeRequest) change_requests.list()
Fetches all change requests and returns array of ChangeRequest instances.
Parameters: None
Return: List of ChangeRequest objects
Array(ChangeRequest) change_requests.find(split_name, segment_name, environment_id)
Finds a change request in an environment.
Parameters:
split_nameas stringsegment_nameas stringenvironment_idas string
Return: Array of ChangeRequest instances
ChangeRequest update_status(new_status, comment)
Updates a status of the current change request instance.
Parameters:
new_statusas stringcommentas string
Return: ChangeRequest object
Users
Class
User
Methods
Array(User) users.list(status)
Fetches all users in the current org for specific status and returns array of User instances.
Parameters:
statusas stringReturn: List of User objects
User users.find(email)
Finds user in a workspace given email and returns User instances.
Parameters:
emailas stringReturn: User object
User update_user(data)
Updates the current user object data.
Parameters: Data as JSON;
{'name':'string', 'email':'string', '2fa':Boolean, 'status':'string'}Return: User object
User update_user_group(data)
Updates the current user object group.
Parameters: Data as JSON;
[{'op': 'replace', 'path': '/groups/0', 'value': {'id': 'groupId', 'type':'group'}}]Return: User object
User invite_user(data)
Sends an invite to an email and returns True if it's successful.
Parameters: Data as JSON;
{'email':'chillaq@gmail.com', "groups":[{"id":"group_id", "type":"group"}]}Return: Boolean
User delete(user_id)
Deletes an existing user and returns True if it's successful.
Parameters:
user_idas stringReturn: Boolean
Groups
Class
Group
Methods
Array(Group) groups.list()
Fetches all groups in current org and returns an array of Group instances.
Parameters: None
Return: List of Group objects
Group groups.find(group_name)
Finds a user in a workspace given email and returns User instances.
Parameters:
emailas stringReturn: User object
Group groups.create_group(data)
Creates a new group in the org and returns a group instance.
Parameters: Data as JSON;
{'name':'string', 'description':'string'}Return: User object
Group groups.update_group(group_id, data)
Updates an existing group in the org and returns group instance.
Parameters: Data as JSON;
{'name':'string', 'description':'string'}Return: Group object
Boolean groups.delete_group(group_id)
Deletes an existing group in the org and returns True if it's successful.
Parameters:
group_idas stringReturn: Boolean
API Keys
Class
APIKey
Methods
APIKey apikeys.create_apikey(api_key_name, api_key_type, environment_id, workspace_id)
Creates a new API key in the org and returns an APIKey instance.
Parameters:
api_key_nameas stringapi_key_typeas stringenvironment_idas stringworkspace_idas stringlist of scopes (optional)
Return: APIKey object
Boolean apikeys.delete_apikey(apikey_id)
Deletes an API key and returns True if it's successful.
Parameters:
apikey_idas stringReturn: Boolean
Flag Sets
Class
FlagSet
Methods
[FlagSet] flag_sets.list(workspace_id)
Returns a list of flag sets.
Parameters:
workspace_idas string
Return: [FlagSet object]
FlagSet flag_sets.find(name, workspace_id)
Find a flag set in a workspace by name.
Parameters:
nameas stringworkspace_idas string
Return: FlagSet object
FlagSet flag_sets.add(flag_set,workspace_id)
Add a flag set in a workspace.
Parameters:
workspace_idas stringflag_setasflag_setobject
Return: FlagSet object
Bool flag_sets.delete(id)
Delete a flag set by ID.
Parameters:
flag_setID as stringReturn: boolean
Large Segments
Class
Large Segment
Methods
Array(LargeSegment) large_segments.list(workspace_id)
Fetches all segments in a workspace and returns an array of Segment instances.
Parameters:
workspace_idas stringReturn: List of Segment objects
LargeSegment large_segments.find(segment_name, workspace_id)
Finds a segment in a workspace given a name.
Parameters:
segment_nameas stringworkspace_idas integer
Return: Segment instance
LargeSegmentDefinition add_to_environment(environment_id)
Adds a current segment object to an environment.
Parameters:
environment_idas integerReturn: LargeSegmentDefinition object
LargeSegmentDefinition remove_from_environment(environment_id)
Removes a current large segment object to an environment and returns True if it's successful.
Parameters:
environment_idas integerReturn: Boolean
Class
LargeSegmentDefinition
Methods
Array(LargeSegmentDefinition) large_segments.list(environment_id, workspace_id)
Fetches all large segment definitions in an environment and returns an array of LargeSegmentDefinition instances.
Parameters:
environment_idas integerworkspace_idas integer
Return: List of LargeSegmentDefinition objects
LargeSegmentDefinition large_segment_definitions.find(segment_name, environment_id, workspace_id)
Finds a large segment in an environment.
Parameters:
segment_nameas stringenvironment_idas integerworkspace_idas integer
Return: LargeSegmentDefinition instance
LargeSegmentDefinition submit_upload(title, comment, approvers, file_path)
Imports keys into the current segment definition from the CSV file.
Parameters:
titleas stringcommentas stringapproversas [string]file_pathas string to a single column, no header CSV with segment key values
Return: Boolean
Boolean remove_all_members( title, comment, approvers)
Removes all keys from the large segment.
Parameters:
titleas stringcommentas stringapproversas [string]
Return: Boolean
Rule-based Segments
Rule-based segments allow you to define audience segments using complex rule structures and exclusion logic.
Class
RuleBasedSegment
Methods
rule_based_segments.list(workspace_id)
Parameters:
workspace_idas stringReturn: List of
RuleBasedSegmentobjects
rule_based_segments.find(segment_name, workspace_id)
Finds a specific rule-based segment by name.
Parameters:
segment_nameas stringworkspace_idas string
Return:
RuleBasedSegmentinstance
Class
RuleBasedSegmentDefinition
The segment definition is used when adding, updating, or making change requests to rule-based segments in specific environments.
Methods
rule_based_segment_definitions.add_to_environment(environment_id)
Adds a rule-based segment to an environment.
Parameters:
environment_idas stringReturn:
RuleBasedSegmentDefinitioninstance
rule_based_segment_definitions.find(segment_name, environment_id, workspace_id)
Finds a rule-based segment definition in an environment.
Parameters:
segment_nameas stringenvironment_idas stringworkspace_idas string
Return:
RuleBasedSegmentDefinitioninstance
rule_based_segment_definitions.update(data)
Updates the rule-based segment definition with rules or exclusions.
Parameters:
dataas dictReturn: Updated
RuleBasedSegmentDefinitioninstance
rule_based_segment_definitions.submit_change_request(...)
Submits a change request to update a rule-based segment definition.
Parameters:
rulesas list of dictsexcluded_keysas list of stringsexcluded_segmentsas list of dictsoperation_typeas stringtitleas stringcommentas stringapproversas list of stringsworkspace_idas string
Return:Boolean
change_requests.list()
List all change requests.
Return: List of
ChangeRequestobjects
change_requests.update_status(status, comment)
Approve or reject a change request.
Parameters:
statusas string (APPROVED or REJECTED)commentas string
Return: Boolean
For more information about rule-based segments, see the README.
Last updated
Was this helpful?