Python Admin API Command-Line Interface (CLI)
Learn how to use the Python Admin API CLI.
Overview
With the Python Admin API command-line interface (CLI), you can:
Search for projects, environments, groups, users, feature flags, and segments
List all projects, 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.
For more information, see the GitHub repository.
Setup
If you don’t have Python 3 installed, install it.
If you are using MacOS, the
pythoncommand ispython3.Run the following command to create an alias for
python:echo "alias python=python3\nalias pip=pip3" >> ~/.zprofile source ~/.zprofileNow your
pythoncommand on MacOS runs python3.
Clone this repository and access it using the following commands:
git clone https://github.com/Split-Community/split_support_tools.git cd split_support_tools/python_admin_api_tool/Create a virtual environment using the following commands
python -m venv venv source venv/bin/activateInstall the requirements using the following commands:
pip install -r requirements.txtMake a copy of the example environment variables file using the following command:
cp env_sample .envAdd your Admin API Key to the
.envfile you just created.Run the tool using the following commands:
python admin_api_tool.pyIf you are using MacOS, run the following command:
python3 admin_api_tool.py
Caching
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.
Usage
The menu is straightforward with the options. There are 5 choices:
Search
The following options are available for search:
List
The following options are available for list:
Export
The following options are available for export:
By default, all exports are in JSON format. For more information, see the JSON to CSV converter section.
Operations
The following options are available for operations:
Update Cache
Harness recommends running this option after you have made changes to your feature flags or segments to ensure FME receives the most recent data.
DEBUG Logging
If you run into issues, you can run the script with debug logging enabled for better troubleshooting:
JSON to CSV converter
You can use the provided convert_json_csv.py to convert your JSON files to CSV files.
In the same directory of your JSON files, run the following command:
Last updated
Was this helpful?