With the Python Admin API command-line interface, (CLI), you can:
- Search for workspaces, environments, groups, users, feature flags, and segments
- List all workspaces, environments, groups, users, feature flags, and segments
- Export detailed definitions to JSON and optionally convert to CSV
- Copy (clone) feature flags and segments
- Delete groups, segments, and feature flags
This Python tool utilizes Split's Python PyPi library for Split REST Admin API.
- If you don’t have Python 3 installed, install it from here
- Note that on MacOS, the python command is
- Run the following command to create an alias for python.
echo "alias python=python3\nalias pip=pip3" >> ~/.zprofile source ~/.zprofile
- Now your
pythoncommand on MacOS runs python3.
- Clone this repository and access it as follows:
git clone https://github.com/Split-Community/split_support_tools.git cd split_support_tools/python_admin_api_tool/
- Create a new virtual environment.
python -m venv venv source venv/bin/activate
- Install the requirements.
pip install -r requirements.txt
- Make a copy of the example environment variables file.
cp env_sample .env
- Add your Admin API key to the newly created
- Note that it's recommended to use an API key that is scoped across all environments and workspaces
- If the environment/workspace has access restrictions, you might encounter an error.
- Run the tool
or on MacOS
To reduce API calls and improve response time, the script caches feature flag definitions and segment definitions on the first run if there is no cache data. Other data will be cached on the first use.
Note: If you make changes to your feature flags or segment definitions, it's recommended that you update the cache using the Update Cache option.
The menu is straightforward with the options. There are 5 choices:
- Update Cache
The Search options are:
1. Search Workspaces Or Groups - This searches for the name of the workspaces or the groups in your org. 2. Search Environments - This searches for all the environments of the same name across all workspaces. 3. Search Users - Requires the email of the users being searched. This shows information of the user and which group they are in. 4. Search Feature Flags - This searches for all feature flags of the same name across all workspaces and environments. - When a feature flag is found, the user can choose to export the following: * This feature flag's definition from a specific environment to json * The treatment keys to csv * The list of the targeting rules csv 5. Search Segments - This will search for all segments of the same name across all workspaces and environments, and will also display all the keys of the segments. - When a segment is found, the user can choose to export the following: * The segment keys to csv
The List options are self-explanatory. Note that these do not show the full details (such as feature flag definitions or segment keys), please use the Export functions to get the full data.
1. List all workspaces - List all workspaces in the org. 2. List all environments - List all environments across all workspaces. 3. List all groups - List all the groups and the list of users. 4. List all segments - List all the segments and keys of each for all environments and workspaces. 5. List all feature Flags - List all the feature flags across all workspaces, does not show feature flag definitions (use the export option for the definitions). 6. List all users - List all users and their statuses.
The Export options are straightforward. By default, all exports are json format.
Also refer to the Additional tool (JSON to CSV converter) for more information.
1. Export environments - This exports all environments across all workspaces. 2. Export groups - This exports all groups and the users in each group. 3. Export segments definitions - This exports all segments definitions across all workspaces and environments. 4. Export segments keys - This lets the user choose the workspace, environment, the segment, and export all the keys. 5. Export feature flag definitions - This exports all feature flag definitions across all workspaces and environments. 6. Export feature flags - This exports all feature flags (not the definitions) across all workspaces and environments. 7. Export users - This exports all the users and their statuses, as well as group memberships. 8. Export workspaces - This exports all workspaces in your org.
The Operations mutates or changes your feature flags/segments/workspaces/environments. More options will be added over time.
1. Copy segment definitions - This allows for copying the keys of one segment to another segment. Users can choose from available lists of workspaces, environments, and segments to copy. 2. Copy feature flag definitions - This allows for copying the definitions of one feature flag to another feature flag. Users can choose from available lists of workspaces, environments, and feature flags to copy. 3. Delete groups - This forcefully deletes the group in the workspace you specified, regardless of the definitions. Note that this is not reversible! 4. Delete segments - This forcefully deletes the segment in the workspace you specified, regardless of the definitions. Note that this is not reversible! 5. Delete feature flags - This forcefully deletes the feature flag in the workspace you specified, regardless of the definitions. Note that this is not reversible!
It's recommended to run this option after you have made changes to feature flags or segments to ensure the latest data.
If you run into issues, you can run the script with debug logging enabled for better troubleshooting:
python admin_api_tool.py --debug
Additional tool (JSON to CSV converter)
You can use the provided
convert_json_csv.py to convert your json files to csv. Simply run
In the same directory of your json files.
The admin tool does not work properly for workspaces that require approval or have access restrictions.
When that happens, you either have to manually do the edit, or you have to make sure the API key you are using has proper access and temporarily disable the approval so the tool can work.