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
Use Environment variable to initialize client #700
Comments
@jensenbox Thanks for reaching out! I don't think we should try to automatically read the API key from an environment variable like this and instead let the developers control this themselves in their own code. I agree that repeating it everywhere can be annoying though I'd recommend having an init function for Stripe that your own code just relies on instead. I'll flag internally for discussion though to see if others on the team think it could be a good addition in the future. |
Thanks for the speedy reply. I think the reading of the env var is a pretty standard practice nowadays. I get that this would be a core change and potentially destabilize the world if it was implemented wrong but I think the net effect of adding the line I suggested should make it work identically in the load order. I did do a blame on the code and noticed that particular line is 10 years old :) I think it would be worthwhile to at least drop it in and test it out. |
We wouldn't just "drop it in" for sure. It's a core behaviour change and quite risky to do without a major version so even if we did this, it'd still be in the future as we group this change with a lot of other breaking changes. The stripe-python library only had one major version released since its creation and we try to minimize breaking changes as much as possible! |
Thanks for opening this issue @jensenbox. I don't think it's likely we will add this, but I'm leaving it open as "speculative" for now in hopes of soliciting feedback from more users. I'm worried that it could confuse users to support setting That said, many other SDKs do support this. |
While it is entirely possible to set the
api_key
of the imported stripe object, when using the stripe object in various locations in a project it is inconvenient to require the inclusion of thestripe.api_key
line redundantly in every module.I propose that as a fallback, use the
STRIPE_API_KEY
key as an environment variable.I would be more than happy to provide a PR with the proposal I am making if that is a desired path.
Effectively it would be taking the following line: https://github.com/stripe/stripe-python/blob/master/stripe/__init__.py#L14 and making it read something like:
api_key = os.environ.get("STRIPE_API_KEY")
In the world of Cloud and Containerization, I suspect this is a very much desired feature.
The text was updated successfully, but these errors were encountered: