You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2a89743
Browse filesBrowse the repository at this point in the historyBrowse files
Install Featurevisor with its optional OpenFeature dependency:
593
+
The provider targets OpenFeature specification `0.8.0` through OpenFeature Python SDK `0.10.x`. OpenFeature remains optional and is not installed or imported by the base Featurevisor package.
594
+
595
+
### Installation
587
596
588
597
```bash
589
598
pip install "featurevisor[openfeature]"
590
599
```
591
600
601
+
If the extra is not installed, importing `featurevisor.openfeature` reports the installation command needed to enable it.
602
+
603
+
### Provider setup
604
+
592
605
```python
593
606
from featurevisor.openfeature import FeaturevisorOpenFeatureProvider
594
607
from openfeature import api
595
608
from openfeature.evaluation_context import EvaluationContext
Use `checkout` for a flag, `checkout:variation` for its variation, and `checkout:title` for its `title` variable. Boolean variables use the boolean resolver. Sequences, mappings, and JSON variables use the object resolver.
621
+
Call `api.shutdown()` during application shutdown. This closes a Featurevisor instance created by the provider and releases provider subscriptions.
622
+
623
+
### Flag key mapping
624
+
625
+
| OpenFeature key | Featurevisor evaluation |
626
+
| --- | --- |
627
+
|`checkout`| Boolean flag for `checkout`|
628
+
|`checkout:variation`| Variation value for `checkout`|
629
+
|`checkout:title`| Variable `title` for `checkout`|
630
+
631
+
Boolean variables use the boolean resolver. Integer and double variables use their matching numeric resolvers. Arrays, objects, and JSON variables use the object resolver.
632
+
633
+
The first separator divides the feature key from the selector. Use `key_separator` and `variation_key` when project keys require a different grammar:
634
+
635
+
```python
636
+
provider = FeaturevisorOpenFeatureProvider(
637
+
{"datafile": datafile_content},
638
+
key_separator="/",
639
+
variation_key="$variation",
640
+
)
641
+
```
642
+
643
+
This makes `checkout/$variation` the variation key and `checkout/title` a variable key.
609
644
610
-
OpenFeature's targeting key maps to `userId` by default. `targeting_key_field`, `key_separator`, and `variation_key` can customize the mapping.
645
+
### Context mapping
611
646
612
-
You can also reuse an existing Featurevisor instance:
647
+
OpenFeature's targeting key maps to `userId` by default. Use `targeting_key_field` to map it to another Featurevisor context field:
648
+
649
+
```python
650
+
provider = FeaturevisorOpenFeatureProvider(
651
+
{"datafile": datafile_content},
652
+
targeting_key_field="accountId",
653
+
)
654
+
```
655
+
656
+
OpenFeature context attributes are copied without mutating the incoming context. Nested arrays and mappings are preserved. Datetimes are normalized to UTC ISO strings, matching the JavaScript provider.
657
+
658
+
### Resolution details
659
+
660
+
The provider maps Featurevisor evaluation results to OpenFeature details:
661
+
662
+
| Featurevisor result | OpenFeature result |
663
+
| --- | --- |
664
+
| Required, forced, sticky, or rule match |`TARGETING_MATCH`|
665
+
| Traffic allocation |`SPLIT`|
666
+
| Disabled variation or variable |`DISABLED`|
667
+
| No match or variable default |`DEFAULT`|
668
+
| Missing feature, variable, or variations |`ERROR` with `FLAG_NOT_FOUND`|
669
+
| Wrong resolver type |`ERROR` with `TYPE_MISMATCH`|
670
+
| Invalid datafile |`ERROR` with `PARSE_ERROR`|
671
+
| Evaluation failure |`ERROR` with `GENERAL`|
672
+
673
+
Errors return the default value supplied to OpenFeature. A malformed datafile uses the stable message `Could not parse datafile`. A later successful `set_datafile` call clears the parse error.
674
+
675
+
Resolution metadata can include `featureKey`, `variableKey`, `featurevisorReason`, `revision`, `schemaVersion`, `ruleKey`, `bucketKey`, `bucketValue`, `forceIndex`, and `variableOverrideIndex`. The selected variation is exposed as the OpenFeature variant when available.
676
+
677
+
### Tracking
678
+
679
+
Tracking is a no-op unless `on_track` is configured:
680
+
681
+
```python
682
+
defhandle_track(name, context, details):
683
+
print(name, context, details)
684
+
685
+
provider = FeaturevisorOpenFeatureProvider(
686
+
{"datafile": datafile_content},
687
+
on_track=handle_track,
688
+
)
689
+
```
690
+
691
+
### Using an existing Featurevisor instance
613
692
614
693
```python
615
694
from featurevisor import create_featurevisor
@@ -635,14 +714,17 @@ This repository assumes:
635
714
Run the local test suite:
636
715
637
716
```bash
638
-
make test
717
+
python -m pip install -e '.[dev]'
718
+
make check
639
719
```
640
720
721
+
`make check` runs the base SDK tests, OpenFeature provider tests, and static type checking. You can also run them separately with `make test`, `make test-openfeature`, and `make typecheck`.
0 commit comments