ConfigCat Python SDK

10.0.0 · active · verified Sat Apr 11

ConfigCat SDK for Python provides easy integration for your application to ConfigCat. It's a feature flag and configuration management service that lets you separate releases from deployments, enabling remote control over features. The library is actively maintained, with the current version being 10.0.0, and receives regular updates including new features and compatibility improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the ConfigCat client, retrieve a feature flag's value, and safely close the client. It also shows how to get a value for a specific user using a `User` object. Remember to replace `YOUR_SDK_KEY_HERE` with your actual ConfigCat SDK Key, ideally loaded from an environment variable.

import os
import configcatclient

# Get your SDK Key from ConfigCat Dashboard (e.g., via environment variable)
SDK_KEY = os.environ.get('CONFIGCAT_SDK_KEY', 'YOUR_SDK_KEY_HERE')

def main():
    # Create a ConfigCat client instance (recommended as a singleton)
    client = configcatclient.get(SDK_KEY)

    # Get your setting value
    # The second argument is the default value if the key is not found
    is_my_awesome_feature_enabled = client.get_value('isMyAwesomeFeatureEnabled', False)

    if is_my_awesome_feature_enabled:
        print("Feature is ENABLED!")
    else:
        print("Feature is DISABLED.")

    # You can also get a value for a specific user
    user = configcatclient.User('some-user-id', email='user@example.com')
    is_feature_for_user = client.get_value('isMyAwesomeFeatureEnabled', False, user)
    print(f"Feature for user 'some-user-id': {is_feature_for_user}")

    # Stop ConfigCat client on application exit to release resources
    client.close()
    # Alternatively, configcatclient.close_all() to close all clients

if __name__ == '__main__':
    main()

view raw JSON →