https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
n

nutritious-rocket-36971

10/25/2023, 4:10 PM
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

billions-xylophone-11752

10/25/2023, 4:15 PM
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

nutritious-rocket-36971

10/25/2023, 4:18 PM
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

billions-xylophone-11752

10/25/2023, 4:22 PM
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

nutritious-rocket-36971

10/25/2023, 4:24 PM
But how does GB know in which environment it is runnning?
Is there an environment variable that GB will read?
b

billions-xylophone-11752

10/25/2023, 4:25 PM
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

nutritious-rocket-36971

10/25/2023, 4:26 PM
Ohhh Ok. I will try that. Thank you so much!!
👍 1
b

billions-xylophone-11752

10/25/2023, 4:26 PM
You bet! Sorry if I misunderstood your original question.
n

nutritious-rocket-36971

10/25/2023, 4:27 PM
No worries. I really apprecaite it.
16 Views