Skip to content

Commit b1a41c5

Browse files
deps: update dependency flagsmith/sdk-spec to v0.6.0 (#270)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: flagsmithsmith[bot] <346993984+flagsmithsmith[bot]@users.noreply.github.com>
1 parent a7dccd0 commit b1a41c5

3 files changed

Lines changed: 57 additions & 8 deletions

File tree

‎.flake8‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
max-line-length = 120
33
max-complexity = 10
44
exclude = .git,__pycache__,.venv
5+
per-file-ignores =
6+
# Step markers must match the spec step text on a single line.
7+
sdk-spec/steps.py: E501

‎.github/workflows/sdk-spec.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ permissions:
1111
jobs:
1212
sdk-spec:
1313
# Keep the ref in `uses:` and `spec-ref` in sync.
14-
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.3.0
14+
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.6.0
1515
with:
16-
spec-ref: v0.3.0
16+
spec-ref: v0.6.0
1717
language: python

‎sdk-spec/steps.py‎

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,39 @@
66

77
import typing
88

9-
from flagsmith import Flagsmith
10-
from flagsmith.models import Flags
9+
from flagsmith import EventProcessorConfig, Flagsmith
10+
from flagsmith.models import Flag, Flags
1111
from flagsmith.types import TraitMapping
1212

1313
SpecFlag = dict[str, typing.Any]
14+
EventValue = typing.Union[str, int, float, bool]
15+
16+
17+
def as_spec_flag(flag: Flag) -> SpecFlag:
18+
return {"feature": flag.feature_name, "enabled": flag.enabled, "value": flag.value}
1419

1520

1621
def as_spec_flags(flags: Flags) -> list[SpecFlag]:
17-
return [
18-
{"feature": flag.feature_name, "enabled": flag.enabled, "value": flag.value}
19-
for flag in flags.all_flags()
20-
]
22+
return [as_spec_flag(flag) for flag in flags.all_flags()]
2123

2224

2325
# Create the SDK client
2426
def create_client(environment_key: str, api_url: str) -> Flagsmith:
2527
return Flagsmith(environment_key=environment_key, api_url=api_url)
2628

2729

30+
# Create the SDK client with events enabled
31+
def create_client_with_events(
32+
environment_key: str, api_url: str, events_api_url: str
33+
) -> Flagsmith:
34+
return Flagsmith(
35+
environment_key=environment_key,
36+
api_url=api_url,
37+
enable_events=True,
38+
event_processor_config=EventProcessorConfig(events_api_url=events_api_url),
39+
)
40+
41+
2842
# When the application gets the environment flags
2943
def get_environment_flags(flagsmith: Flagsmith) -> list[SpecFlag]:
3044
return as_spec_flags(flagsmith.get_environment_flags())
@@ -35,3 +49,35 @@ def get_identity_flags(
3549
flagsmith: Flagsmith, identifier: str, traits: TraitMapping
3650
) -> list[SpecFlag]:
3751
return as_spec_flags(flagsmith.get_identity_flags(identifier, traits=traits))
52+
53+
54+
# When the application gets the experiment flag "{feature}" for identity "{identifier}" with traits:
55+
def get_experiment_flag(
56+
flagsmith: Flagsmith, feature: str, identifier: str, traits: TraitMapping
57+
) -> list[SpecFlag]:
58+
flag = flagsmith.get_experiment_flag(feature, identifier, traits)
59+
return [as_spec_flag(flag)] if isinstance(flag, Flag) else []
60+
61+
62+
# When the application tracks event "{event}" for identity "{identifier}" with value {value} and metadata:
63+
def track_event(
64+
flagsmith: Flagsmith,
65+
event: str,
66+
identifier: str,
67+
value: EventValue,
68+
metadata: dict[str, typing.Any],
69+
) -> None:
70+
flagsmith.track_event(event, identifier=identifier, value=value, metadata=metadata)
71+
72+
73+
# When the application tracks an exposure of feature "{feature}" for identity "{identifier}" with value {value} and metadata:
74+
def track_exposure_event(
75+
flagsmith: Flagsmith,
76+
feature: str,
77+
identifier: str,
78+
value: EventValue,
79+
metadata: dict[str, typing.Any],
80+
) -> None:
81+
flagsmith.track_exposure_event(
82+
feature, identifier=identifier, value=value, metadata=metadata
83+
)

0 commit comments

Comments
 (0)