LBRY Block Explorer

LBRY Claims • how-to-hide-your-api-keys-openai_api_key

ffe28545bbfef6094dc5800b93519049caf7cd94

Published By
Created On
30 Jun 2023 10:52:04 UTC
Transaction ID
Cost
Safe for Work
Free
Yes
How to hide your API keys | OPENAI_API_KEY | Python os.environ.get
This video shows you how to set an API key as an environment variable directly in your shell's `~/.zshrc` configuration file using the `export` command and access it from Python using `os.environ.get`, you can follow these steps:

1. Open your preferred text editor and open the `~/.zshrc` file. For example, you can use the following command to open it with the Nano editor:

```bash
nano ~/.zshrc
```

2. Scroll to the end of the file or the appropriate section where you want to add the environment variable.

3. Add the following line to set the environment variable:

```bash
export API_KEY="your_api_key_here"
```

Replace `"your_api_key_here"` with your actual API key.

4. Save the changes and exit the text editor. In Nano, you can press `Ctrl + X`, then `Y` to save the changes.

5. To apply the changes to your current session, either close and reopen the terminal or run the following command to reload the shell configuration file:

```bash
source ~/.zshrc
```

6. In your Python script, you can access the API key using `os.environ.get` method. Here's an example:

```python
import os

api_key = os.environ.get('API_KEY')

if api_key:
# Use the API key in your code
# ...
else:
# API key not set
# Handle the case accordingly
# ...
```

The `os.environ.get('API_KEY')` method retrieves the value of the `API_KEY` environment variable. It returns `None` if the environment variable is not set, allowing you to handle that case appropriately.

By following these steps, you'll be able to set an API key as an environment variable in your `~/.zshrc` configuration file and access it from your Python script using `os.environ.get`.

Become a patron : ? https://www.patreon.com/drpi
Buy me a coffee (or Tea) ☕ https://www.buymeacoffee.com/DrPi

If you want a fast VPS server with Python installed check out :
https://webdock.io/en?maff=wdaff--170
https://webdock.io/en/black-friday-cyber-monday-weekend-2022

Pytest with FastAPI course on "TestDriven.io":
-------------------------------------------------------------------------
https://testdriven.io/courses/tdd-fastapi/?utm_source=python360
https://testdriven.io/courses/scalable-fastapi-aws/?utm_source=python360
https://testdriven.io/courses/fastapi-celery/?utm_source=python360


Thumbs up yeah? (cos Algos..)

#hideapikey #openai #python
...
https://www.youtube.com/watch?v=b6pknmBGYNg
Author
Content Type
Unspecified
video/mp4
Language
English
Open in LBRY

More from the publisher

Controlling
VIDEO
SCRAP
Controlling
VIDEO
WEB S
Controlling
VIDEO
CONVE
Controlling
VIDEO
NUMPY
Controlling
VIDEO
LOOKI
Controlling
VIDEO
POWER
Controlling
VIDEO
VISUA
Controlling
VIDEO
FASTA
Controlling
VIDEO
PROGR