Skip to content

Commit

Permalink
Add EnvVar vs os.getenv section
Browse files Browse the repository at this point in the history
  • Loading branch information
erinkcochran87 committed Nov 16, 2023
1 parent ce9d021 commit 8ae4c7e
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Refer to the [Dagster Cloud Branch Deployments example](#example-2-dagster-cloud

### From Dagster configuration

[Configurable Dagster objects](/concepts/configuration/config-schema) - such as ops, assets, resources, I/O managers, and so on - can accept configuration from environment variables. Dagster provides a native way to specify environment variables in your configuration. These environment variables are retrieved at launch time, rather than on initialization as with `os.getenv`.
[Configurable Dagster objects](/concepts/configuration/config-schema) - such as ops, assets, resources, I/O managers, and so on - can accept configuration from environment variables. Dagster provides a native way to specify environment variables in your configuration. These environment variables are retrieved at launch time, rather than on initialization as with `os.getenv`. Refer to the [next section](##using-envvar-vs-osgetenv) for more info.

<TabGroup>
<TabItem name="In Python code">
Expand Down Expand Up @@ -147,6 +147,15 @@ Refer to the [Handling secrets section](#handling-secrets) and [Per-environment
</TabItem>
</TabGroup>

### Using EnvVar vs os.getenv

We just covered two different ways to access environment variables in Dagster. So, which one should you use? When choosing an approach, keep the following in mind:

- **When `os.getenv` is used**, the variable's value is retrieved when Dagster loads the [code location](/concepts/code-locations) and **will** be visible in the UI.
- **When `EnvVar` is used**, the variable's value is retrieved at runtime and **won't** be visible in the UI.

<EnvVarsBenefits />

---

## Handling secrets
Expand Down Expand Up @@ -249,7 +258,7 @@ defs = Definitions(

Let's review what's happening here:

- We've created a dictionary of resource definitions, `resources`, named after our `local` and `production` environments. In this example, we're using a [Pandas Snowflake I/O manager](/\_apidocs/libraries/dagster-snowflake-pandas).
- We've created a dictionary of resource definitions, `resources`, named after our `local` and `production` environments. In this example, we're using a [Pandas Snowflake I/O manager](/_apidocs/libraries/dagster-snowflake-pandas).
- For both `local` and `production`, we constructed the I/O manager using environment-specific run configuration. Note the differences in configuration between `local` and `production`, specifically where environment variables were used.
- Following the `resources` dictionary, we define the `deployment_name` variable, which determines the current executing environment. This variable defaults to `local`, ensuring that `DAGSTER_DEPLOYMENT=PRODUCTION` must be set to use the `production` configuration.

Expand Down

0 comments on commit 8ae4c7e

Please sign in to comment.