Hi folks!! I just started using GB with Python. Ho...
# ask-questions
n
Hi folks!! I just started using GB with Python. How do I tell the SDK in which environment it is running. I created a staging environment but the feature flag only works when the production environment is activated. Thanks
b
Hey Luis - you can create another SDK Connection and specify the
environment
there. Most orgs then set the
api_host
and
client_key
as env variables.
n
Thanks Michael. This is my code. I don't were to tell the connection it is using a staging environment, def load_features() -> GrowthBook: gb = GrowthBook( api_host=settings.GROWTHBOOK_API_HOST, client_key=settings.GROWTHBOOK_CLIENT_KEY, on_experiment_viewed=on_experiment_viewed ) gb.load_features() return gb
b
Hmm.. I'm not super familiar with Python and it's associated frameworks. I found this article from Twilio on setting/accessing environment variables in Python.
But... looking at your code, it looks like
GROWTHBOOK_API-HOST
and
GROWTHBOOK_CLIENT_KEY
may already be environment variables. Typically, environment variables are stored in a
.env
file.
n
But how does GB know in which environment it is runnning?
Is there an environment variable that GB will read?
b
No, depending on the environment, your code should pass in a different
GROWTHBOOK_CLIENT_KEY
- that client key is what tells GrowthBook which environment it needs to evaluate features for.
n
Ohhh Ok. I will try that. Thank you so much!!
👍 1
b
You bet! Sorry if I misunderstood your original question.
n
No worries. I really apprecaite it.