python-dotenv API Reference
Full documentation for python-dotenv (Standard Library / Native)
python-dotenv.Any
Python Library Documentation: class Any in module typing class Any(builtins.object) | Any(*args, **kwargs) | | Special type indicating an unconstrained type. | | - Any is compatible with every type. | - Any assumed to have all methods. | - All values assumed to be instances of Any. | | Note that all the above statements are true from the point of view of | static type checkers. At runtime, Any should not be used with instance | checks. | | Static methods defined here: | | __new__(cls, *args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
python-dotenv.Optional
Python Library Documentation: _SpecialForm in module typing
Optional = typing.Optional
Optional[X] is equivalent to Union[X, None].
python-dotenv.dotenv_values
Python Library Documentation: function dotenv_values in module dotenv.main
dotenv_values(dotenv_path: Union[str, ForwardRef('os.PathLike[str]'), NoneType] = None, stream: Optional[IO[str]] = None, verbose: bool = False, interpolate: bool = True, encoding: Optional[str] = 'utf-8') -> Dict[str, Optional[str]]
Parse a .env file and return its content as a dict.
The returned dict will have `None` values for keys without values in the .env file.
For example, `foo=bar` results in `{"foo": "bar"}` whereas `foo` alone results in
`{"foo": None}`
Parameters:
dotenv_path: Absolute or relative path to the .env file.
stream: `StringIO` object with .env content, used if `dotenv_path` is `None`.
verbose: Whether to output a warning if the .env file is missing.
encoding: Encoding to be used to read the file.
If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
.env file.
python-dotenv.find_dotenv
Python Library Documentation: function find_dotenv in module dotenv.main
find_dotenv(filename: str = '.env', raise_error_if_not_found: bool = False, usecwd: bool = False) -> str
Search in increasingly higher folders for the given file
Returns path to the file if found, or an empty string otherwise
python-dotenv.get_cli_string
Python Library Documentation: function get_cli_string in module dotenv
get_cli_string(path: Optional[str] = None, action: Optional[str] = None, key: Optional[str] = None, value: Optional[str] = None, quote: Optional[str] = None)
Returns a string suitable for running as a shell script.
Useful for converting a arguments passed to a fabric task
to be passed to a `local` or `run` command.
python-dotenv.get_key
Python Library Documentation: function get_key in module dotenv.main
get_key(dotenv_path: Union[str, ForwardRef('os.PathLike[str]')], key_to_get: str, encoding: Optional[str] = 'utf-8') -> Optional[str]
Get the value of a given key from the given .env.
Returns `None` if the key isn't found or doesn't have a value.
python-dotenv.load_dotenv
Python Library Documentation: function load_dotenv in module dotenv.main
load_dotenv(dotenv_path: Union[str, ForwardRef('os.PathLike[str]'), NoneType] = None, stream: Optional[IO[str]] = None, verbose: bool = False, override: bool = False, interpolate: bool = True, encoding: Optional[str] = 'utf-8') -> bool
Parse a .env file and then load all the variables found as environment variables.
Parameters:
dotenv_path: Absolute or relative path to .env file.
stream: Text stream (such as `io.StringIO`) with .env content, used if
`dotenv_path` is `None`.
verbose: Whether to output a warning the .env file is missing.
override: Whether to override the system environment variables with the variables
from the `.env` file.
encoding: Encoding to be used to read the file.
Returns:
Bool: True if at least one environment variable is set else False
If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
.env file with it's default parameters. If you need to change the default parameters
of `find_dotenv()`, you can explicitly call `find_dotenv()` and pass the result
to this function as `dotenv_path`.
If the environment variable `PYTHON_DOTENV_DISABLED` is set to a truthy value,
.env loading is disabled.
python-dotenv.load_ipython_extension
Python Library Documentation: function load_ipython_extension in module dotenv load_ipython_extension(ipython: Any) -> None
python-dotenv.main
Python Library Documentation: module dotenv.main in dotenv
NAME
dotenv.main
CLASSES
builtins.object
DotEnv
class DotEnv(builtins.object)
| DotEnv(dotenv_path: Union[str, ForwardRef('os.PathLike[str]'), NoneType], stream: Optional[IO[str]] = None, verbose: bool = False, encoding: Optional[str] = None, interpolate: bool = True, override: bool = True) -> None
|
| Methods defined here:
|
| __init__(self, dotenv_path: Union[str, ForwardRef('os.PathLike[str]'), NoneType], stream: Optional[IO[str]] = None, verbose: bool = False, encoding: Optional[str] = None, interpolate: bool = True, override: bool = True) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| dict(self) -> Dict[str, Optional[str]]
| Return dotenv as dict
|
| get(self, key: str) -> Optional[str]
|
| parse(self) -> Iterator[Tuple[str, Optional[str]]]
|
| set_as_environment_variables(self) -> bool
| Load the current dotenv as system environment variable.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
dotenv_values(dotenv_path: Union[str, ForwardRef('os.PathLike[str]'), NoneType] = None, stream: Optional[IO[str]] = None, verbose: bool = False, interpolate: bool = True, encoding: Optional[str] = 'utf-8') -> Dict[str, Optional[str]]
Parse a .env file and return its content as a dict.
The returned dict will have `None` values for keys without values in the .env file.
For example, `foo=bar` results in `{"foo": "bar"}` whereas `foo` alone results in
`{"foo": None}`
Parameters:
dotenv_path: Absolute or relative path to the .env file.
stream: `StringIO` object with .env content, used if `dotenv_path` is `None`.
verbose: Whether to output a warning if the .env file is missing.
encoding: Encoding to be used to read the file.
If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
.env file.
find_dotenv(filename: str = '.env', raise_error_if_not_found: bool = False, usecwd: bool = False) -> str
Search in increasingly higher folders for the given file
Returns path to the file if found, or an empty string otherwise
get_key(dotenv_path: Union[str, ForwardRef('os.PathLike[str]')], key_to_get: str, encoding: Optional[str] = 'utf-8') -> Optional[str]
Get the value of a given key from the given .env.
Returns `None` if the key isn't found or doesn't have a value.
load_dotenv(dotenv_path: Union[str, ForwardRef('os.PathLike[str]'), NoneType] = None, stream: Optional[IO[str]] = None, verbose: bool = False, override: bool = False, interpolate: bool = True, encoding: Optional[str] = 'utf-8') -> bool
Parse a .env file and then load all the variables found as environment variables.
Parameters:
dotenv_path: Absolute or relative path to .env file.
stream: Text stream (such as `io.StringIO`) with .env content, used if
`dotenv_path` is `None`.
verbose: Whether to output a warning the .env file is missing.
override: Whether to override the system environment variables with the variables
from the `.env` file.
encoding: Encoding to be used to read the file.
Returns:
Bool: True if at least one environment variable is set else False
If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
.env file with it's default parameters. If you need to change the default parameters
of `find_dotenv()`, you can explicitly call `find_dotenv()` and pass the result
to this function as `dotenv_path`.
If the environment variable `PYTHON_DOTENV_DISABLED` is set to a truthy value,
.env loading is disabled.
resolve_variables(values: Iterable[Tuple[str, Optional[str]]], override: bool) -> Mapping[str, Optional[str]]
rewrite(path: Union[str, ForwardRef('os.PathLike[str]')], encoding: Optional[str], follow_symlinks: bool = False) -> Iterator[Tuple[IO[str], IO[str]]]
set_key(dotenv_path: Union[str, ForwardRef('os.PathLike[str]')], key_to_set: str, value_to_set: str, quote_mode: str = 'always', export: bool = False, encoding: Optional[str] = 'utf-8', follow_symlinks: bool = False) -> Tuple[Optional[bool], str, str]
Adds or Updates a key/value to the given .env
The target .env file is created if it doesn't exist.
This function doesn't follow symlinks by default, to avoid accidentally
modifying a file at a potentially untrusted path. If you don't need this
protection and need symlinks to be followed, use `follow_symlinks`.
unset_key(dotenv_path: Union[str, ForwardRef('os.PathLike[str]')], key_to_unset: str, quote_mode: str = 'always', encoding: Optional[str] = 'utf-8', follow_symlinks: bool = False) -> Tuple[Optional[bool], str]
Removes a given key from the given `.env` file.
If the .env path given doesn't exist, fails.
If the given key doesn't exist in the .env, fails.
This function doesn't follow symlinks by default, to avoid accidentally
modifying a file at a potentially untrusted path. If you don't need this
protection and need symlinks to be followed, use `follow_symlinks`.
with_warn_for_invalid_lines(mappings: Iterator[dotenv.parser.Binding]) -> Iterator[dotenv.parser.Binding]
DATA
Dict = typing.Dict
A generic version of dict.
Iterable = typing.Iterable
A generic version of collections.abc.Iterable.
Iterator = typing.Iterator
A generic version of collections.abc.Iterator.
Mapping = typing.Mapping
A generic version of collections.abc.Mapping.
Optional = typing.Optional
Optional[X] is equivalent to Union[X, None].
StrPath = typing.Union[str, ForwardRef('os.PathLike[str]')]
Tuple = typing.Tuple
Deprecated alias to builtins.tuple.
Tuple[X, Y] is the cross-product type of X and Y.
Example: Tuple[T1, T2] is a tuple of two elements corresponding
to type variables T1 and T2. Tuple[int, float, str] is a tuple
of an int, a float and a string.
To specify a variable-length tuple of homogeneous type, use Tuple[T, ...].
Union = typing.Union
Union type; Union[X, Y] means either X or Y.
On Python 3.10 and higher, the | operator
can also be used to denote unions;
X | Y means the same thing to the type checker as Union[X, Y].
To define a union, use e.g. Union[int, str]. Details:
- The arguments must be types and there must be at least one.
- None as an argument is a special case and is replaced by
type(None).
- Unions of unions are flattened, e.g.::
assert Union[Union[int, str], float] == Union[int, str, float]
- Unions of a single argument vanish, e.g.::
assert Union[int] == int # The constructor actually returns int
- Redundant arguments are skipped, e.g.::
assert Union[int, str, int] == Union[int, str]
- When comparing unions, the argument order is ignored, e.g.::
assert Union[int, str] == Union[str, int]
- You cannot subclass or instantiate a union.
- You can use Optional[X] as a shorthand for Union[X, None].
logger = <Logger dotenv.main (WARNING)>
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\dotenv\main.py
python-dotenv.parser
Python Library Documentation: module dotenv.parser in dotenv
NAME
dotenv.parser
CLASSES
builtins.Exception(builtins.BaseException)
Error
builtins.object
Position
Reader
builtins.tuple(builtins.object)
Binding
Original
class Binding(builtins.tuple)
| Binding(key: Optional[str], value: Optional[str], original: dotenv.parser.Original, error: bool)
|
| Binding(key, value, original, error)
|
| Method resolution order:
| Binding
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __getnewargs__(self) from collections.Binding
| Return self as a plain tuple. Used by copy and pickle.
|
| __repr__(self) from collections.Binding
| Return a nicely formatted representation string
|
| _asdict(self) from collections.Binding
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections.Binding
| Return a new Binding object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| _make(iterable) from collections.Binding
| Make a new Binding object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(_cls, key: Optional[str], value: Optional[str], original: dotenv.parser.Original, error: bool) from namedtuple_Binding.Binding
| Create new instance of Binding(key, value, original, error)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| key
| Alias for field number 0
|
| value
| Alias for field number 1
|
| original
| Alias for field number 2
|
| error
| Alias for field number 3
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'error': <class 'bool'>, 'key': typing.Optional[str...
|
| __match_args__ = ('key', 'value', 'original', 'error')
|
| __orig_bases__ = (<function NamedTuple>,)
|
| _field_defaults = {}
|
| _fields = ('key', 'value', 'original', 'error')
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class Error(builtins.Exception)
| Method resolution order:
| Error
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class Original(builtins.tuple)
| Original(string: str, line: int)
|
| Original(string, line)
|
| Method resolution order:
| Original
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __getnewargs__(self) from collections.Original
| Return self as a plain tuple. Used by copy and pickle.
|
| __repr__(self) from collections.Original
| Return a nicely formatted representation string
|
| _asdict(self) from collections.Original
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections.Original
| Return a new Original object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| _make(iterable) from collections.Original
| Make a new Original object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(_cls, string: str, line: int) from namedtuple_Original.Original
| Create new instance of Original(string, line)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| string
| Alias for field number 0
|
| line
| Alias for field number 1
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'line': <class 'int'>, 'string': <class 'str'>}
|
| __match_args__ = ('string', 'line')
|
| __orig_bases__ = (<function NamedTuple>,)
|
| _field_defaults = {}
|
| _fields = ('string', 'line')
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class Position(builtins.object)
| Position(chars: int, line: int) -> None
|
| Methods defined here:
|
| __init__(self, chars: int, line: int) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| advance(self, string: str) -> None
|
| set(self, other: 'Position') -> None
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| start() -> 'Position'
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Reader(builtins.object)
| Reader(stream: IO[str]) -> None
|
| Methods defined here:
|
| __init__(self, stream: IO[str]) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| get_marked(self) -> dotenv.parser.Original
|
| has_next(self) -> bool
|
| peek(self, count: int) -> str
|
| read(self, count: int) -> str
|
| read_regex(self, regex: Pattern[str]) -> Sequence[str]
|
| set_mark(self) -> None
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
decode_escapes(regex: Pattern[str], string: str) -> str
make_regex(string: str, extra_flags: int = 0) -> Pattern[str]
parse_binding(reader: dotenv.parser.Reader) -> dotenv.parser.Binding
parse_key(reader: dotenv.parser.Reader) -> Optional[str]
parse_stream(stream: IO[str]) -> Iterator[dotenv.parser.Binding]
parse_unquoted_value(reader: dotenv.parser.Reader) -> str
parse_value(reader: dotenv.parser.Reader) -> str
DATA
Iterator = typing.Iterator
A generic version of collections.abc.Iterator.
Match = typing.Match
A generic version of re.Match.
Optional = typing.Optional
Optional[X] is equivalent to Union[X, None].
Pattern = typing.Pattern
A generic version of re.Pattern.
Sequence = typing.Sequence
A generic version of collections.abc.Sequence.
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\dotenv\parser.py
python-dotenv.set_key
Python Library Documentation: function set_key in module dotenv.main
set_key(dotenv_path: Union[str, ForwardRef('os.PathLike[str]')], key_to_set: str, value_to_set: str, quote_mode: str = 'always', export: bool = False, encoding: Optional[str] = 'utf-8', follow_symlinks: bool = False) -> Tuple[Optional[bool], str, str]
Adds or Updates a key/value to the given .env
The target .env file is created if it doesn't exist.
This function doesn't follow symlinks by default, to avoid accidentally
modifying a file at a potentially untrusted path. If you don't need this
protection and need symlinks to be followed, use `follow_symlinks`.
python-dotenv.unset_key
Python Library Documentation: function unset_key in module dotenv.main
unset_key(dotenv_path: Union[str, ForwardRef('os.PathLike[str]')], key_to_unset: str, quote_mode: str = 'always', encoding: Optional[str] = 'utf-8', follow_symlinks: bool = False) -> Tuple[Optional[bool], str]
Removes a given key from the given `.env` file.
If the .env path given doesn't exist, fails.
If the given key doesn't exist in the .env, fails.
This function doesn't follow symlinks by default, to avoid accidentally
modifying a file at a potentially untrusted path. If you don't need this
protection and need symlinks to be followed, use `follow_symlinks`.
python-dotenv.variables
Python Library Documentation: module dotenv.variables in dotenv
NAME
dotenv.variables
CLASSES
builtins.object
Atom
Literal
Variable
class Atom(builtins.object)
| Methods defined here:
|
| __ne__(self, other: object) -> bool
| Return self!=value.
|
| resolve(self, env: Mapping[str, Optional[str]]) -> str
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset({'resolve'})
class Literal(Atom)
| Literal(value: str) -> None
|
| Method resolution order:
| Literal
| Atom
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: object) -> bool
| Return self==value.
|
| __hash__(self) -> int
| Return hash(self).
|
| __init__(self, value: str) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> str
| Return repr(self).
|
| resolve(self, env: Mapping[str, Optional[str]]) -> str
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| ----------------------------------------------------------------------
| Methods inherited from Atom:
|
| __ne__(self, other: object) -> bool
| Return self!=value.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Atom:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Variable(Atom)
| Variable(name: str, default: Optional[str]) -> None
|
| Method resolution order:
| Variable
| Atom
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other: object) -> bool
| Return self==value.
|
| __hash__(self) -> int
| Return hash(self).
|
| __init__(self, name: str, default: Optional[str]) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> str
| Return repr(self).
|
| resolve(self, env: Mapping[str, Optional[str]]) -> str
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| ----------------------------------------------------------------------
| Methods inherited from Atom:
|
| __ne__(self, other: object) -> bool
| Return self!=value.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Atom:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
parse_variables(value: str) -> Iterator[dotenv.variables.Atom]
DATA
Iterator = typing.Iterator
A generic version of collections.abc.Iterator.
Mapping = typing.Mapping
A generic version of collections.abc.Mapping.
Optional = typing.Optional
Optional[X] is equivalent to Union[X, None].
Pattern = typing.Pattern
A generic version of re.Pattern.
__annotations__ = {'_posix_variable': typing.Pattern[str]}
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\dotenv\variables.py