def merge(defaults, file, env):
    """Merge configuration from defaults, file, and environment."""
    config = defaults

    # Merge in file options, if they exist in the defaults.
    for (k, v) in file.items():
        if k in config:
            config[k] = v

    # Merge in environment options, if they exist in the defaults.
    for (k, v) in env.items():
        if k in config:
            config[k] = v

    return config