Type-safe configuration management for Gleam applications
What is dream_config?
A standalone module for loading configuration from environment variables and .env files. It is built with the same quality standards as Dream, but it is completely independent. Use it in any Gleam project.
Features
- ✅ Load from environment variables or
.envfiles - ✅ The environment wins over a
.envfile, so the platform's values are never replaced (the override functions let the file win) - ✅ One typed error for every read:
NotSet,NotAnIntegerorEmpty, with the variable name - ✅ A typed error for a bad
.envfile, with the path and the line number - ✅ Support for strings, integers, and booleans
- ✅ Required vs optional configuration values, and an empty required value is an error
- ✅ Zero dependencies on Dream or other frameworks
Installation
gleam add dream_config
Quick Start
Read your settings into a record. Each error names the variable:
Read the settings into a record

import dream_config/loader.{type ConfigError} as config
import gleam/result
pub type Settings {
Settings(database_url: String, port: Int, debug_mode: Bool, api_key: String)
}
pub fn load_settings() -> Result(Settings, ConfigError) {
// Required: the error names the variable that is not set, empty or wrong
use database_url <- result.try(config.get_required("DATABASE_URL"))
use port <- result.try(config.get_required_int("PORT"))
// Optional, with defaults
let debug_mode = config.get_bool("DEBUG")
let api_key = config.get("API_KEY") |> result.unwrap("default-key")
Ok(Settings(database_url:, port:, debug_mode:, api_key:))
}
Then load the .env file and the settings one time at startup, and stop with the reason when one is missing or wrong:
Start the app or stop with the reason

import dream_config/loader as config
import gleam/int
import gleam/io
import gleam/result
import snippets/readme_quick_start.{type Settings, load_settings}
pub fn main() -> Nil {
case start() {
Ok(message) -> io.println(message)
Error(reason) -> {
io.println_error("Cannot start: " <> reason)
halt(1)
}
}
}
pub fn start() -> Result(String, String) {
// Local values. A variable that is already set keeps its value.
use _ <- result.try(
config.load_dotenv() |> result.map_error(config.describe_load_error),
)
use settings <- result.try(
load_settings() |> result.map_error(config.describe),
)
Ok(serve(settings))
}
fn serve(settings: Settings) -> String {
"Listening on port " <> int.to_string(settings.port)
}
@external(erlang, "erlang", "halt")
fn halt(status: Int) -> Nil
Guides
- Getting started: load your app's settings into a typed record at startup, stop with a clear message when one is missing, empty or wrong, and test the loader
- Use a .env file in development: which value wins between the environment and the file, the override functions, a secrets file from a path, the file format, and the errors for a bad file
- Read optional settings, numbers and flags: defaults that apply only when a setting is not set, range checks, and the values that
get_boolaccepts
API Reference
The full API reference is on HexDocs.
Design Principles
dream_config follows Dream's design principles and contributing guide.
About Dream
This module was originally built for the Dream web toolkit, but it's completely standalone and can be used in any Gleam project. It follows Dream's design principles and will be maintained as part of the Dream ecosystem.
Contributing
See the Contributing Guide. The coding and testing standards are Dream's: see Dream's contributing guide.
License
MIT — see LICENSE.md