Load environment variables from .env file if it exists.
()
| 15 | |
| 16 | # Load environment variables from .env file |
| 17 | def load_env_file(): |
| 18 | """Load environment variables from .env file if it exists.""" |
| 19 | env_file = Path(__file__).parent.parent / ".env" |
| 20 | if env_file.exists(): |
| 21 | with open(env_file, "r") as f: |
| 22 | for line in f: |
| 23 | line = line.strip() |
| 24 | if line and not line.startswith("#") and "=" in line: |
| 25 | key, value = line.split("=", 1) |
| 26 | # Don't override existing environment variables |
| 27 | if key not in os.environ: |
| 28 | os.environ[key] = value |
| 29 | |
| 30 | |
| 31 | # Load .env file at module import |