-
Notifications
You must be signed in to change notification settings - Fork 25.3k
add load_dotenv()
to ensure environment variables are loaded
#128045
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
Conversation
💚 CLA has been signed |
Pinging @elastic/es-docs (Team:Docs) |
Hi, thanks for your Elasticsearch PR. I'm routing this to the docs team for review. However, I will make a drive-by comment: I think the docs as they stand work for the basic case. They tell you to set So my 2¢ is that we shouldn't be issuing a blanket advice to make this call (which brings in a dependency on the Also, does the change suggested not require an import to make it work? (Again, I'm not a Python dev, so I could be wrong there.) |
Hi @PeteGillinElastic thank you for the feedback and for routing this to the docs team for review. You are correct that using My intention with the If the Python client section in the README assumes the use of these credentials, it might be helpful to explicitly mention saving the password in an environment variable. For example, after running the setup command:
which outputs:
We could add a note like:
export ELASTIC_PASSWORD=PASSWORD This would clarify how to use the autogenerated credentials with the Python client. However, if my interpretation is incorrect, I’m happy to revise the PR or the suggestion should be simply ignored. Thanks again for your review! |
Ah, thanks for the additional info, your suggestion makes more sense now. I confess that I have never actually used It still seems to me as though using Incidentally, it looks like the |
In case it wasn't clear: I do agree with your basic point that we should make some change here. The section on the python client immediately follows the I'm just not certain which option(s) we should be suggesting 🙁. |
Ah yes, you're absolutely right -- the autogenerated password is saved to Given that the Python client section immediately follows the Source the .env file to load the environment variables and export the elastic user password source .env
export ELASTIC_PASSWORD=$ES_LOCAL_PASSWORD Again, there are probably other better options but this approach at least avoids the |
That general approach sounds reasonable. A few thoughts...
|
…nt variable - Added instructions for exporting the `ES_LOCAL_PASSWORD` environment variable. - Updated the `curl` example and Python client example to use `ES_LOCAL_PASSWORD` for consistency. These changes are based on feedback from the PR discussion with @PeteGillinElastic
@MustaphaU I just saw your latest commit. I like the approach. Please comment when you're happy that it's ready for review. Unless anyone from the docs team happens to jump in soon, I'm happy to take this on myself, I think I have enough context now. |
Thank you @PeteGillinElastic I’m okay with the current state of the changes, and it’s ready for review. Please let me know if there’s anything else I can adjust. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the contribution, and for engaging in the discussion so helpfully.
I can take care of getting this merged now.
buildkite test this |
This is now merged. Congratulations on your first contribution to Elasticsearch, @MustaphaU ! |
Thank you @PeteGillinElastic ! 🎉 |
…nt variable (elastic#128045) - Added instructions for exporting the `ES_LOCAL_PASSWORD` environment variable. - Updated the `curl` example and Python client example to use `ES_LOCAL_PASSWORD` for consistency.
This PR adds
load_dotenv()
to the instructions for using the Python Elasticsearch client to ensure that environment variables, such asELASTIC_PASSWORD
, are properly loaded.Without calling
load_dotenv()
, environment variables defined in a .env file are not loaded into the runtime environment. As a result:returns
None
this leads to the following error when initializing the Elasticsearch client:
Error: