ConfigCat Python SDK
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
- breaking Version 10.0.0 dropped support for Python 2.7, 3.5, 3.6, and 3.7. Attempting to use the library on these versions will result in `ImportError` or other compatibility issues.
- breaking Deprecated client initialization functions like `configcatclient.create_client()`, `create_client_with_auto_poll()`, etc., were removed in v8.0.0. The `stop()` method was also renamed to `close()`.
- breaking Version 9.0.0 introduced support for Config JSON v6 format. The older v5 format is no longer accepted for flag overrides, and the `User`'s `custom` dictionary now allows attribute values other than strings.
- gotcha It is strongly recommended to use the ConfigCat Client as a singleton object throughout your application. `configcatclient.get()` returns a singleton instance for a given SDK key.
- gotcha Failure to explicitly close the ConfigCat client on application exit can lead to resource leaks (e.g., open HTTP connections, lingering background threads for polling).
- gotcha Starting from v8.0.0, passing an invalid SDK key format to `configcatclient.get()` will raise a `ConfigCatClientException` unless the client is configured for local-only flag overrides.
Install
-
pip install configcat-client
Imports
- configcatclient
import configcatclient
- get
client = configcatclient.get("#YOUR-SDK-KEY#") - ConfigCatOptions
from configcatclient import ConfigCatOptions
- PollingMode
from configcatclient import PollingMode
- User
from configcatclient import User
Quickstart
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()