theskumar / theskumar/python-dotenv
Unable to escape posix expansion
Open
@theskumar is already working on this.
Since Apr 8, 2025.
- Dominant language
- Python
- Stars
- 8.9k
- Forks
- 581
- PR merge metrics
- No merged PRs in 30d
Description
What
Unable to elegantly escape the $ in ${VARIABLE} expansion.
Scenario
.env
VAR=${VARIABLE}
script.py
import os
import dotenv
if dotenv.find_dotenv():
dotenv.load_dotenv(interpolate=False)
print(f"VAR={os.getenv('VAR')}"
I do not see the interpolate kwarg in the documentation, however looking at the stub: https://github.com/theskumar/python-dotenv/blob/914c68ef0e4c2c085d2753f5cbbf304852f37850/src/dotenv/main.py#L307-L330
*Edit: and the pypi documentation:

Expected Behavior
output
>> VAR='${VARIABLE}'
Actual Behavior
output
>> VAR=''
Workaround
My current workaround is to provide the desired string as a default value for variable expansion.
.env
VAR=${_:-${VARIABLE}]
output
>> VAR='${VARIABLE}'
System
Host: Windows 11
Python: 3.10 w/ Poetry environment
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.