### Harness Mode Client Initialization Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Example of how to initialize the client for Harness mode with authentication details. ```python client = get_client({ 'harness_mode': True, 'harness_token': 'YOUR_HARNESS_TOKEN', 'account_identifier': 'YOUR_ACCOUNT_ID' }) ``` -------------------------------- ### Install the splitapiclient Source: https://github.com/splitio/python-api/blob/master/README.md Command to install the splitapiclient library using pip. ```bash pip install splitapiclient ``` -------------------------------- ### Harness Mode Client Initialization Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Example of how to initialize the client with harness mode enabled, including token and account identifier. ```python client = get_client({ 'harness_mode': True, 'harness_token': 'YOUR_TOKEN', 'account_identifier': 'YOUR_ACCOUNT' }) ``` -------------------------------- ### Working with Harness-specific Resources - List Tokens Source: https://github.com/splitio/python-api/blob/master/README.md Example of listing all tokens for a given account identifier in Harness mode. ```python # Account identifier is required for all Harness operations account_id = 'YOUR_ACCOUNT_IDENTIFIER' # List all tokens (org_identifier and project_identifier are optional) tokens = client.token.list(account_id) for token in tokens: print(f"Token: {token.name}, ID: {token.id}") ``` -------------------------------- ### Basic harness mode setup Source: https://github.com/splitio/python-api/blob/master/README.md Initializes the Split API client in harness mode using a Harness API key and account identifier. ```python from splitapiclient.main import get_client # Basic harness mode setup with required harness_token client = get_client({ 'harness_mode': True, 'harness_token': 'YOUR_HARNESS_TOKEN', # Required: Harness API key 'account_identifier': 'YOUR_HARNESS_ACCOUNT_ID' # Required for Harness operations }) ``` -------------------------------- ### Harness mode setup with org and project identifiers set at client initialization Source: https://github.com/splitio/python-api/blob/master/README.md Demonstrates initializing the client with organization and project identifiers already set, simplifying subsequent calls. ```python # If org_identifier and project_identifier are set at client initialization, you can omit them client = get_client({ 'harness_mode': True, 'harness_token': 'YOUR_HARNESS_TOKEN', 'account_identifier': account_id, 'org_identifier': org_id, 'project_identifier': project_id }) ``` -------------------------------- ### Create a new service account Source: https://github.com/splitio/python-api/blob/master/README.md Example of creating a new service account by passing a JSON body with account details. ```python # Create a new service account sa_data = { 'name': sa_name, 'identifier': sa_identifier, 'email': "test@harness.io", 'accountIdentifier': account_id, 'description': 'Service account for test', 'tags': {'test': 'test tag'} } new_sa = client.service_account.create(sa_data, account_id) ``` -------------------------------- ### Working with Harness-specific Resources - List Service Accounts Source: https://github.com/splitio/python-api/blob/master/README.md Example of listing service accounts with optional organization and project identifiers. ```python # List service accounts with org and project identifiers org_id = 'YOUR_ORG_IDENTIFIER' project_id = 'YOUR_PROJECT_IDENTIFIER' service_accounts = client.service_account.list(account_id, org_identifier=org_id, project_identifier=project_id) for sa in service_accounts: print(f"Service Account: {sa.name}, ID: {sa.id}") ``` -------------------------------- ### Rule-Based Segment Structure - Matcher Examples Source: https://github.com/splitio/python-api/blob/master/README.md Provides examples of different matcher types used in rule-based segment definitions, including string, numeric, boolean, date/time, and split dependency matching. ```python # Examples of different matcher types matchers = [ # String matching { 'type': 'IN_LIST_STRING', 'attribute': 'device', 'strings': ['mobile', 'tablet'] }, # Numeric comparisons { 'type': 'GREATER_THAN_OR_EQUAL_NUMBER', 'attribute': 'age', 'number': 21 }, { 'type': 'LESS_THAN_OR_EQUAL_NUMBER', 'attribute': 'account_age_days', 'number': 30 }, { 'type': 'BETWEEN_NUMBER', 'attribute': 'purchases', 'between': {'from': 5, 'to': 20} }, # Boolean conditions { 'type': 'BOOLEAN', 'attribute': 'subscribed', 'bool': True }, # Date/time matching { 'type': 'ON_DATE', 'attribute': 'sign_up_date', 'date': 1623456789000 # timestamp in milliseconds }, # Dependency on another split { 'type': 'IN_SPLIT', 'attribute': '', 'depends': {'splitName': 'another_split', 'treatment': 'on'} } ] ``` -------------------------------- ### Harness mode setup with optional organization and project identifiers Source: https://github.com/splitio/python-api/blob/master/README.md Initializes the Split API client in harness mode, including optional organization and project identifiers. ```python # Include optional org_identifier and project_identifier client = get_client({ 'harness_mode': True, 'harness_token': 'YOUR_HARNESS_TOKEN', 'account_identifier': 'YOUR_HARNESS_ACCOUNT_ID', 'org_identifier': 'YOUR_ORG_ID', # Optional: organization identifier 'project_identifier': 'YOUR_PROJECT_ID' # Optional: project identifier }) ``` -------------------------------- ### Get definition method for SplitDefinition Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Enables retrieving individual flag definition details. ```python get_definition() ``` -------------------------------- ### Add a user to a group Source: https://github.com/splitio/python-api/blob/master/README.md Example of adding a user to specified groups within an account. ```python # Add a user to a group client.harness_user.add_user_to_groups(user.id, [group.id], account_id) ``` -------------------------------- ### Working with Split Resources in Harness Mode Source: https://github.com/splitio/python-api/blob/master/README.md Examples of accessing standard Split resources like workspaces and environments in harness mode. ```python # List workspaces (read-only in harness mode) for ws in client.workspaces.list(): print(f"Workspace: {ws.name}, Id: {ws.id}") # Find a specific workspace ws = client.workspaces.find("Default") # List environments in a workspace for env in client.environments.list(ws.id): print(f"Environment: {env.name}, Id: {env.id}") ``` -------------------------------- ### Import the client object and initialize connection Source: https://github.com/splitio/python-api/blob/master/README.md Initializes the Split API client using an Admin API Key. ```python from splitapiclient.main import get_client client = get_client({'apikey': 'ADMIN API KEY'}) ``` -------------------------------- ### List all flag sets Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Method to list all flag sets. ```python client.flag_sets.list() ``` -------------------------------- ### Create new flag sets Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Method to create new flag sets. ```python client.flag_sets.create() ``` -------------------------------- ### Fetch all Environments Source: https://github.com/splitio/python-api/blob/master/README.md Lists all environments within a specific workspace and prints their names and IDs. ```python ws = client.workspaces.find("Defaults") for env in client.environments.list(ws.id): print("\nEnvironment: " + env.name + ", Id: " + env.id) ``` -------------------------------- ### Fetch all workspaces Source: https://github.com/splitio/python-api/blob/master/README.md Iterates through and prints the name and ID of all available workspaces. ```python for ws in client.workspaces.list(): print("\nWorkspace:" + ws.name + ", Id: " + ws.id) ``` -------------------------------- ### Set default identifiers when creating the client Source: https://github.com/splitio/python-api/blob/master/README.md Initializes the client with default account, organization, and project identifiers to simplify subsequent requests. ```python # Set default identifiers when creating the client client = get_client({ 'harness_mode': True, 'harness_token': 'YOUR_HARNESS_TOKEN', 'account_identifier': 'YOUR_ACCOUNT_IDENTIFIER', # Required 'org_identifier': 'YOUR_ORG_IDENTIFIER', # Optional 'project_identifier': 'YOUR_PROJECT_IDENTIFIER' # Optional }) # Now you can make calls without specifying identifiers in each request tokens = client.token.list() # account_identifier is automatically included projects = client.harness_project.list() # account_identifier and org_identifier are automatically included (project_identifier is not used for projects endpoint) ``` -------------------------------- ### Create Group Source: https://github.com/splitio/python-api/blob/master/README.md Creates a new group with a specified name and description. ```python client.groups.create_group({'name': 'new_group', 'description': ''}) ``` -------------------------------- ### Manage restrictions Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Methods to manage restrictions. ```python client.restrictions.* ``` -------------------------------- ### Fetch all Rule-Based Segments Source: https://github.com/splitio/python-api/blob/master/README.md Retrieves and prints the names and descriptions of all rule-based segments. ```python ws = client.workspaces.find("Defaults") for segment in client.rule_based_segments.list(ws.id): print("\nRule-Based Segment: " + segment.name + ", " + segment.description) ``` -------------------------------- ### Add new Split Source: https://github.com/splitio/python-api/blob/master/README.md Creates and prints the name of a new split with a description. ```python split = ws.add_split({'name': 'split_name', 'description': 'new UI feature'}, "user") print(split.name) ``` -------------------------------- ### Calling methods without specifying identifiers Source: https://github.com/splitio/python-api/blob/master/README.md Demonstrates how to call list methods for service accounts and projects, which use default identifiers. ```python # Uses default identifiers service_accounts = client.service_account.list() projects = client.harness_project.list() ``` -------------------------------- ### Fetch all Splits in an Environment Source: https://github.com/splitio/python-api/blob/master/README.md Retrieves and prints the names and default rules of all split definitions within a specific environment. ```python ws = client.workspaces.find("Defaults") env = client.environments.find("Production", ws.id) for spDef in client.split_definitions.list(env.id, ws.id): print(spDef.name + str(spDef._default_rule)) ``` -------------------------------- ### Enable optional logging Source: https://github.com/splitio/python-api/blob/master/README.md Configures basic logging to display DEBUG level messages. ```python import logging logging.basicConfig(level=logging.DEBUG) ``` -------------------------------- ### Invite new user Source: https://github.com/splitio/python-api/blob/master/README.md Invites a new user to a specified group. ```python group = client.groups.find('Administrators') userData = {'email': 'user@email.com', 'groups': [{'id': '', 'type': 'group'}]} userData['groups'][0]['id'] = group._id client.users.invite_user(userData) ``` -------------------------------- ### Delete environments Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Method to delete environments. ```python environment.delete() ``` -------------------------------- ### Fetch all Groups Source: https://github.com/splitio/python-api/blob/master/README.md Retrieves and prints the ID and name of all groups. ```python for group in client.groups.list(): print(group._id + ", " + group._name) ``` -------------------------------- ### Fetch all Splits Source: https://github.com/splitio/python-api/blob/master/README.md Retrieves and prints the names and workspace IDs of all splits. ```python ws = client.workspaces.find("Defaults") for split in client.splits.list(ws.id): print("\nSplit: " + split.name + ", " + split._workspace_id) ``` -------------------------------- ### Add new environment Source: https://github.com/splitio/python-api/blob/master/README.md Creates and adds a new environment to a specified workspace with given properties. ```python ws = client.workspaces.find("Defaults") env = ws.add_environment({'name': 'new_environment', 'production': False}) ``` -------------------------------- ### List groups with filterType and other optional parameters Source: https://github.com/splitio/python-api/blob/master/README.md Demonstrates listing groups with specific account, organization, project identifiers, and a filter type. ```python # List groups with filterType and other optional parameters groups = client.harness_group.list( account_identifier='YOUR_ACCOUNT_ID', org_identifier='YOUR_ORG_ID', project_identifier='YOUR_PROJECT_ID', filterType='INCLUDE_INHERITED_GROUPS' ) ``` -------------------------------- ### Fetch all Active users Source: https://github.com/splitio/python-api/blob/master/README.md Retrieves and prints the email and ID of all active users. ```python for user in client.users.list('ACTIVE'): print(user.email + ", " + user._id) ``` -------------------------------- ### Update environment fields Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Method to update environment fields. ```python environment.update() ``` -------------------------------- ### Update workspace properties Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Method to update workspace properties. ```python workspace.update() ``` -------------------------------- ### Add new Rule-Based Segment Source: https://github.com/splitio/python-api/blob/master/README.md Creates and prints the name of a new rule-based segment with a description. ```python segment_data = { 'name': 'advanced_users', 'description': 'Users who match advanced criteria' } rule_segment = ws.add_rule_based_segment(segment_data, "user") print(rule_segment.name) ``` -------------------------------- ### List large segments Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Method to list large segments. ```python client.large_segments.list() ``` -------------------------------- ### List all groups (default behavior) Source: https://github.com/splitio/python-api/blob/master/README.md Lists all groups without any specific filtering. ```python # List all groups (default behavior) all_groups = client.harness_group.list() ``` -------------------------------- ### List large segment definitions Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Method to list large segment definitions. ```python client.large_segment_definitions.list() ``` -------------------------------- ### Add user to new group Source: https://github.com/splitio/python-api/blob/master/README.md Adds a user to a new group. ```python user = client.users.find('user@email.com') group = client.groups.find('Administrators') data = [{'op': 'add', 'path': '/groups/-', 'value': {'id': '', 'type': 'group'}}] data[0]['value']['id'] = group._id user.update_user_group(data) ``` -------------------------------- ### Delete workspaces Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Method to delete workspaces. ```python workspace.delete() ``` -------------------------------- ### Import attributes from JSON Source: https://github.com/splitio/python-api/blob/master/CHANGES.txt Enables bulk attribute import from JSON data. ```python import_attributes_from_json() ``` -------------------------------- ### Restore Split Source: https://github.com/splitio/python-api/blob/master/README.md Restores a previously killed split definition. ```python splitDef.restore() ``` -------------------------------- ### Add Rule-Based Segment to environment Source: https://github.com/splitio/python-api/blob/master/README.md Adds a rule-based segment to a specific environment. ```python ws = client.workspaces.find("Defaults") segment = client.rule_based_segments.find("advanced_users", ws.id) env = client.environments.find("Production", ws.id) segdef = segment.add_to_environment(env.id) ``` -------------------------------- ### List all change requests Source: https://github.com/splitio/python-api/blob/master/README.md This snippet iterates through all change requests and prints details if they are associated with a split or a segment. ```python for cr in client.change_requests.list(): if cr._split is not None: print(cr._id + ", " + cr._split['name'] + ", " + cr._title + ", " + str(cr._split['environment']['id'])) if cr._segment is not None: print(cr._id + ", " + cr._segment['name'] + ", " + cr._title) ``` -------------------------------- ### Find a specific workspace Source: https://github.com/splitio/python-api/blob/master/README.md Retrieves and prints the name and ID of a workspace identified by its name. ```python ws = client.workspaces.find("Defaults") print("\nWorkspace:" + ws.name + ", Id: " + ws.id) ``` -------------------------------- ### Add Split to environment Source: https://github.com/splitio/python-api/blob/master/README.md Adds a split definition to a specific environment, including treatments, rules, and default settings. ```python ws = client.workspaces.find("Defaults") split = client.splits.find("new_feature", ws.id) env = client.environments.find("Production", ws.id) tr1 = treatment.Treatment({"name":"on","configurations":""}) tr2 = treatment.Treatment({"name":"off","configurations":""}) bk1 = bucket.Bucket({"treatment":"on","size":50}) bk2 = bucket.Bucket({"treatment":"off","size":50}) match = matcher.Matcher({"attribute":"group","type":"IN_LIST_STRING","strings":["employees"]}) cond = condition.Condition({'matchers':[match.export_dict()]}) rl = rule.Rule({'condition':cond.export_dict(), 'buckets':[bk1.export_dict(), bk2.export_dict()]}) defrl = default_rule.DefaultRule({"treatment":"off","size":100}) 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"} splitdef = split.add_to_environment(env.id, data) ``` -------------------------------- ### Add tags Source: https://github.com/splitio/python-api/blob/master/README.md Associates new tags with an existing split. ```python split.associate_tags(['my_new_tag', 'another_new_tag']) ``` -------------------------------- ### Update user info Source: https://github.com/splitio/python-api/blob/master/README.md Updates the information for a given user. ```python data = {'name': 'new_name', 'email': 'user@email.com', '2fa': False, 'status': 'ACTIVE'} user = client.users.find('user@email.com') user.update_user(user._id, data) ``` -------------------------------- ### Use default identifiers but override only org_identifier Source: https://github.com/splitio/python-api/blob/master/README.md Demonstrates overriding only the organization identifier while using default account identifier for a specific request. ```python # Use default identifiers but override only org_identifier # Note: project_identifier is not used for harness_project endpoints projects = client.harness_project.list(org_identifier='DIFFERENT_ORG_ID') ``` -------------------------------- ### Kill Split Source: https://github.com/splitio/python-api/blob/master/README.md Kills a specific split definition within an environment. ```python ws = client.workspaces.find("Defaults") env = client.environments.find("Production", ws.id) splitDef = client.split_definitions.find("new_feature", env.id, ws.id) splitDef.kill() ``` -------------------------------- ### Approve specific change request Source: https://github.com/splitio/python-api/blob/master/README.md This snippet demonstrates how to approve a specific change request by filtering for a change request related to a split named 'new_feature' and then updating its status. ```python for cr in client.change_requests.list(): if cr._split['name'] == 'new_feature': cr.update_status("APPROVED", "done") ``` -------------------------------- ### Replace existing user group Source: https://github.com/splitio/python-api/blob/master/README.md Replaces a user's existing group membership. ```python user = client.users.find('user@email.com') group = client.groups.find('Administrators') data = [{'op': 'replace', 'path': '/groups/0', 'value': {'id': '', 'type': 'group'}}] data[0]['value']['id'] = group._id user.update_user_group(data) ``` -------------------------------- ### Update Rule-Based Segment definition with rules Source: https://github.com/splitio/python-api/blob/master/README.md This snippet demonstrates how to update a rule-based segment definition by providing new rules, including conditions with combiners and matchers. ```python ws = client.workspaces.find("Defaults") env = client.environments.find("Production", ws.id) segdef = client.rule_based_segment_definitions.find("advanced_users", env.id, ws.id) # Define rules that match users in a certain list rules_data = { 'rules': [ { 'condition': { 'combiner': 'AND', 'matchers': [ { 'type': 'GREATER_THAN_OR_EQUAL_NUMBER', 'attribute': 'age', 'number': 30 }, { 'type': 'BOOLEAN', 'attribute': 'completed_tutorials', 'bool': True } ] } } ] } # Update the segment definition with the rules updated_segdef = segdef.update(rules_data) # the workspace id is passed in from the find operation - so it's not needed here ``` -------------------------------- ### Override default identifiers for a specific request Source: https://github.com/splitio/python-api/blob/master/README.md Shows how to override the default account and organization identifiers for a single API call. ```python # Override default identifiers for a specific request # Note: project_identifier is not used for harness_project endpoints projects = client.harness_project.list( account_identifier='DIFFERENT_ACCOUNT_ID', org_identifier='DIFFERENT_ORG_ID' ) ``` -------------------------------- ### Submit a Change request to update a Split definition Source: https://github.com/splitio/python-api/blob/master/README.md Submits a change request to update a split definition with new treatments, rules, and comments. ```python splitDef = client.split_definitions.find("new_feature", env.id, ws.id) definition= {"treatments":[ {"name":"on"},{"name":"off"}], "defaultTreatment":"off", "baselineTreatment": "off", "rules": [], "defaultRule":[{"treatment":"off","size":100}],"comment": "updating default rule" } splitDef.submit_change_request(definition, 'UPDATE', 'updating default rule', 'comment', ['user@email.com'], '') ``` -------------------------------- ### Delete a pending invite Source: https://github.com/splitio/python-api/blob/master/README.md Deletes a pending user invite based on email address. ```python for user in client.users.list('PENDING'): print(user.email + ", " + user._id + ", " + user._status) if user.email == 'user@email.com': client.users.delete(user._id) ``` -------------------------------- ### List groups with filterType to exclude inherited groups Source: https://github.com/splitio/python-api/blob/master/README.md Filters groups to exclude inherited ones. ```python # List groups with filterType to exclude inherited groups groups = client.harness_group.list(filterType='EXCLUDE_INHERITED_GROUPS') ``` -------------------------------- ### Update Rule-Based Segment definition with excluded keys and excluded segments Source: https://github.com/splitio/python-api/blob/master/README.md This snippet shows how to update a segment definition by including rules, a list of excluded keys, and a list of excluded segments. ```python ws = client.workspaces.find("Defaults") env = client.environments.find("Production", ws.id) segdef = client.rule_based_segment_definitions.find("advanced_users", env.id, ws.id) # Define rules and exclusion data update_data = { 'rules': [ { 'condition': { 'combiner': 'AND', 'matchers': [ { 'type': 'GREATER_THAN_OR_EQUAL_NUMBER', 'attribute': 'age', 'number': 30 } ] } } ], 'excludedKeys': ['user1', 'user2', 'user3'], 'excludedSegments': [ { 'name': 'beta_testers', 'type': 'standard_segment' } ] } # Update the segment definition with rules and exclusions updated_segdef = segdef.update(update_data) ``` -------------------------------- ### Remove Rule-Based Segment from environment Source: https://github.com/splitio/python-api/blob/master/README.md Removes a rule-based segment from a specific environment. ```python ws = client.workspaces.find("Defaults") segment = client.rule_based_segments.find("advanced_users", ws.id) env = client.environments.find("Production", ws.id) success = segment.remove_from_environment(env.id) ``` -------------------------------- ### Submit a Change request to update a Rule-Based Segment definition Source: https://github.com/splitio/python-api/blob/master/README.md This snippet demonstrates how to submit a change request to update a rule-based segment definition, including new rules, excluded keys, excluded segments, operation type, title, comment, approvers, and workspace ID. ```python ws = client.workspaces.find("Defaults") env = client.environments.find("Production", ws.id) segdef = client.rule_based_segment_definitions.find("advanced_users", env.id, ws.id) # New rules for the change request rules = [ { 'condition': { 'combiner': 'AND', 'matchers': [ { 'type': 'GREATER_THAN_OR_EQUAL_NUMBER', 'attribute': 'age', 'number': 25 }, { 'type': 'BOOLEAN', 'attribute': 'completed_tutorials', 'bool': True } ] } } ] # Define excluded keys and segments for the change request excluded_keys = ['user1', 'user2'] excluded_segments = [ { 'name': 'test_users', 'type': 'rule_based_segment' } ] # Submit change request with all parameters segdef.submit_change_request( rules=rules, excluded_keys=excluded_keys, excluded_segments=excluded_segments, operation_type='UPDATE', title='Lower age threshold to 25', comment='Including more users in advanced segment', approvers=['user@email.com'], workspace_id=ws.id ) ``` -------------------------------- ### Delete Group Source: https://github.com/splitio/python-api/blob/master/README.md Deletes a group by its ID. ```python group = client.groups.find('new_group') client.groups.delete_group(group._id) ``` -------------------------------- ### Remove Rule based segment from workspace Source: https://github.com/splitio/python-api/blob/master/README.md Deletes a rule-based segment from the workspace. ```python ws = client.workspaces.find("Defaults") success = ws.delete_rule_based_segment("advanced_users") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.