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

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

  1. If you don’t have Python 3 installed, install it.

    • If you are using MacOS, the python command is python3.

    • Run the following command to create an alias for python:

      echo "alias python=python3\nalias pip=pip3" >> ~/.zprofile
      source ~/.zprofile
    • Now your python command on MacOS runs python3.

  2. 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/
  3. Create a virtual environment using the following commands

    python -m venv venv
    source venv/bin/activate
  4. Install the requirements using the following commands:

    pip install -r requirements.txt
  5. Make a copy of the example environment variables file using the following command:

    cp env_sample .env
  6. Add your Admin API Key to the .env file you just created.

    Harness recommends using an API key that is scoped across all environments and projects. If the environment or project has access restrictions, you may encounter an error.

    In cases like these, you can manually edit or ensure the API key that you are using has proper access, and temporarily disable the approval so the tool can work.

  7. Run the tool using the following commands:

    python admin_api_tool.py

    If 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.

If you make changes to your feature flags or segment definitions, Harness recommends updating the cache using the Update Cache option.

Usage

The menu is straightforward with the options. There are 5 choices:

The following options are available for search:

List

The following options are available for list:

The List option does not show the full details (such as feature flag definitions or segment keys). To get the comprehensive data, use the Export option.

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?