https://dagster.io/ logo
#ask-community
Title
# ask-community
s

Sebastien

05/17/2023, 6:34 PM
Hi experts, I dont find where to put my .env file, EnvVar just return the KEY, not the value. How to know what is folder where dagit or dagster-daemon is started ? I start from .bat file cd C:/myproject D:/python/venv/myVenv/Script/dagster dev I suppose .env must be here : C:/myproject/.env But it doesnot work 🤔 D:/python/venv/myVenv/Script/.env doesnot work too 😕 Tx for help
d

Daniel Kim

05/18/2023, 2:14 AM
.env file is supposed to be located where you launch dagster dev from, so in your case: D:/python/venv/myVenv/Script/ But I think the issue is how or where you are using EnvVar as I also ran into this unexpectedly. I think this line from the docs can be easily overlooked as I certainly did: "Configurable Dagster objects - such as ops, assets, resources, I/O managers, and so on - can accept configuration from environment variables." So I think what this means is that EnvVar() doesn't work outside of those configurable dagster objects. In other words as an example, the last line below in my example code, my print statement below only prints the key and not the value. I was expecting that it would print the value and not the key. When it is in the configured() function, it worked as expected, it got the key's value from the .env file. But after re-reading that line from the docs, I realize perhaps I can't use EnvVar outside of a configurable object. I could be wrong though or maybe we should be able to and it doesn't work on Windows. I'm hoping someone from dagster team can chime in and confirm. I'll have to check in my Ubuntu WSL if I'm getting the same result. To be honest, I would like to be able to use EnvVar in any context or anywhere in my Python script in the event I want to pass that value to a variable that I can then use with a non-configurable Dagster object.
Copy code
defs = Definitions(
    assets=[build_asset(data_set) for data_set in data_sets],
    resources={
        "faa_io_manager": duckdb_pandas_io_manager.configured(
            {
                "database": EnvVar("DUCKDB_FAA_DB"),
            }
        ),
    },
)

print(f'DUCKDB_FAA_DB: {EnvVar("DUCKDB_FAA_DB")}')
🤖 1
s

Sebastien

05/18/2023, 7:17 AM
Thanks you for your answer, I tried to use EnvVar to set the 'compute_kind' value of an asset for exemple. I will try with other contexts to understand better what is the good way to use EnvVar fonction. Tx
j

jamie

05/18/2023, 2:15 PM
Hey there, I believe Daniel is correct. Internally, EnvVar is just a wrapper around a string. We use it for configuration of resources, io managers, and in Config classes so that the fetching of the environment variable can be delayed until execution time, but the logic that handles that is specific to those cases (resources, io managers, config). In other use cases, you should use
os.getenv
👍 1
s

Sebastien

05/18/2023, 2:18 PM
Copy 🫡