flagsmith 5.4.0__tar.gz → 6.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,21 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flagsmith
3
- Version: 5.4.0
3
+ Version: 6.0.0
4
4
  Summary: Flagsmith Python SDK
5
5
  License: BSD3
6
6
  License-File: LICENSE
7
7
  Keywords: feature,flag,flagsmith,remote,config
8
8
  Author: Flagsmith
9
9
  Author-email: support@flagsmith.com
10
- Requires-Python: >=3.9,<4
10
+ Requires-Python: >=3.10,<4
11
11
  Classifier: License :: Other/Proprietary License
12
12
  Classifier: Programming Language :: Python :: 3
13
- Classifier: Programming Language :: Python :: 3.9
14
13
  Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
17
16
  Classifier: Programming Language :: Python :: 3.13
18
17
  Classifier: Programming Language :: Python :: 3.14
19
- Requires-Dist: flagsmith-flag-engine (>=10.0.4,<11.0.0)
18
+ Requires-Dist: flagsmith-flag-engine (>=10.2.0,<11.0.0)
20
19
  Requires-Dist: iso8601 (>=2.1.0,<3.0.0) ; python_version < "3.11"
21
20
  Requires-Dist: requests (>=2.32.3,<3.0.0)
22
21
  Requires-Dist: requests-futures (>=1.0.1,<2.0.0)
@@ -39,6 +39,7 @@ class FeatureSegmentModel(typing.TypedDict):
39
39
 
40
40
  class MultivariateFeatureOptionModel(typing.TypedDict):
41
41
  value: str
42
+ key: NotRequired[typing.Optional[str]]
42
43
 
43
44
 
44
45
  class MultivariateFeatureStateValueModel(typing.TypedDict):
@@ -357,16 +357,17 @@ class Flagsmith:
357
357
 
358
358
  Skips the exposure event when the resolved flag is a `DefaultFlag`
359
359
  (i.e. the feature was not present and was served via the
360
- `default_flag_handler`), to keep experimentation data clean.
360
+ `default_flag_handler`) or when the feature is disabled, to keep
361
+ experimentation data clean.
361
362
  """
362
363
  if not self._event_processor:
363
364
  raise ValueError("Events must be enabled to use experiment flags.")
364
365
  flag = self.get_identity_flags(identifier, traits).get_flag(feature_name)
365
- if not flag.is_default:
366
+ if isinstance(flag, Flag) and flag.enabled:
366
367
  self.track_exposure_event(
367
368
  feature_name=feature_name,
368
369
  identifier=identifier,
369
- value=flag.value,
370
+ value=flag.variant if flag.variant is not None else flag.value,
370
371
  traits=traits,
371
372
  )
372
373
  return flag
@@ -7,6 +7,7 @@ from datetime import datetime, timezone
7
7
  import sseclient
8
8
  from flag_engine.context.types import (
9
9
  FeatureContext,
10
+ FeatureValue,
10
11
  SegmentContext,
11
12
  SegmentRule,
12
13
  StrValueSegmentCondition,
@@ -245,11 +246,13 @@ def _map_environment_document_feature_states_to_feature_contexts(
245
246
  if multivariate_feature_state_values := feature_state.get(
246
247
  "multivariate_feature_state_values"
247
248
  ):
248
- feature_context["variants"] = [
249
- {
250
- "value": multivariate_feature_state_value[
251
- "multivariate_feature_option"
252
- ]["value"],
249
+ variants: list[FeatureValue] = []
250
+ for multivariate_feature_state_value in multivariate_feature_state_values:
251
+ multivariate_feature_option = multivariate_feature_state_value[
252
+ "multivariate_feature_option"
253
+ ]
254
+ variant: FeatureValue = {
255
+ "value": multivariate_feature_option["value"],
253
256
  "weight": multivariate_feature_state_value["percentage_allocation"],
254
257
  "priority": (
255
258
  multivariate_feature_state_value.get("id")
@@ -258,8 +261,10 @@ def _map_environment_document_feature_states_to_feature_contexts(
258
261
  ).int
259
262
  ),
260
263
  }
261
- for multivariate_feature_state_value in multivariate_feature_state_values
262
- ]
264
+ if (key := multivariate_feature_option.get("key")) is not None:
265
+ variant["key"] = key
266
+ variants.append(variant)
267
+ feature_context["variants"] = variants
263
268
 
264
269
  if feature_segment := feature_state.get("feature_segment"):
265
270
  feature_context["priority"] = feature_segment["priority"]
@@ -51,6 +51,7 @@ class DefaultFlag(BaseFlag):
51
51
  class Flag(BaseFlag):
52
52
  feature_id: int
53
53
  feature_name: str
54
+ variant: typing.Optional[str] = None
54
55
  is_default: bool = field(default=False)
55
56
 
56
57
  @classmethod
@@ -64,6 +65,7 @@ class Flag(BaseFlag):
64
65
  value=flag_result["value"],
65
66
  feature_name=flag_result["name"],
66
67
  feature_id=metadata["id"],
68
+ variant=flag_result.get("variant"),
67
69
  )
68
70
  raise ValueError(
69
71
  "FlagResult metadata is missing. Cannot create Flag instance. "
@@ -77,6 +79,7 @@ class Flag(BaseFlag):
77
79
  value=flag_data["feature_state_value"],
78
80
  feature_name=flag_data["feature"]["name"],
79
81
  feature_id=flag_data["feature"]["id"],
82
+ variant=flag_data.get("variant"),
80
83
  )
81
84
 
82
85
 
@@ -2,7 +2,6 @@ from __future__ import annotations
2
2
 
3
3
  import logging
4
4
  import threading
5
- import time
6
5
  import typing
7
6
 
8
7
  if typing.TYPE_CHECKING:
@@ -26,8 +25,11 @@ class EnvironmentDataPollingManager(threading.Thread):
26
25
 
27
26
  def run(self) -> None:
28
27
  while not self._stop_event.is_set():
29
- self.main.update_environment()
30
- time.sleep(self.refresh_interval_seconds)
28
+ try:
29
+ self.main.update_environment()
30
+ except Exception:
31
+ logger.exception("Error updating environment")
32
+ self._stop_event.wait(self.refresh_interval_seconds)
31
33
 
32
34
  def stop(self) -> None:
33
35
  self._stop_event.set()
@@ -40,8 +40,9 @@ class EventStreamManager(threading.Thread):
40
40
  for event in sse_client.events():
41
41
  self.on_event(map_sse_event_to_stream_event(event))
42
42
 
43
- except (requests.RequestException, ValueError, TypeError):
43
+ except Exception:
44
44
  logger.exception("Error opening or reading from the event stream")
45
+ self._stop_event.wait(1)
45
46
 
46
47
  def stop(self) -> None:
47
48
  self._stop_event.set()
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "flagsmith"
3
- version = "5.4.0"
3
+ version = "6.0.0"
4
4
  description = "Flagsmith Python SDK"
5
5
  authors = ["Flagsmith <support@flagsmith.com>"]
6
6
  license = "BSD3"
@@ -10,9 +10,9 @@ documentation = "https://docs.flagsmith.com"
10
10
  packages = [{ include = "flagsmith" }]
11
11
 
12
12
  [tool.poetry.dependencies]
13
- flagsmith-flag-engine = "^10.0.4"
13
+ flagsmith-flag-engine = "^10.2.0"
14
14
  iso8601 = { version = "^2.1.0", python = "<3.11" }
15
- python = ">=3.9,<4"
15
+ python = ">=3.10,<4"
16
16
  requests = "^2.32.3"
17
17
  requests-futures = "^1.0.1"
18
18
  sseclient-py = "^1.8.0"
@@ -22,11 +22,11 @@ typing-extensions = "^4.15.0"
22
22
  optional = true
23
23
 
24
24
  [tool.poetry.group.dev.dependencies]
25
- mypy = { version = "^1.16.1", python = ">=3.9,<4" }
26
- pytest = "^7.4.0"
25
+ mypy = "^1.16.1"
26
+ pytest = ">=7.4,<10.0"
27
27
  pytest-cov = "^4.1.0"
28
28
  pytest-mock = "^3.6.1"
29
- pre-commit = { version = "^4.2.0", python = ">=3.9,<4" }
29
+ pre-commit = "^4.2.0"
30
30
  responses = "^0.24.1"
31
31
  types-requests = "^2.32"
32
32
  pyfakefs = "^5.9.2"
@@ -35,7 +35,7 @@ pyfakefs = "^5.9.2"
35
35
  exclude = ["example/*"]
36
36
 
37
37
  [tool.black]
38
- target-version = ["py39"]
38
+ target-version = ["py310"]
39
39
 
40
40
  [build-system]
41
41
  requires = ["poetry-core>=1.0.0"]
File without changes
File without changes
File without changes
File without changes