HOW TO: Hide Sensitive info in Python Using .env?
• You want to use secrets and tokens in your script but don’t want to hardcode them in as strings. We can use environment variables instead.
• Here are the steps:
1. Create `.env` file in the root directory of your project
2. Inside type: `export authToken='yourAuthToken';`
3. In your terminal run: `source .env`
These environment variables only persist for this session. When you open a new terminal, you will have to run source .env again to use the keys.
4. In your python project, you can use your token using the os.environ.get method, like this:
```python
import os
authToken = os.environ.get('authToken', None)
print(authToken)
```
4.1 In Jupyter Notebook
```python
from dotenv import load_dotenv
load_dotenv()
```
5. Make sure to add .env to .gitignore if you want to share your code on GitHub.
References:
https://www.zeolearn.com/magazine/how...
/ how-to-not-show-credential-in-jupyter-note...
__________________________________________
No Copyright Background Music
Music by INOSSI - Chill Out
• INOSSI - Chill Out (Official)
__________________________________________
Auf dieser Seite können Sie das Online-Video HOW TO: Hide Sensitive info in Python Using Environment Variables? mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer chinamatt 19 November 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 838 Mal angesehen und es wurde von 16 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!