Skip to content

config_from_{json, yaml, ini, toml, dotenv} should accept a pathlib.Path as a data parameter. #96

@publicmatt

Description

@publicmatt

Right now it looks like most of the methods to define a file path take a Union[str, TextIO] type. It would be nice if it were possible to pass a pathlib.Path type as well:

from pathlib import Path
root = Path(__file__).parent
cfg = config_from_dotenv(root / '.env', read_from_file=true)

Right now, when I try to do so, I get the following error:

  File "/path/to/.venv/lib/python3.11/site-packages/config/__init__.py", line 579, in _reload
    data = data.read()
           ^^^^^^^^^

There might have to be some introspection of the data object, or a conversion of the str to a Path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions