flagdock 0.3.2__tar.gz → 0.4.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.
- {flagdock-0.3.2 → flagdock-0.4.0}/PKG-INFO +9 -6
- {flagdock-0.3.2 → flagdock-0.4.0}/README.md +8 -5
- {flagdock-0.3.2 → flagdock-0.4.0}/pyproject.toml +1 -1
- {flagdock-0.3.2 → flagdock-0.4.0}/src/flagdock/engine.py +31 -2
- {flagdock-0.3.2 → flagdock-0.4.0}/src/flagdock/provider.py +4 -3
- {flagdock-0.3.2 → flagdock-0.4.0}/.gitignore +0 -0
- {flagdock-0.3.2 → flagdock-0.4.0}/LICENSE +0 -0
- {flagdock-0.3.2 → flagdock-0.4.0}/src/flagdock/__init__.py +0 -0
- {flagdock-0.3.2 → flagdock-0.4.0}/src/flagdock/_usage.py +0 -0
- {flagdock-0.3.2 → flagdock-0.4.0}/src/flagdock/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: flagdock
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Flagdock feature flags for Python: an OpenFeature provider that downloads the rules once and evaluates in memory
|
|
5
5
|
Project-URL: Homepage, https://flagdock.com
|
|
6
6
|
Author-email: Flagdock <info@flagdock.com>
|
|
@@ -47,14 +47,16 @@ The only dependency is `openfeature-sdk`; HTTP uses the standard library. Python
|
|
|
47
47
|
from openfeature.evaluation_context import EvaluationContext
|
|
48
48
|
from flagdock import FlagdockProvider
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
provider = FlagdockProvider(os.environ["FLAGDOCK_KEY"], app_name="checkout-api")
|
|
51
|
+
api.set_provider_and_wait(provider)
|
|
51
52
|
flags = api.get_client()
|
|
52
53
|
|
|
53
54
|
if flags.get_boolean_value("new-checkout", False, EvaluationContext(user.id, {"plan": user.plan})):
|
|
54
55
|
... # the new code path
|
|
55
56
|
```
|
|
56
57
|
|
|
57
|
-
Call `api.shutdown()` when
|
|
58
|
+
`EvaluationContext(targeting_key, attributes)` says who is asking. Call `api.shutdown()` when
|
|
59
|
+
the process stops, so the last usage counts are sent.
|
|
58
60
|
|
|
59
61
|
Server keys can read your targeting rules, so keep them on the server.
|
|
60
62
|
|
|
@@ -71,7 +73,7 @@ Server keys can read your targeting rules, so keep them on the server.
|
|
|
71
73
|
| `start_timeout` | `10` | Seconds `initialize` waits for the first download. |
|
|
72
74
|
| `usage_interval` | `60` | Seconds between usage reports; `0` turns reporting off. |
|
|
73
75
|
| `stream` | `True` | Follow changes live; `False` only polls. |
|
|
74
|
-
| `url`, `fallback_urls` |
|
|
76
|
+
| `url`, `fallback_urls` | `https://edge.flagdock.com`, then `https://app.flagdock.com` | Where the rules come from. Leave them out unless you were given another address. |
|
|
75
77
|
|
|
76
78
|
Number flags can be read with `get_integer_value` (whole numbers only) or `get_float_value`, and
|
|
77
79
|
JSON flags with `get_object_value`. While Flagdock can't be reached, answers carry the reason
|
|
@@ -86,8 +88,9 @@ epoch milliseconds, `datetime` and `date` values.
|
|
|
86
88
|
rules). Put it in the page as JSON and pass it as `bootstrap` to `@flagdock/web` or
|
|
87
89
|
`@flagdock/react`, so the browser shows the right values in its first render.
|
|
88
90
|
- `provider.rotate_key(new_key)` switches keys without a restart.
|
|
89
|
-
- `
|
|
90
|
-
reports a goal event, which the console uses to compare the values of a flag
|
|
91
|
+
- `flags.track("order-completed", EvaluationContext(user.id), TrackingEventDetails(value=order.total))`
|
|
92
|
+
reports a goal event, which the console uses to compare the values of a flag
|
|
93
|
+
(`from openfeature.track import TrackingEventDetails`).
|
|
91
94
|
- The provider is thread safe; with forking servers (gunicorn, uWSGI) create it in each worker
|
|
92
95
|
after the fork.
|
|
93
96
|
|
|
@@ -28,14 +28,16 @@ The only dependency is `openfeature-sdk`; HTTP uses the standard library. Python
|
|
|
28
28
|
from openfeature.evaluation_context import EvaluationContext
|
|
29
29
|
from flagdock import FlagdockProvider
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
provider = FlagdockProvider(os.environ["FLAGDOCK_KEY"], app_name="checkout-api")
|
|
32
|
+
api.set_provider_and_wait(provider)
|
|
32
33
|
flags = api.get_client()
|
|
33
34
|
|
|
34
35
|
if flags.get_boolean_value("new-checkout", False, EvaluationContext(user.id, {"plan": user.plan})):
|
|
35
36
|
... # the new code path
|
|
36
37
|
```
|
|
37
38
|
|
|
38
|
-
Call `api.shutdown()` when
|
|
39
|
+
`EvaluationContext(targeting_key, attributes)` says who is asking. Call `api.shutdown()` when
|
|
40
|
+
the process stops, so the last usage counts are sent.
|
|
39
41
|
|
|
40
42
|
Server keys can read your targeting rules, so keep them on the server.
|
|
41
43
|
|
|
@@ -52,7 +54,7 @@ Server keys can read your targeting rules, so keep them on the server.
|
|
|
52
54
|
| `start_timeout` | `10` | Seconds `initialize` waits for the first download. |
|
|
53
55
|
| `usage_interval` | `60` | Seconds between usage reports; `0` turns reporting off. |
|
|
54
56
|
| `stream` | `True` | Follow changes live; `False` only polls. |
|
|
55
|
-
| `url`, `fallback_urls` |
|
|
57
|
+
| `url`, `fallback_urls` | `https://edge.flagdock.com`, then `https://app.flagdock.com` | Where the rules come from. Leave them out unless you were given another address. |
|
|
56
58
|
|
|
57
59
|
Number flags can be read with `get_integer_value` (whole numbers only) or `get_float_value`, and
|
|
58
60
|
JSON flags with `get_object_value`. While Flagdock can't be reached, answers carry the reason
|
|
@@ -67,8 +69,9 @@ epoch milliseconds, `datetime` and `date` values.
|
|
|
67
69
|
rules). Put it in the page as JSON and pass it as `bootstrap` to `@flagdock/web` or
|
|
68
70
|
`@flagdock/react`, so the browser shows the right values in its first render.
|
|
69
71
|
- `provider.rotate_key(new_key)` switches keys without a restart.
|
|
70
|
-
- `
|
|
71
|
-
reports a goal event, which the console uses to compare the values of a flag
|
|
72
|
+
- `flags.track("order-completed", EvaluationContext(user.id), TrackingEventDetails(value=order.total))`
|
|
73
|
+
reports a goal event, which the console uses to compare the values of a flag
|
|
74
|
+
(`from openfeature.track import TrackingEventDetails`).
|
|
72
75
|
- The provider is thread safe; with forking servers (gunicorn, uWSGI) create it in each worker
|
|
73
76
|
after the fork.
|
|
74
77
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "flagdock"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "Flagdock feature flags for Python: an OpenFeature provider that downloads the rules once and evaluates in memory"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -461,6 +461,8 @@ class Resolution:
|
|
|
461
461
|
rule_index: Optional[int] = None
|
|
462
462
|
bucket: Optional[int] = None
|
|
463
463
|
prerequisite: Optional[str] = None
|
|
464
|
+
#: True when a rule's slice kept this person out (another test's people, or the holdout) and no later rule matched.
|
|
465
|
+
excluded: bool = False
|
|
464
466
|
|
|
465
467
|
def to_dict(self) -> dict[str, Any]:
|
|
466
468
|
"""The same keys the TypeScript engine uses, leaving out the ones that are not set."""
|
|
@@ -477,6 +479,8 @@ class Resolution:
|
|
|
477
479
|
v = getattr(self, name)
|
|
478
480
|
if v is not None:
|
|
479
481
|
out[key] = v
|
|
482
|
+
if self.excluded:
|
|
483
|
+
out["excluded"] = True
|
|
480
484
|
return out
|
|
481
485
|
|
|
482
486
|
|
|
@@ -530,6 +534,18 @@ def _rule_matches(
|
|
|
530
534
|
return False, None
|
|
531
535
|
|
|
532
536
|
|
|
537
|
+
def _in_slices(rule: Mapping[str, Any], context: Mapping[str, Any]) -> bool:
|
|
538
|
+
"""Whether the person's bucket for every slice of the rule is inside it."""
|
|
539
|
+
value = _bucket_value(rule, context)
|
|
540
|
+
for s in rule.get("slices") or []:
|
|
541
|
+
if value is None:
|
|
542
|
+
return False
|
|
543
|
+
bucket = rollout_bucket(s.get("salt"), value)
|
|
544
|
+
if not (s.get("from") <= bucket < s.get("to")):
|
|
545
|
+
return False
|
|
546
|
+
return True
|
|
547
|
+
|
|
548
|
+
|
|
533
549
|
def _pick_from_split(
|
|
534
550
|
split: Sequence[Mapping[str, Any]], rule: Mapping[str, Any], flag: Mapping[str, Any], context: Mapping[str, Any]
|
|
535
551
|
) -> Optional[str]:
|
|
@@ -609,6 +625,7 @@ def _evaluate_at(
|
|
|
609
625
|
rule_index: Optional[int] = None,
|
|
610
626
|
bucket: Optional[int] = None,
|
|
611
627
|
prerequisite: Optional[str] = None,
|
|
628
|
+
excluded: bool = False,
|
|
612
629
|
) -> tuple[Resolution, bool]:
|
|
613
630
|
if not isinstance(value_key, str) or value_key not in values:
|
|
614
631
|
return Resolution(
|
|
@@ -626,7 +643,14 @@ def _evaluate_at(
|
|
|
626
643
|
error_message=f'Value "{value_key}" of flag "{flag_key}" is not a {flag.get("kind")}',
|
|
627
644
|
), False
|
|
628
645
|
resolved = Resolution(
|
|
629
|
-
value,
|
|
646
|
+
value,
|
|
647
|
+
reason,
|
|
648
|
+
value_key=value_key,
|
|
649
|
+
rule_id=rule_id,
|
|
650
|
+
rule_index=rule_index,
|
|
651
|
+
bucket=bucket,
|
|
652
|
+
prerequisite=prerequisite,
|
|
653
|
+
excluded=excluded,
|
|
630
654
|
)
|
|
631
655
|
return resolved, False
|
|
632
656
|
|
|
@@ -654,8 +678,13 @@ def _evaluate_at(
|
|
|
654
678
|
return serve(flag.get("offValue"), "PREREQUISITE_FAILED", prerequisite=prerequisite.get("flag"))
|
|
655
679
|
|
|
656
680
|
last_bucket: Optional[int] = None
|
|
681
|
+
excluded = False
|
|
657
682
|
for i, rule in enumerate(flag.get("rules") or []):
|
|
658
683
|
matched, bucket = _rule_matches(rule, flag, ruleset, context)
|
|
684
|
+
# Slices only matter to someone the rule would otherwise take.
|
|
685
|
+
if matched and rule.get("slices") and not _in_slices(rule, context):
|
|
686
|
+
matched = False
|
|
687
|
+
excluded = True
|
|
659
688
|
if bucket is not None:
|
|
660
689
|
last_bucket = bucket
|
|
661
690
|
if not matched:
|
|
@@ -670,4 +699,4 @@ def _evaluate_at(
|
|
|
670
699
|
value_key = served.get("value") if isinstance(served, Mapping) and served.get("value") is not None else flag.get("matchValue")
|
|
671
700
|
return serve(value_key, "TARGETING_MATCH", rule.get("id"), i, bucket)
|
|
672
701
|
|
|
673
|
-
return serve(flag.get("defaultValue"), "DEFAULT", bucket=last_bucket)
|
|
702
|
+
return serve(flag.get("defaultValue"), "DEFAULT", bucket=last_bucket, excluded=excluded)
|
|
@@ -23,7 +23,7 @@ from . import engine
|
|
|
23
23
|
from ._usage import ActivityLog, UsageCounter
|
|
24
24
|
|
|
25
25
|
SDK_NAME = "python"
|
|
26
|
-
SDK_VERSION = "0.
|
|
26
|
+
SDK_VERSION = "0.4.0"
|
|
27
27
|
DEFAULT_URL = "https://edge.flagdock.com"
|
|
28
28
|
DEFAULT_FALLBACK_URL = "https://app.flagdock.com"
|
|
29
29
|
|
|
@@ -481,8 +481,9 @@ class FlagdockProvider(AbstractProvider):
|
|
|
481
481
|
if self._usage_interval > 0:
|
|
482
482
|
self._usage.record(flag_key, r.value_key)
|
|
483
483
|
user = ctx.get("targetingKey")
|
|
484
|
-
# Who got which value, so goals can be compared. Only for people the app identifies
|
|
485
|
-
|
|
484
|
+
# Who got which value, so goals can be compared. Only for people the app identifies, and not for
|
|
485
|
+
# people a slice kept out of a test (another test's people, or the holdout).
|
|
486
|
+
if r.value_key is not None and isinstance(user, str) and user != "" and not r.excluded:
|
|
486
487
|
self._activity.expose(flag_key, r.value_key, user)
|
|
487
488
|
if r.reason == "ERROR":
|
|
488
489
|
return r, FlagResolutionDetails(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|