Python SDK installation

2 minute read

Control feature rollout for certain user segments of your application with feature flags. To start using feature management in the platform, follow the instructions below to install the SDK and deploy a feature flag.

These same instructions are available in the platform UI. Select Installation from the left pane to use.

To install the SDK:

  1. Select the next to Feature management on the left pane, and then select Installation.

  2. Select an Environment from the options, or create an environment by completing the following:

    1. Select CREATE ENVIRONMENT.

    2. Enter an Environment name.

    3. (Optional) Enter a Description.

    4. (Optional) Select Approvers if you want to have a manual approval required before deployment.

    5. (Optional) Enter any Properties you want to associate with the environment. For more information, refer to properties configuration and properties in an environment.

    6. Select SUBMIT.

  3. Select Python from the language options, and the package manager Pip is selected by default.

  4. Add the ROX package to your application by running the shell command appropriate for the package manager:

    pip install rox
  5. Add the following code to your Python application:

    Your SDK key is a unique environment identifier. During SDK installation, the SDK key is displayed within the Rox.setup call.
    # Import SDK from rox.server.rox_server import Rox from rox.server.flags.rox_flag import RoxFlag from rox.core.entities.rox_string import RoxString from rox.core.entities.rox_int import RoxInt from rox.core.entities.rox_double import RoxDouble # Create Roxflags in the Flags container class class Flags: def __init__(self): #Define the feature flags self.enableTutorial = RoxFlag(False) self.titleColors = RoxString('White', ['White', 'Blue', 'Green', 'Yellow']) self.page = RoxInt(1, [1, 2, 3]) self.percentage = RoxDouble(99.9, [10.5, 50.0, 99.9]) flags = Flags() # Register the flags container Rox.register(flags) # Setup the environment key cancel_event = Rox.setup("<your-SDK-key>").result();(1) # Boolean flag example print('enableTutorial is {}'.format(flags.enableTutorial.is_enabled())) # String flag example print('color is {}'.format(flags.titleColors.get_value())) # Int flag example print('page is {}'.format(flags.page.get_value())) # Double flag example print('percentage is {}'.format(flags.percentage.get_value()))
    1 The platform provides the unique SDK key for your environment at the <your-SDK-key> location within the Rox.setup call.
  6. Run your application and then select TEST INTEGRATION to confirm a successful connection.

After running the application, a default flag is automatically added to your feature flag list.

You have installed an SDK and created flags in your application.

Refer to the SDK reference for more information.