For the complete documentation index, see llms.txt. This page is also available as Markdown.

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, and PUT

  • /apiKeys: POST for apiKeyType == '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.

  • token

  • harness_apikey

  • service_account

  • harness_user

  • harness_group

  • role

  • resource_group

  • role_assignment

  • harness_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.

The account_identifier parameter can be omitted if it was set during client initialization.

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_name as string

    • field_value as 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_data as dict

    • traffic_type as string

  • Return: RuleBasedSegment instance

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_name as 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_name as string

  • Return: 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_name as 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_name as string

  • Return: 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_name as 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_name as string

  • Return: 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_name as string

  • Return: Boolean

Restrictions

Class

Restriction

Methods

Array(Restriction) restrictions.list(resourceType, resourceId)

Fetches all restrictions for a given resource type and id.

  • Parameters:

    • resource_type as string; for example 'workspace'

    • resource_id as 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_id as string

  • Return: List of environment objects

Environment environments.find(environment_name, workspace_id)

Finds an environment in a workspace that is given a name.

  • Parameters:

    • environment_name as string

    • workspace_id as 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_id as 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_id as string

    • workspace_id as 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_name as string

    • field_value as 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_id as string

  • Return: List of TrafficType objects

TrafficType traffictypes.find(traffic_type_name, workspace_id)

Finds a traffic type in a workspace by name.

  • Parameters:

    • traffic_type_name as string

    • workspace_id as 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 be displayName, description, dataType, and an array of suggestedValues.

  • 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_id as string

    • traffic_type_id as 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_id as string

    • traffic_type_name as string

    • workspace_id as 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 get traffic_type_id for current Attribute object

  • display_name: Set or get display_name for current Attribute object

  • description: Set or get description for current Attribute object

  • data_type: Set or get display_type for current Attribute object

  • is_searchable: Set or get is_searchable for 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, key

  • Return: 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_id as string

  • Return: List of Segment objects

Segment segments.find(segment_name, workspace_id)

Finds a segment in a workspace given a name.

  • Parameters:

    • segment_name as string

    • workspace_id as integer

  • Return: Segment instance

SegmentDefinition add_to_environment(environment_id)

Adds a current segment object to an environment.

  • Parameters: environment_id as integer

  • Return: 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_id as integer

  • Return: 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_id as integer

    • workspace_id as integer

  • Return: List of SegmentDefinition objects

SegmentDefinition segment_definitions.find(segment_name, environment_id, workspace_id)

Finds a segment in an environment.

  • Parameters:

    • segment_name as string

    • environment_id as integer

    • workspace_id as 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_name as string

  • Return: 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_keys as boolean

    • json_data as 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_data as 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_type as string

    • title as string

    • comment as string

    • approvers as string array

  • Return: ChangeRequest object

Splits (now called Feature Flags in Split UI)

Class

Split

Only getSplit and createSplit return the owners property.

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_id as integer

    • tags as 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_name as string

    • workspace_id as integer

    • tags as string (Optional)

  • Return: Split instance

SplitDefinition add_to_environment(environment_id, json_data)

Adds current Split object to an environment.

  • Parameters:

    • environment_id as integer

    • json_data as 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: tags as string array

  • Return: 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_id as integer

    • workspace_id as 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_name as string

    • environment_id as integer

    • workspace_id as integer

  • Return: SplitDefinition instance

SplitDefinition split_definitions.get_definition(split_name, environment_id, workspace_id)

Get a single split definition directly.

  • Parameters:

    • split_name as string

    • environment_id as integer

    • workspace_id as 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_type as string

    • title as string

    • comment as string

    • approvers as string array

    • rollout_status_id as 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_name as string

    • segment_name as string

    • environment_id as string

  • Return: Array of ChangeRequest instances

ChangeRequest update_status(new_status, comment)

Updates a status of the current change request instance.

  • Parameters:

    • new_status as string

    • comment as 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: status as string

  • Return: List of User objects

User users.find(email)

Finds user in a workspace given email and returns User instances.

  • Parameters: email as string

  • Return: 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_id as string

  • Return: 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: email as string

  • Return: 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_id as string

  • Return: 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_name as string

    • api_key_type as string

    • environment_id as string

    • workspace_id as string

    • list 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_id as string

  • Return: Boolean

Flag Sets

Class

FlagSet

Methods

[FlagSet] flag_sets.list(workspace_id)

Returns a list of flag sets.

  • Parameters:

    • workspace_id as string

  • Return: [FlagSet object]

FlagSet flag_sets.find(name, workspace_id)

Find a flag set in a workspace by name.

  • Parameters:

    • name as string

    • workspace_id as string

  • Return: FlagSet object

FlagSet flag_sets.add(flag_set,workspace_id)

Add a flag set in a workspace.

  • Parameters:

    • workspace_id as string

    • flag_set as flag_set object

  • Return: FlagSet object

Bool flag_sets.delete(id)

Delete a flag set by ID.

  • Parameters: flag_set ID as string

  • Return: 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_id as string

  • Return: List of Segment objects

LargeSegment large_segments.find(segment_name, workspace_id)

Finds a segment in a workspace given a name.

  • Parameters:

    • segment_name as string

    • workspace_id as integer

  • Return: Segment instance

LargeSegmentDefinition add_to_environment(environment_id)

Adds a current segment object to an environment.

  • Parameters: environment_id as integer

  • Return: 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_id as integer

  • Return: 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_id as integer

    • workspace_id as 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_name as string

    • environment_id as integer

    • workspace_id as integer

  • Return: LargeSegmentDefinition instance

LargeSegmentDefinition submit_upload(title, comment, approvers, file_path)

Imports keys into the current segment definition from the CSV file.

This creates a change request and may not be fully automatable in environments with additional change requests and approvers.

  • Parameters:

    • title as string

    • comment as string

    • approvers as [string]

    • file_path as 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.

This creates a change request and may not be fully automatable in environments with additional change requests and approvers.

  • Parameters:

    • title as string

    • comment as string

    • approvers as [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_id as string

  • Return: List of RuleBasedSegment objects

rule_based_segments.find(segment_name, workspace_id)

Finds a specific rule-based segment by name.

  • Parameters:

    • segment_name as string

    • workspace_id as string

  • Return: RuleBasedSegment instance

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_id as string

  • Return: RuleBasedSegmentDefinition instance

rule_based_segment_definitions.find(segment_name, environment_id, workspace_id)

Finds a rule-based segment definition in an environment.

  • Parameters:

    • segment_name as string

    • environment_id as string

    • workspace_id as string

  • Return: RuleBasedSegmentDefinition instance

rule_based_segment_definitions.update(data)

Updates the rule-based segment definition with rules or exclusions.

  • Parameters: data as dict

  • Return: Updated RuleBasedSegmentDefinition instance

rule_based_segment_definitions.submit_change_request(...)

Submits a change request to update a rule-based segment definition.

  • Parameters:

    • rules as list of dicts

    • excluded_keys as list of strings

    • excluded_segments as list of dicts

    • operation_type as string

    • title as string

    • comment as string

    • approvers as list of strings

    • workspace_id as string

  • Return:Boolean

change_requests.list()

List all change requests.

  • Return: List of ChangeRequest objects

change_requests.update_status(status, comment)

Approve or reject a change request.

  • Parameters:

    • status as string (APPROVED or REJECTED)

    • comment as string

  • Return: Boolean

For more information about rule-based segments, see the README.

Last updated

Was this helpful?