filmov
tv
HOW TO: Hide Sensitive info in Python Using Environment Variables?

Показать описание
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.
```python
import os
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:
__________________________________________
No Copyright Background Music
Music by INOSSI - Chill Out
__________________________________________
• 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.
```python
import os
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:
__________________________________________
No Copyright Background Music
Music by INOSSI - Chill Out
__________________________________________