liveBook · Manning

Python-dotenv

As explained in Enterprise RAG

python-dotenv is a Python library that loads key-value settings from a .env file into environment variables.

python-dotenv loads key-value settings from a .env file into environment variables, keeping API keys out of scripts and plain-text sharing. section 2.4.3

Use the library through a short setup workflow:

  • Create a .env file in the project folder and place the API key there. section 2.4.3
  • Install python-dotenv from the terminal. section 2.4.3
  • Call load_dotenv(), then retrieve the key with os.getenv("OPENAI_API_KEY"). section 2.4.3
from dotenv import load_dotenv
import os
 
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
 

Shows the minimal Python integration for loading .env values and assigning the API key. section 2.4.3

How Enterprise RAG covers it

How deep it goes
Demonstrates installation, .env creation, loading, and lookup, but does not discuss library internals.
Examples
Uses an OPENAI_API_KEY entry in .env and loads it before an OpenAI request.
What it assumes
Assumes a Python script and API key, while teaching package installation and environment loading from the beginning.
What you can do after
Apply it via python-dotenv to load a project API key without embedding it in source code.
How it connects
Connects environment variables with API keys, the OpenAI API, automated evaluations, and version control.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Enterprise RAG. The section links point to the parts of the book it draws on.