Skip to content
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

Open
jensenbox opened this issue Dec 17, 2020 · 4 comments
Open

Use Environment variable to initialize client #700

jensenbox opened this issue Dec 17, 2020 · 4 comments
Assignees

Comments

@jensenbox
Copy link

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 the stripe.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.

@remi-stripe
Copy link
Contributor

@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.

@remi-stripe remi-stripe self-assigned this Dec 17, 2020
@jensenbox
Copy link
Author

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.

@remi-stripe
Copy link
Contributor

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!

@richardm-stripe
Copy link
Contributor

richardm-stripe commented Dec 21, 2020

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 stripe.api_key via environment variable without allowing the other configuration options e.g. stripe.max_network_retries or stripe.default_http_client to be similarly configured.
I'm also worried that allowing simple configuration to be done via environment variables will discourage users from creating an init function for Stripe like Remi suggested, which will make life more difficult when it is time to try and make a more sophisticated configuration change.

That said, many other SDKs do support this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants