-
Notifications
You must be signed in to change notification settings - Fork 6
chore: change openfeature requirement to compatible patch versions #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
61542b3
chore: change openfeature requirement to compatible patch versions
jsalaber 29a2513
update the typing to match openfeature
suthar26 cb8eb5d
lint
suthar26 d25d6ac
fix type checking
suthar26 c43afbc
Apply suggestion from @Copilot
suthar26 6a5f0d7
update openfeature test
suthar26 af10986
lint
suthar26 d72dfc9
lint
suthar26 35307fd
lint
suthar26 2028f91
lint
suthar26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,19 +7,32 @@ | |
| from openfeature import api | ||
| from openfeature.evaluation_context import EvaluationContext | ||
|
|
||
| FLAG_KEY = "test-boolean-variable" | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def main(): | ||
| """ | ||
| Sample usage of the DevCycle OpenFeature Provider along with the Python Server SDK using Local Bucketing. | ||
|
|
||
| This example demonstrates how to use all variable types supported by DevCycle through OpenFeature: | ||
| - Boolean variables | ||
| - String variables | ||
| - Number variables (integer and float) | ||
| - JSON object variables | ||
|
|
||
| See DEVCYCLE_SETUP.md for instructions on creating the required variables in DevCycle. | ||
| """ | ||
| logging.basicConfig(level="INFO", format="%(levelname)s: %(message)s") | ||
|
|
||
| # create an instance of the DevCycle Client object | ||
| server_sdk_key = os.environ["DEVCYCLE_SERVER_SDK_KEY"] | ||
| server_sdk_key = os.environ.get("DEVCYCLE_SERVER_SDK_KEY") | ||
| if not server_sdk_key: | ||
| logger.error("DEVCYCLE_SERVER_SDK_KEY environment variable is not set") | ||
| logger.error( | ||
| "Please set it with: export DEVCYCLE_SERVER_SDK_KEY='your-sdk-key'" | ||
| ) | ||
| exit(1) | ||
|
|
||
| devcycle_client = DevCycleLocalClient(server_sdk_key, DevCycleLocalOptions()) | ||
|
|
||
| # Wait for DevCycle to initialize and load the configuration | ||
|
|
@@ -32,6 +45,8 @@ def main(): | |
| logger.error("DevCycle failed to initialize") | ||
| exit(1) | ||
|
|
||
| logger.info("DevCycle initialized successfully!\n") | ||
|
|
||
| # set the provider for OpenFeature | ||
| api.set_provider(devcycle_client.get_openfeature_provider()) | ||
|
|
||
|
|
@@ -53,22 +68,168 @@ def main(): | |
| }, | ||
| ) | ||
|
|
||
| # Look up the value of the flag | ||
| if open_feature_client.get_boolean_value(FLAG_KEY, False, context): | ||
| logger.info(f"Variable {FLAG_KEY} is enabled") | ||
| logger.info("=" * 60) | ||
| logger.info("Testing Boolean Variable") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test Boolean Variable | ||
| boolean_details = open_feature_client.get_boolean_details( | ||
| "test-boolean-variable", False, context | ||
| ) | ||
| logger.info("Variable Key: test-boolean-variable") | ||
| logger.info("Value: {boolean_details.value}") | ||
| logger.info("Reason: {boolean_details.reason}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if boolean_details.value: | ||
| logger.info("✓ Boolean variable is ENABLED") | ||
| else: | ||
| logger.info(f"Variable {FLAG_KEY} is not enabled") | ||
| logger.info("✗ Boolean variable is DISABLED") | ||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing String Variable") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Fetch a JSON object variable | ||
| json_object = open_feature_client.get_object_value( | ||
| # Test String Variable | ||
| open_feature_client.get_string_details( | ||
| "test-string-variable", "default string", context | ||
| ) | ||
| logger.info("Variable Key: test-string-variable") | ||
| logger.info("Value: {string_details.value}") | ||
| logger.info("Reason: {string_details.reason}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing Number Variable (Integer)") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test Number Variable (Integer) | ||
| open_feature_client.get_integer_details("test-number-variable", 0, context) | ||
| logger.info("Variable Key: test-number-variable") | ||
| logger.info("Value: {integer_details.value}") | ||
| logger.info("Reason: {integer_details.reason}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing Number Variable (Float)") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test Number Variable as Float | ||
| # Note: If the DevCycle variable is an integer, it will be cast to float | ||
| open_feature_client.get_float_value("test-number-variable", 0.0, context) | ||
| logger.info("Variable Key: test-number-variable (as float)") | ||
| logger.info("Value: {float_value}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing JSON Object Variable") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test JSON Object Variable | ||
| open_feature_client.get_object_details( | ||
| "test-json-variable", {"default": "value"}, context | ||
| ) | ||
| logger.info(f"JSON Object Value: {json_object}") | ||
| logger.info("Variable Key: test-json-variable") | ||
| logger.info("Value: {json_details.value}") | ||
| logger.info("Reason: {json_details.reason}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing Object Variable - Empty Dictionary") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test with empty dictionary default (valid per OpenFeature spec) | ||
| open_feature_client.get_object_value("test-json-variable", {}, context) | ||
| logger.info("Variable Key: test-json-variable (with empty default)") | ||
| logger.info("Value: {empty_dict_result}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing Object Variable - Mixed Types") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test with flat dictionary containing mixed primitive types | ||
| # OpenFeature allows string, int, float, bool, and None in flat dictionaries | ||
| mixed_default = { | ||
| "string_key": "hello", | ||
| "int_key": 42, | ||
| "float_key": 3.14, | ||
| "bool_key": True, | ||
| "none_key": None, | ||
| } | ||
| mixed_result = open_feature_client.get_object_value( | ||
| "test-json-variable", mixed_default, context | ||
| ) | ||
| logger.info("Variable Key: test-json-variable (with mixed types)") | ||
| logger.info("Value: {mixed_result}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| logger.info( | ||
| f"Value types: {[(k, type(v).__name__) for k, v in mixed_result.items()]}" | ||
| ) | ||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing Object Variable - All String Values") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test with all string values | ||
| string_dict_default = { | ||
| "name": "John Doe", | ||
| "email": "[email protected]", | ||
| "status": "active", | ||
| } | ||
| open_feature_client.get_object_value( | ||
| "test-json-variable", string_dict_default, context | ||
| ) | ||
| logger.info("Variable Key: test-json-variable (all strings)") | ||
| logger.info("Value: {string_dict_result}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing Object Variable - Numeric Values") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test with numeric values (integers and floats) | ||
| numeric_dict_default = {"count": 100, "percentage": 85.5, "threshold": 0} | ||
| open_feature_client.get_object_value( | ||
| "test-json-variable", numeric_dict_default, context | ||
| ) | ||
| logger.info("Variable Key: test-json-variable (numeric)") | ||
| logger.info("Value: {numeric_dict_result}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing Object Variable - Boolean Flags") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test with boolean values | ||
| bool_dict_default = {"feature_a": True, "feature_b": False, "feature_c": True} | ||
| open_feature_client.get_object_value( | ||
| "test-json-variable", bool_dict_default, context | ||
| ) | ||
| logger.info("Variable Key: test-json-variable (booleans)") | ||
| logger.info("Value: {bool_dict_result}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing Object Variable - With None Values") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test with None values (valid per OpenFeature spec for flat dictionaries) | ||
| none_dict_default = { | ||
| "optional_field": None, | ||
| "required_field": "value", | ||
| "nullable_count": None, | ||
| } | ||
| open_feature_client.get_object_value( | ||
| "test-json-variable", none_dict_default, context | ||
| ) | ||
| logger.info("Variable Key: test-json-variable (with None)") | ||
| logger.info("Value: {none_dict_result}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("\n" + "=" * 60) | ||
| logger.info("Testing Non-Existent Variable (Should Return Default)") | ||
| logger.info("=" * 60) | ||
|
|
||
| # Test non-existent variable to demonstrate default handling | ||
| open_feature_client.get_string_details( | ||
| "doesnt-exist", "default fallback value", context | ||
| ) | ||
| logger.info("Variable Key: doesnt-exist") | ||
| logger.info("Value: {nonexistent_details.value}") | ||
| logger.info("Reason: {nonexistent_details.reason}") | ||
suthar26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Retrieve a string variable along with resolution details | ||
| details = open_feature_client.get_string_details("doesnt-exist", "default", context) | ||
| logger.info(f"String Value: {details.value}") | ||
| logger.info(f"Eval Reason: {details.reason}") | ||
| logger.info("\n" + "=" * 60) | ||
| logger.info("All tests completed!") | ||
| logger.info("=" * 60) | ||
|
|
||
| devcycle_client.close() | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.