Python Feature Flags

Split's Python SDK provides robust, scalable feature flag management, giving any team the power to safely launch features and target them to users.

Begin your free trial today.

Why use Split for Python?

Split’s Python SDK brings free, scalable feature flagging to any app, website or experience built in Python. Split helps teams control rollouts, and customer experiences, while gathering new data and insight on how their products are being engaged. With Split, teams can:

  • Release features to production but disabled for all users by default
  • Target new features only to internal QA teams
  • Slowly roll out features to a broader audience by percentage, demographic, geography, account type, or any other metric
  • Kill features with a single click to revert back to your safe state

Split works across many different languages, letting developers, PMs and support teams control feature rollout from one unified view—and monitor the success of any new code. Our integrations bring rollout updates into the tools your team is already using, further opening the feature-delivery process up to your entire organization.

Supports Python with Django

Split's Python SDK for Django supports two different approaches to share information across processes: in-memory cache (via uWSGI) and External cache (via Redis). django_splitio supports both Python 2 (2.7.10 or later) and Python 3 (3.3 or later) and Django 1.8 (or later). Stable versions can be installed from PyPI using pip.

Visit our documentation to learn more about using the Split Python SDK with Django.

Using the Python SDK in Multi-Process Mode

When running Python in multi-process mode, state is usually shared between multiple processes using a remote data store. As a result, the Python SDK with multi-process support is architected differently that the plain Python SDK. This architecture has three components:

  • The Synchronizer Service The Synchronizer Service is responsible for fetching the data from Split servers it needs to evaluate what treatment to show to a customer. It is a background service that can be run on one machine on a schedule via your scheduling system. We recommend supervisord.
  • The cache component The cache is where cron jobs store data fetched from Split servers. Moreover, the SDK client reads from this cache and stores diagnostic data in the cache which is posted back to Split servers via cron jobs. We currently support two type of caches: in-memory cache (via uWSGI), and External cache (via Redis).The current Redis support requires Redis >= v2.6 and the SDK uses Python's Redis library to communicate with Redis.
  • The SDK client is embedded within your Python app. It is the brain that uses data fetched from the cache to decide which treatment to show to a customer for a particular split.

Visit our documentation to learn more about the Split Python SDK's multi-process mode.

Getting Started with Split for Python

Split's Python SDK is very simple to integrate into your code base and is completely open source. All it really takes to get rolling with Split is initiating the SDK, then splitting your code.

Initiating the SDK

First, import the SDK into your project:

          pip install splitio_client[cpphash]==4.1.1
        

The instantiate the SDK and create a new Split client:


from splitio import get_factory

factory = get_factory('YOUR_API_KEY')
split = factory.client()

        

We recommend instantiating it once as a singleton and reusing it throughout your application.

Include the API key for the environment you are setting up the SDK for. The API key is available under your Organization Settings page, under the APIs tab. The API key is of type sdk**

Splitting your code.

With the SDK instantiated, it’s now time to start splitting your code base. Find a feature you’d like to split, and wrap it in the split feature flag like so:


treatment = split.get_treatment('CUSTOMER_ID', 'SPLIT_NAME')

if treatment == "on":
    # insert code here to show on treatment
elif treatment == "off":
    # insert code here to show off treatment
else:
    # insert your control treatment code here

        

The Split Python SDK integrates seamlessly into your code; no other changes or dependencies are needed to get Split up and running.

For more advanced configurations like running multiple evaluations at once, or using attributes in the SDK, take a look at our Python SDK documentation.

To continue diving into Split, sign up for a free account today, or dig into our Documentation.