{
 "kind": "tool",
 "slug": "python-dotenv",
 "path": "tools/python-dotenv/",
 "name": "python-dotenv",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Dev workflow and config",
   "tools/dev-workflow/"
  ]
 ],
 "lead": "Keep secrets and settings in a .env file.",
 "chips": [
  {
   "label": "Dev workflow and config",
   "path": "tools/dev-workflow/"
  },
  {
   "label": "PYPI"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "pip install python-dotenv"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/theskumar/python-dotenv"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "BSD-3-Clause",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met",
   "note": "Any use is allowed; keep the copyright notice and license text when you ship its files.",
   "src": "https://github.com/theskumar/python-dotenv/blob/main/LICENSE"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Nov 9, 2026",
   "note": "Latest GitHub release Oct 1, 2026. ",
   "src": "https://github.com/theskumar/python-dotenv"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "568 projects",
   "status": "info",
   "sub": "#3 of 299 in its category",
   "note": "Dependency in 568 public GitHub projects set up for AI coding agents that we scanned (9.1%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 11, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What python-dotenv does",
   "parts": [
    {
     "t": "prose",
     "text": "python-dotenv is a free Python library that reads a small text file named .env and hands its lines to your program as settings. You keep keys, passwords and addresses in that file on your own computer, out of the code. On the server the same program reads the real settings instead."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Keep service keys out of code",
       "text": "Your app calls a paid AI or payment service; the secret key sits in .env on your laptop, never in the code you share or push.",
       "idea": false
      },
      {
       "title": "Same code on laptop and server",
       "text": "On your computer settings come from .env; on the hosting service the real settings win, with no code change.",
       "idea": false
      },
      {
       "title": "Read settings without changing anything",
       "text": "A small script reads the values from .env into a plain list of names and values, for example to show which settings are missing.",
       "idea": false
      },
      {
       "title": "Shared and private settings files",
       "text": "The team shares one file with ordinary settings, and each person keeps a second file with their own secrets.",
       "idea": false
      },
      {
       "title": "Run any command with the settings",
       "text": "Start a script, a worker or a test run with the values from .env, without changing that program.",
       "idea": false
      },
      {
       "title": "Notebook experiments with keys",
       "text": "In a Jupyter notebook, load your keys from .env with two lines instead of pasting them into a cell.",
       "idea": false
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "python-dotenv popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "80",
       "of": "/ 100",
       "l": "Gid Score, #92 overall"
      },
      {
       "n": "185M",
       "l": "downloads a week, pypi"
      },
      {
       "n": "8,917",
       "l": "GitHub stars"
      },
      {
       "n": "568",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How python-dotenv is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "python-dotenv is a dependency in 568 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (35.0% of the 1,623 Python ones), #3 of 299 in dev workflow and config.",
      "Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 5,334; those are left out of every share on this page.",
      "The most used alternative in our scan is Pydantic Settings (219 projects).",
      "Projects that use it most often also use Pydantic (49.3%), Uvicorn (43.8%), Requests (42.6%).",
      "It is more common in projects set up for OpenClaw (12.0%) than for OpenAI Codex (4.3%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "286 projects, 9.4%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "240 projects, 7.3%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "192 projects, 7.9%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "40 projects, 12.0%",
       "v": "OpenClaw",
       "path": "agents/openclaw/"
      },
      {
       "l": "25 projects, 5.3%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "23 projects, 8.2%",
       "v": "Devin Desktop",
       "path": "agents/devin-desktop/"
      },
      {
       "l": "20 projects, 4.3%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "15 projects, 4.4%",
       "v": "OpenCode",
       "path": "agents/opencode/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 49.3% of its projects",
       "v": "Pydantic",
       "path": "tools/pydantic/"
      },
      {
       "l": "In 43.8% of its projects",
       "v": "Uvicorn",
       "path": "tools/uvicorn/"
      },
      {
       "l": "In 42.6% of its projects",
       "v": "Requests",
       "path": "tools/requests-py/"
      },
      {
       "l": "In 39.3% of its projects",
       "v": "FastAPI",
       "path": "tools/fastapi/"
      },
      {
       "l": "In 30.6% of its projects",
       "v": "OpenAI Python Library",
       "path": "tools/openai-pypi/"
      },
      {
       "l": "In 29.2% of its projects",
       "v": "PyYAML",
       "path": "tools/pyyaml/"
      },
      {
       "l": "In 28.7% of its projects",
       "v": "NumPy",
       "path": "tools/numpy/"
      },
      {
       "l": "In 29.6% of its projects",
       "v": "Model Context Protocol SDK (Python)",
       "path": "tools/mcp/"
      }
     ]
    }
   ]
  },
  {
   "id": "profile",
   "nav": "Profile",
   "h2": "python-dotenv in practice",
   "parts": [
    {
     "t": "h3",
     "text": "Strengths"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "Real environment variables win by default",
       "v": "<code>load_dotenv()</code> does not override variables that are already set, because it defaults to <code>override=False</code>. A <code>.env</code> file can sit in development while deployed values stay in charge. Pass <code>override=True</code> to reverse this."
      },
      {
       "l": "dotenv_values gives you a dict instead",
       "v": "<code>dotenv_values</code> parses the file and returns a <code>dict</code> without touching <code>os.environ</code>. The README shows it merging <code>.env.shared</code>, <code>.env.secret</code> and <code>os.environ</code> into one config."
      },
      {
       "l": "Config does not have to come from a file",
       "v": "Both <code>load_dotenv</code> and <code>dotenv_values</code> take a <code>stream</code> argument. The docs give the network as an example source. The file format section adds that reading from FIFOs (named pipes) on Unix is supported."
      },
      {
       "l": "An off switch for code you cannot edit",
       "v": "Setting <code>PYTHON_DOTENV_DISABLED=1</code> stops <code>load_dotenv()</code> from loading anything. The docs suggest this for production, or when a third-party package calls it."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Watch out for"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "The file format has no formal spec",
       "v": "The maintainers say the <code>.env</code> format is not formally specified and is still changing. Files should \"mostly look like Bash files\", but that is a guide, not a guarantee."
      },
      {
       "l": "Only ${VAR} is expanded",
       "v": "Variable references must use braces. A bare <code>$DOMAIN</code> is left as is."
      },
      {
       "l": "Expansion order depends on override",
       "v": "With <code>override=False</code>, an expanded variable takes its value from the environment first and from the <code>.env</code> file second. With <code>override=True</code> or <code>dotenv_values()</code>, the file comes first. The same <code>.env</code> can therefore produce different values."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Layer shared, secret and real environment values"
    },
    {
     "t": "tabs",
     "label": "Example",
     "items": [
      {
       "tab": "Python",
       "code": "import os\nfrom dotenv import dotenv_values\n\nconfig = {\n    **dotenv_values(\".env.shared\"), # load shared development variables\n    **dotenv_values(\".env.secret\"), # load sensitive variables\n    **os.environ, # override loaded values with environment variables\n}"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "profile",
   "h2": "More about python-dotenv",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Head to head",
       "items": [
        {
         "text": "python-dotenv vs Pydantic Settings",
         "note": "used together in 125 projects",
         "path": "tools/compare/python-dotenv-vs-pydantic-settings/"
        }
       ]
      },
      {
       "title": "Packages around it",
       "items": [
        "requests: HTTP client",
        "pydantic: Data validation",
        "uvicorn: ASGI server",
        "fastapi: Web API framework",
        "solders: Solana Python bindings",
        "numpy: Numerical arrays"
       ]
      },
      {
       "title": "More in Dev workflow and config",
       "path": "tools/dev-workflow/",
       "items": [
        {
         "text": "dotenv",
         "path": "tools/dotenv/"
        },
        {
         "text": "Husky",
         "path": "tools/husky/"
        },
        {
         "text": "lint-staged",
         "path": "tools/lint-staged/"
        },
        {
         "text": "concurrently",
         "path": "tools/concurrently/"
        },
        {
         "text": "Rich",
         "path": "tools/rich/"
        },
        {
         "text": "cross-env",
         "path": "tools/cross-env/"
        },
        {
         "text": "chalk",
         "path": "tools/chalk/"
        },
        {
         "text": "Commander",
         "path": "tools/commander/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "python-dotenv",
       "me": true,
       "facts": [
        "BSD-3-Clause",
        "Gid 80",
        "185M/wk"
       ]
      },
      {
       "name": "Pydantic Settings",
       "why": "Pick Pydantic Settings when you also want each setting checked and turned into the right type (number, true/false) when the app starts.",
       "path": "tools/pydantic-settings/",
       "facts": [
        "MIT",
        "Gid 71",
        "123M/wk"
       ]
      },
      {
       "name": "environs",
       "why": "Pick environs when you want .env loading plus typed helpers such as reading a number, a list or a URL from a setting.",
       "path": "tools/environs/",
       "facts": []
      },
      {
       "name": "python-decouple",
       "why": "Pick python-decouple when settings may come from either .env or an .ini file and you want defaults and casting in one call.",
       "path": "tools/python-decouple/",
       "facts": []
      }
     ],
     "more": "Compare python-dotenv with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Use python-dotenv (pin python-dotenv==1.2.4, Python 3.10+) to load settings from a .env file with an explicit path at startup, read keys with os.environ[...], add .env to .gitignore and commit a .env.example with empty values."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Install the package. Its name is python-dotenv; in code you import dotenv.",
       "code": "pip install python-dotenv",
       "src": "https://github.com/theskumar/python-dotenv/blob/main/README.md"
      },
      {
       "text": "Load the file at the start of your program, then read settings as usual.",
       "code": "from dotenv import load_dotenv\n\nload_dotenv()  # reads variables from a .env file and sets them in os.environ\n",
       "src": "https://github.com/theskumar/python-dotenv/blob/main/README.md"
      },
      {
       "text": "Put a .env file in the project's root folder and add .env to .gitignore.",
       "code": "# Development settings\nDOMAIN=example.org\nADMIN_EMAIL=admin@${DOMAIN}\nROOT_URL=${DOMAIN}/app\n",
       "src": "https://github.com/theskumar/python-dotenv/blob/main/README.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Rules for your agent"
    },
    {
     "t": "rules",
     "label": "Paste into AGENTS.md or CLAUDE.md",
     "text": "## python-dotenv\n- Install with `pip install python-dotenv`; add the `[cli]` extra only if the `dotenv` command is needed.\n- Call `load_dotenv()` once at startup, then read config through `os.environ` or `os.getenv`.\n- Do not pass `override=True` unless `.env` values must beat variables already set in the environment; the default is `override=False`.\n- Use `dotenv_values(\".env\")` when you need a dict and must not modify `os.environ`.\n- Write variable references as `${VAR}`; bare `$VAR` is not expanded.\n- Add `.env` to `.gitignore`, especially when it holds secrets like passwords.\n- To stop `load_dotenv()` in production or inside third-party code, set `PYTHON_DOTENV_DISABLED=1` instead of editing calls.\n"
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "load_dotenv() with no path in a script that lives in another folder (a tools/ or scripts/ folder)",
       "fix": "load_dotenv(\"path/to/.env\") with an explicit path, or load_dotenv(find_dotenv(usecwd=True))",
       "why": "Without a path it searches from the script's folder upward; in our run a script in tools/ skipped the .env in the current folder and picked up a different .env two levels higher."
      },
      {
       "dont": "Expecting .env to replace a variable that the shell or server already set",
       "fix": "Pass override=True when the file must win (local tools), keep the default on servers",
       "why": "The default keeps existing values; in our run PORT stayed 9000 until override=True."
      },
      {
       "dont": "ROOT_URL=$DOMAIN/app",
       "fix": "ROOT_URL=${DOMAIN}/app",
       "why": "Only the braced form is filled in; in our run BARE=$DOMAIN/shop came back unchanged."
      },
      {
       "dont": "if os.environ[\"DEBUG\"]: ... (with DEBUG=false in .env)",
       "fix": "os.environ.get(\"DEBUG\", \"\").lower() in (\"1\", \"true\", \"yes\"), or use pydantic-settings for typed values",
       "why": "Every value is text. In our run DEBUG=true arrived as the string 'true', so even 'false' counts as true."
      },
      {
       "dont": "Committing .env with real keys, or pasting its contents into a chat or an issue",
       "fix": "Add .env to .gitignore and commit a .env.example with names and empty values",
       "why": "The file holds secrets in plain text."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Does it replace settings that are already set on the server?",
       "a": "No, not by default. Pass override=True if the file should win.",
       "evidence": {
        "url": "https://github.com/theskumar/python-dotenv/blob/main/README.md",
        "quote": "Not override existing environment variables (override=False). Pass override=True to override existing variables."
       }
      },
      {
       "q": "Can one value use another, like ${DOMAIN}?",
       "a": "Yes, with braces. A bare $DOMAIN stays as written; our run showed the same.",
       "evidence": {
        "url": "https://github.com/theskumar/python-dotenv/blob/main/README.md",
        "quote": "If you use variables in values, ensure they are surrounded with { and }, like ${DOMAIN}, as bare variables such as $DOMAIN are not expanded."
       }
      },
      {
       "q": "Where does load_dotenv() look for the file?",
       "a": "Next to the Python script and then in the folders above it, not in the folder you started the program from.",
       "evidence": {
        "url": "https://github.com/theskumar/python-dotenv/blob/main/README.md",
        "quote": "Look for a .env file in the same directory as the Python script (or higher up the directory tree)."
       }
      },
      {
       "q": "Can a value span several lines?",
       "a": "Yes, if it is in single or double quotes.",
       "evidence": {
        "url": "https://github.com/theskumar/python-dotenv/blob/main/README.md",
        "quote": "It is possible for single- or double-quoted values to span multiple lines."
       }
      },
      {
       "q": "Is it still maintained?",
       "a": "Yes. Version 1.2.4 came out on 2026-10-01 and more fixes are listed as unreleased.",
       "evidence": {
        "url": "https://github.com/theskumar/python-dotenv/blob/main/CHANGELOG.md",
        "quote": "[1.2.4] - 2026-10-01"
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "pypi python-dotenv"
  ],
  [
   "Category",
   "Dev workflow and config"
  ],
  [
   "License",
   "BSD-3-Clause"
  ],
  [
   "Latest version",
   "v1.2.4, October 1, 2026"
  ],
  [
   "On GitHub since",
   "September 2014"
  ],
  [
   "Gid Score",
   "80.5"
  ],
  [
   "Rank in category",
   "#3 of 299"
  ],
  [
   "GitHub",
   "theskumar/python-dotenv"
  ],
  [
   "Last change",
   "Nov 9, 2026"
  ]
 ],
 "good": [
  "The .env file is plain text. Keep it out of git and out of anything you share, or the secrets leak with it.",
  "Settings already set on the computer win over the file, unless you ask for the opposite.",
  "The file format has no formal standard and still changes a little between versions."
 ],
 "checked_line": "Read by AgentGid from 4 official pages, card checked Nov 11, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/theskumar.png"
}