python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

Is there an equivalent of load_yaml, but from a string or a file-like object?

Open davidkh opened this issue 3 years ago • 0 comments

Hi, I am working on an application whose configuration is provided in the form of environment variables, so we rely on the load_yaml method to load a config file with environment variable references, like this:

db:
  readonly:
    host: ${MYSQL_RO_HOST:db}
    port: ${MYSQL_RO_PORT:3306}
etc.

Now we are attempting to package the application in a PEX file, which is a single-file executable artifact containing a Python application, its libraries, and a Python runtime. Problem: the config.yaml file is bundled inside the PEX file, so it is not a file itself.

Using the standard library, I can open the resource to get a file-like object, or I can read the resource into memory as a string. Is there a way to use either of these to load the config and still get environment variable interpolation?

davidkh avatar Apr 10 '22 16:04 davidkh