All notable changes to the LaunchDarkly Python SDK will be documented in this file. This project adheres to Semantic Versioning.
- The SDK could fail to send debug events when event debugging was enabled on the LaunchDarkly dashboard, if the application server's time zone was not GMT.
- The logic for detecting uWSGI did not account for undocumented behavior in some environments where the
uwsgi
module is present in an incomplete state; this could cause an error on startup in such environments. Also, the log message about threading options related to uWSGI contained a broken link. (Thanks, andrefreitas!)
This major release is for Python compatibility updates and removal of deprecated APIs. It introduces no new functionality except type hints.
- Added type hints to all SDK methods. Python by itself does not enforce these, but commonly used development tools can provide static checking to trigger warnings or errors if the wrong type is used.
- Python 2.7, 3.3, and 3.4 are no longer supported. The minimum Python version is now 3.5.
- The first parameter to the
Config
constructor,sdk_key
, is now required. Previously it was possible to omit thesdk_key
from theConfig
and specify it separately when initializing the SDK. Now, it is always in theConfig
.
- Removed
ldclient.set_sdk_key()
. The correct way to do this now, if you are using the singleton client methodldclient.get()
, is to callldclient.set_config()
with aConfig
object that contains the SDK key. - Removed the optional SDK key parameter from the
LDClient
constructor. You must now provide a configuration parameter of typeConfig
, and set the SDK key within theConfig
constructor:LDClient(Config(sdk_key = "my-sdk-key", [any other config options]))
. Previously, it was possible to specify the SDK key as a single string parameter and omit theConfig
object—LDClient("my-sdk-key")
—although this would cause a deprecation warning to be logged; specifying both a key and aConfig
was always an error. - Removed the individual HTTP-related parameters such as
connect_timeout
from theConfig
type. The correct way to set these now is with theHTTPConfig
sub-configuration object:Config(sdk_key = "my-sdk-key", http = HTTPConfig(connect_timeout = 10))
. - Removed all other types, parameters, and methods that were deprecated as of the last 6.x release.
- The SDK was not recognizing proxy authorization parameters included in a proxy URL (example:
http://username:password@proxyhost:port
). It will now use these parameters if present, regardless of whether you set the proxy URL programmatically or in an environment variable. (Thanks, gangeli!)
- A problem with the SDK's use of
urllib3.Retry
could prevent analytics event delivery from being retried after a network error or server error. (#143)
- The new
Config
parameterinitial_reconnect_delay
allows customizing of the base retry delay for stream connections (that is, the delay for the first reconnection after a failure; subsequent retries use an exponential backoff). - The new
Config
parameterhttp
and theHTTPConfig
class allow advanced configuration of the SDK's network behavior, such as specifying a custom certificate authority for connecting to a proxy/gateway that uses a self-signed certificate.
- The retry delay for stream connections has been changed as follows: it uses an exponential backoff no matter what type of error occurred (previously, some kinds of errors had a hard-coded 1-second delay), and each delay is reduced by a random jitter of 0-50% rather than 0-100%. Also, if a connection remains active for at least 60 seconds, the backoff is reset to the initial value. This makes the Python SDK's behavior consistent with other LaunchDarkly SDKs.
- The existing
Config
propertiesconnect_timeout
,read_timeout
, andverify_ssl
are now deprecated and superseded by the equivalent properties inHTTPConfig
.
- Setting
verify_ssl
toFalse
in the client configuration did not have the expected effect of completely turning off SSL/TLS verification, because it still left certificate verification in effect, so it would allow a totally insecure connection but reject a secure connection whose certificate had an unknown CA. This has been changed so that it will turn off certificate verification as well. This is not a recommended practice and a future version of the SDK will add a way to specify a custom certificate authority instead (to support, for instance, using the Relay Proxy with a self-signed certificate).
- When diagnostic events are enabled (as they are by default), the SDK was logging spurious warning messages saying "Unhandled exception in event processor. Diagnostic event was not sent. ['DiagnosticEventSendTask' object has no attribute '_response_fn']". The events were still being sent; the misleading message has been removed.
Note: if you are using the LaunchDarkly Relay Proxy to forward events, update the Relay to version 5.10.0 or later before updating to this Python SDK version.
- The SDK now periodically sends diagnostic data to LaunchDarkly, describing the version and configuration of the SDK, the architecture and version of the runtime platform, and performance statistics. No credentials, hostnames, or other identifiable values are included. This behavior can be disabled with the
diagnostic_opt_out
option or configured withdiagnostic_recording_interval
.
- The SDK now specifies a uniquely identifiable request header when sending events to LaunchDarkly to ensure that events are only processed once, even if the SDK sends them two times due to a failed initial attempt.
- In rare circumstances (depending on the exact data in the flag configuration, the flag's salt value, and the user properties), a percentage rollout could fail and return a default value, logging the error "variation/rollout object with no variation or rollout". This would happen if the user's hashed value fell exactly at the end of the last "bucket" (the last variation defined in the rollout). This has been fixed so that the user will get the last variation.
- Changed
Files.new_data_source()
to useyaml.safe_load()
instead ofyaml.load()
for YAML/JSON test data parsing. This disablespyyaml
extended syntax features that could allow arbitrary code execution. (#136)
- Fixed an incompatibility with Python 3.3 due to an unpinned dependency on
expiringdict
. - Fixed usages that caused a
SyntaxWarning
in Python 3.8. (Thanks, bunchesofdonald!) - Updated CI scripts so a
SyntaxWarning
will always cause a build failure, and added a 3.8 build.
- The new
Config
parameterhttp_proxy
allows you to specify a proxy server programmatically rather than by using environment variables. This may be helpful if you want the SDK to use a proxy, but do not want other Python code to use the proxy. (Thanks, gangeli!)
- Since version 6.1.0, the SDK was not respecting the standard
https_proxy
environment variable for specifying a proxy (because that variable is not used byurllib3
). This has been fixed. - In streaming mode, the SDK could fail to apply a feature flag update if it exceeded the LaunchDarkly service's maximum streaming message size; the service uses an alternate delivery mechanism in this case, which was broken in the SDK. This bug was also introduced in version 6.1.0.
- Fixed the generated documentation to exclude special members like
__dict__
.
- Fixed a bug in 6.10.0 that prevented analytics events from being generated for missing flags.
- Added support for upcoming LaunchDarkly experimentation features. See
LDClient.track()
.
- Under conditions where analytics events are being generated at an extremely high rate (for instance, if an application is evaluating a flag repeatedly in a tight loop on many threads), a thread could be blocked indefinitely within
variation
while waiting for the internal event processing logic to catch up with the backlog. The logic has been changed to drop events if necessary so threads will not be blocked (similar to how the SDK already drops events if the size of the event buffer is exceeded). If that happens, this warning message will be logged once: "Events are being produced faster than they can be processed; some events will be dropped". Under normal conditions this should never happen; this change is meant to avoid a concurrency bottleneck in applications that are already so busy that thread starvation is likely.
- Usages of
Logger.warn()
were causing deprecation warnings in some versions of Python. Changed these toLogger.warning()
. (#125)
- Changed the artifact name from
ldclient-py
tolaunchdarkly-server-sdk
- Changed repository references to use the new URL
There are no other changes in this release. Substituting ldclient-py
version 6.9.1 with launchdarkly-server-sdk
version 6.9.2 will not affect functionality.
- The
set_sdk_key
function was comparing the existing SDK key (if any) to the new one by identity (is
) rather than equality (==
). In Python, two strings that have the same characters may or may not be the same string instance; in the case where they were not,set_sdk_key
would inappropriately reinitialize the client even though the SDK key had not really changed. (Thanks, jpgimenez!) - Running the SDK unit tests is now simpler in that the database integrations can be skipped. See
CONTRIBUTING.md
.
The LaunchDarkly SDK repositories are being renamed for consistency. This repository is now python-server-sdk
rather than python-client
.
The package name will also change. In the 6.9.1 release, it is still ldclient-py
; in all future releases, it will be launchdarkly-server-sdk
. No further updates to the ldclient-py
package will be published after this release.
- It is now possible to use the
with
statement on an LDClient object, so thatclose()
will be called automatically when it goes out of scope.
- Calling
close()
on the client would cause an error if the configuration includeduse_ldd=True
. (#118)
- Setting user attributes to non-string values when a string was expected would cause analytics events not to be processed. Also, in the case of the "secondary" attribute, this could cause evaluations to fail for a flag with a percentage rollout. The SDK will now convert attribute values to strings as needed. (#115)
- If
track
oridentify
is called without a user, the SDK now logs a warning, and does not send an analytics event to LaunchDarkly (since it would not be processed without a user).
Note that starting with this release, generated API documentation is available online at https://launchdarkly-python-sdk.readthedocs.io. This is published automatically from the documentation comments in the code.
- The SDK no longer uses
jsonpickle
. - The CI test suite for all supported Python versions, which previously only ran in Linux, has been extended to include Python 3.6 in Windows.
- Corrected and expanded many documentation comments. All public API methods (not including internal implementation details) are now documented.
- Fixed a different packaging error that was still present in the 6.8.1 release, which made the package installable but caused imports to fail. The 6.8.1 release has been pulled from PyPI. We apologize for these recent errors, which were not detected prior to release because our prerelease testing was using the source code directly rather than installing it with
pip
. Our CI tests have been updated and should prevent this in the future.
- Fixed a packaging error that made the 6.8.0 release not installable. There are no other changes. The 6.8.0 release has been pulled from PyPI.
- It is now possible to use Consul as a persistent feature store, similar to the existing Redis and DynamoDB integrations. See
Consul
inldclient.integrations
, and the reference guide for "Using a persistent feature store".
- It is now possible to use DynamoDB as a persistent feature store, similar to the existing Redis integration. See
DynamoDB
inldclient.integrations
, and the reference guide to "Using a persistent feature store". - The new class
CacheConfig
(inldclient.feature_store
) encapsulates all the parameters that control local caching in database feature stores. This takes the place of theexpiration
andcapacity
parameters that are in the deprecatedRedisFeatureStore
constructor; it can be used with DynamoDB and any other database integrations in the future, and if more caching options are added toCacheConfig
they will be automatically supported in all of the feature stores.
- The
RedisFeatureStore
constructor inldclient.redis_feature_store
. The recommended way to create a Redis feature store now is to useRedis.new_feature_store
inldclient.integrations
.
- It is now possible to inject feature flags into the client from local JSON or YAML files, replacing the normal LaunchDarkly connection. This would typically be for testing purposes. See
file_data_source.py
.
- The
all_flags_state
method now accepts a new option,details_only_for_tracked_flags
, which reduces the size of the JSON representation of the flag state by omitting some metadata. Specifically, it omits any data that is normally used for generating detailed evaluation events if a flag does not have event tracking or debugging turned on.
- The SDK previously contained a copy of code from the
expiringdict
package. This has been changed to use the current version of that package from PyPi.
- JSON data from
all_flags_state
is now slightly smaller even if you do not use the new option described above, because it omits the flag property for event tracking unless that property is true.
- In polling mode, if the client received an HTTP error from LaunchDarkly, it stopped polling. This has been fixed so it only stops polling if the error is 401 (indicating an invalid SDK key).
- When using a Redis feature store, if the
hgetall
method returned an invalid result,all_flags
andall_flags_state
would throw an exception. Instead,all_flags
will now return an empty dict, andall_flags_state
will return a state object with no flags andvalid==False
. (Thanks, thieman!)
- In Python 3, if the Redis feature store encountered a Redis exception, it would crash on trying to log the
message
property of the exception, which does not exist in Python 3. This has been fixed. (Thanks, mattbriancon!)
- The new
LDClient
methodvariation_detail
allows you to evaluate a feature flag (using the same parameters as you would forvariation
) and receive more information about how the value was calculated. This information is returned in anEvaluationDetail
object, which contains both the result value and a "reason" object which will tell you, for instance, if the user was individually targeted for the flag or was matched by one of the flag's rules, or if the flag returned the default value due to an error.
- When evaluating a prerequisite feature flag, the analytics event for the evaluation did not include the result value if the prerequisite flag was off.
- The new
LDClient
methodall_flags_state()
should be used instead ofall_flags()
if you are passing flag data to the front end for use with the JavaScript SDK. It preserves some flag metadata that the front end requires in order to send analytics events correctly. Versions 2.5.0 and above of the JavaScript SDK are able to use this metadata, but the output ofall_flags_state()
will still work with older versions. - The
all_flags_state()
method also allows you to select only client-side-enabled flags to pass to the front end, by using the optionclient_side_only=True
.
LDClient.all_flags()
- In streaming mode, each connection failure or unsuccessful reconnection attempt logs a message at
ERROR
level. Previously, this message included the amount of time before the next retry; since that interval is different for each attempt, that meant theERROR
-level messages were all unique, which could cause problems for monitors. This has been changed so theERROR
-level message is always the same, and is followed by anINFO
-level message about the time delay. (Note that in order to suppress the default message, the LaunchDarkly client modifies the logger used by thebackoff
package; if you are usingbackoff
for some other purpose and do want to see the default message, setlogging.getLogger('backoff').propagate
toTrue
.) (#88)
- Removed an unused dependency on the
CacheControl
package.
- The client now uses
urllib3
for HTTP requests, rather than therequests
package. This change was made becauserequests
has a dependency on an LGPL-licensed package, and some of our customers cannot use LGPL code. The networking behavior of the client should be unchanged. - The client now treats most HTTP 4xx errors as unrecoverable: that is, after receiving such an error, it will not make any more HTTP requests for the lifetime of the client instance, in effect taking the client offline. This is because such errors indicate either a configuration problem (invalid SDK key) or a bug in the client, which will not resolve without a restart or an upgrade. This does not apply if the error is 400, 408, 429, or any 5xx error.
- During initialization, if the client receives any of the unrecoverable errors described above,
ldclient.get()
will return immediately; previously it would continue waiting until a timeout. Theis_initialized()
method will return false in this case.
- Fixed a bug introduced in v6.0.3 that caused the user cache for analytics events to never be cleared, also causing an
AttributeError
to appear in the log.
- Removed a dependency on the
pylru
package, because it uses a GPL license.
- Fixed a bug that, in Python 3.x, could cause a timer thread to keep running after the client has been shut down. This bug also caused the message "TypeError: Event object is not callable" to be logged.
- Fixed the
Config
initializer to create a new instance ofInMemoryFeatureStore
if you omit thefeature_store
argument. Previously, allConfig
instances that were created with default parameters would share the same feature store instance. - Clarified HTTP proxy setup instructions in the readme.
- Fixed a bug that caused an error message to be logged (
KeyError: 'default'
) when evaluating a prerequisite flag (and that also prevented an analytics event from being sent for that flag). - When running in uWSGI, the client will no longer log an error message if the
enableThreads
option is absent, as long as thethreads
option has been set to a number greater than 1. (#84)
This release was broken and has been removed.
- To reduce the network bandwidth used for analytics events, feature request events are now sent as counters rather than individual events, and user details are now sent only at intervals rather than in each event. These behaviors can be modified through the LaunchDarkly UI and with the new configuration option
inline_users_in_events
. For more details, see Analytics Data Stream Reference. - The analytics event processor now flushes events at a configurable interval defaulting to 5 seconds, like the other SDKs (previously it flushed if no events had been posted for 5 seconds, or if events exceeded a configurable number). This interval is set by the new
Config
propertyflush_interval
.
- Python 2.6 is no longer supported.
- Removed the
Config
propertyevents_upload_max_batch_size
, which is no longer relevant in the new event flushing logic (see above).
- It was not possible to install the SDK with
pip
10.0.0. This should work now (thanks, @theholy7!) with the latestpip
as well as previous versions.
- Fixed a bug that, in Python 3.x, caused an error when using an integer user attribute to compute a rollout.
- Fixed a bug that, in Python 3.x, made the
all_flags
method return a dictionary with byte-string keys instead of string keys when using the Redis feature store.
- In the Redis feature store, fixed a synchronization problem that could cause a feature flag update to be missed if several of them happened in rapid succession.
- Support for a new LaunchDarkly feature: reusable user segments.
- The
FeatureStore
interface has been changed to support user segment data as well as feature flags. Existing code that usesInMemoryFeatureStore
orRedisFeatureStore
should work as before, but custom feature store implementations will need to be updated.
- Twisted is no longer supported.
This release was broken and has been removed.
- Percentage rollouts can now reference an attribute with an integer value, not just string attributes.
- Fixed a bug that caused unusually slow initialization times when there are large numbers of flags.
- Fixed reporting of events for prerequisite checks.
- Reduced WARN-level logging for a feature flag not being found to INFO level.
- Fixed a bug where a previously deleted feature flag might be considered still available.
- The private attributes feature added in v4.1.0 was not available in Twisted mode; now it is.
- Will use feature store if already initialized even if connection to service could not be established. This is useful when flags have been initialized in redis.
- Allow user to stop user attributes from being sent in analytics events back to LaunchDarkly. Set
private_attribute_names
on each request and/or onConfig
to a list of strings matching the names of the attributes you wish to exclude. Setall_attributes_private
on theConfig
object to hide all attributes.
- Stop reattempting connections when receiving a 401 (unauthorized) response from LaunchDarkly. This should only be caused by invalid SDK key so retrying is pointless.
events_enabled
is deprecated andsend_events
should be used instead.events_enabled
may be removed in a future minor revision.
- Improved error handling when processing stream events
- Replaced 3rd party rfc3339 library for license compliance
- No longer caching
get_one()
responses
- #70 Regex
matches
targeting rules now include the user if a match is found anywhere in the attribute. Before fixing this bug, the beginning of the attribute needed to match the pattern.
- #43 Started publishing code coverage metrics to Code Climate. Bear in mind that the Code Climate coverage report only shows the unit test coverage, while the bulk of our SDK test coverage comes from a separate integration test suite.
- #65 Ensure that no warning is logged about a missing SDK key when the
ldclient
package is imported.
- Fixed missing python2.6-requirements.txt in manifest
- Support for Python 2.6.
- RedisFeatureStore now returns default when Redis errors occur
- Better detection of stream connection issues.
- Changing the config and SDK key is now supported after initialization. The client will be restarted with the new configuration
- Breaking api change:
ldclient.sdk_key = <KEY>
replaced with:ldclient.set_sdk_key('<KEY>')
- Breaking api change:
ldclient.config = config
replaced with:ldclient.set_config(config)
- No longer depend on sseclient library, instead include our own sse client
- Add backoff when retrying stream connection.
- More correct initialized state.
- Better error handling when sending events.
- Now using jsonpickle to serialize analytics events. Addresses launchdarkly#57
- Better handling of indirect/put and indirect/patch messages in streaming connection.
- Twisted support for LDD mode only.
- FeatureStore interface get() and all() methods now take an additional callback parameter.
- Support for multivariate feature flags.
variation
replacestoggle
and can return a string, number, dict, or boolean value depending on how the flag is defined. - New
all_flags
method returns all flag values for a specified user. - New
secure_mode_hash
function computes a hash suitable for the new LaunchDarkly JavaScript client's secure mode feature.
- The
toggle
call has been deprecated in favor ofvariation
.
- Twisted support has temporarily been removed.