How to hide my API key from my web application #151885
Answered
by
DulangaDasanayake
grahamj89
asked this question in
Code Security
-
Select Topic AreaQuestion BodyI want to know how to hide my API key from my web application. I can't publicly share it, also I don't want make my repository private. Any help is much appreciated a lot. |
Beta Was this translation helpful? Give feedback.
Answered by
DulangaDasanayake
Feb 20, 2025
Replies: 1 comment 1 reply
-
Hi, @grahamj89 To keep your API key secure while still keeping your repository public, you can follow these steps:
This way, the API key is never exposed in your codebase, and you can still keep your repository public. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
grahamj89
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, @grahamj89
To keep your API key secure while still keeping your repository public, you can follow these steps:
Use Environment Variables:
os
module to access these variables. This prevents the key from being hardcoded into your application code.Add
.env
File:.env
file in your project root and store the API key there. Use thepython-dotenv
package to load environment variables from this file..env
:python-dotenv
:.env
variables in your app: