featurehub-io / featurehub-python-sdk

Official FeatureHub Python SDK
MIT License
11 stars 1 forks source link

Using multiple keys? #20

Open ilyatovbin-pp opened 1 year ago

ilyatovbin-pp commented 1 year ago

Use-case: I have Per-App Features, and then I have another app called Global which has Features on a global scale enabling or disabling larger chunks of code for multiple apps and environments. also I have string Features that are used by multiple apps.

I saw that the API key is a list, so I've tried putting in two keys, expecting the repository to load Features from both apps I need, but from what I see it uses only the first one.

If this is as expected, there's no point in using a list when creating a FeatureHubConfig object.

config = FeatureHubConfig(edge_url, [key1,key2])
asyncio.run(config.init())
while not config.repository().is_ready():
    time.sleep(0.1)
client = config.new_context().build_sync()
client._repository.features.items()

The above example shows only the Features available only for key1

Expected result:

rvowles commented 1 year ago

Hey @ilyatovbin-pp, are you using SSE? SSE only supports one of the keys, it isn't able to support both. The GET API is able to support both. If you wish to use SSE for your client, you will need a bit of hand-coding. Have a look to see what the FeatureHubConfig is actually doing when it puts everything together. You will find it creates a repository and a StreamingEdgeClient, and a FeatureHubRepository. So if instead you do this (sort of)

repo = FeatureHubRepository() config = FeatureHubConfig(edge_url, [key1]) config.repository(repo) StreamingEdgeClient(edge_url, [key1], repo) asyncio.run(config.init())

That will essentially get you around this for the time being. The reason it will work, even if you are using strategies is because the evaluation is done in the client side.

ilyatovbin-pp commented 1 year ago

I didn't quite understand how that helps me but I'll play around with it later and see if I can figure it out.