We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[bug][Documentation] Exporting: write() got an unexpected keyword argument 'merge'
**Describe the bug**
Following the example on the documentation to [export](https://www.dynaconf.com/advanced/#exporting) Dynaconf data to a file raises an exception with the `merge` argument

**To Reproduce**
~~~Python
loaders.write("/a/b/c", DynaBox(config).to_dict(), merge=False)
~~~

**Expected behavior**
The file should have been written

**Actual Behavior**
`TypeError: write() got an unexpected keyword argument 'merge'`

Just a quick documentation fix,
thanks !


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dynaconf/loaders/__init__.py`
Content:
```
1 from __future__ import annotations
2 
3 import importlib
4 import os
5 
6 from dynaconf import constants as ct
7 from dynaconf import default_settings
8 from dynaconf.loaders import ini_loader
9 from dynaconf.loaders import json_loader
10 from dynaconf.loaders import py_loader
11 from dynaconf.loaders import toml_loader
12 from dynaconf.loaders import yaml_loader
13 from dynaconf.utils import deduplicate
14 from dynaconf.utils import ensure_a_list
15 from dynaconf.utils.boxing import DynaBox
16 from dynaconf.utils.files import get_local_filename
17 from dynaconf.utils.parse_conf import false_values
18 
19 
20 def default_loader(obj, defaults=None):
21     """Loads default settings and check if there are overridings
22     exported as environment variables"""
23     defaults = defaults or {}
24     default_settings_values = {
25         key: value
26         for key, value in default_settings.__dict__.items()  # noqa
27         if key.isupper()
28     }
29 
30     all_keys = deduplicate(
31         list(defaults.keys()) + list(default_settings_values.keys())
32     )
33 
34     for key in all_keys:
35         if not obj.exists(key):
36             value = defaults.get(key, default_settings_values.get(key))
37             obj.set(key, value)
38 
39     # start dotenv to get default env vars from there
40     # check overrides in env vars
41     if obj.get("load_dotenv") is True:
42         default_settings.start_dotenv(obj)
43 
44     # Deal with cases where a custom ENV_SWITCHER_IS_PROVIDED
45     # Example: Flask and Django Extensions
46     env_switcher = defaults.get(
47         "ENV_SWITCHER_FOR_DYNACONF", "ENV_FOR_DYNACONF"
48     )
49 
50     for key in all_keys:
51         if key not in default_settings_values.keys():
52             continue
53 
54         env_value = obj.get_environ(
55             env_switcher if key == "ENV_FOR_DYNACONF" else key,
56             default="_not_found",
57         )
58 
59         if env_value != "_not_found":
60             obj.set(key, env_value, tomlfy=True)
61 
62 
63 def _run_hook_module(hook, hook_module, obj, key=None):
64     """Run the hook function from the settings obj.
65 
66     given a hook name, a hook_module and a settings object
67     load the function and execute if found.
68     """
69     if hook in obj._loaded_hooks.get(hook_module.__file__, {}):
70         # already loaded
71         return
72 
73     if hook_module and getattr(hook_module, "_error", False):
74         if not isinstance(hook_module._error, FileNotFoundError):
75             raise hook_module._error
76 
77     hook_func = getattr(hook_module, hook, None)
78     if hook_func:
79         hook_dict = hook_func(obj.dynaconf.clone())
80         if hook_dict:
81             merge = hook_dict.pop(
82                 "dynaconf_merge", hook_dict.pop("DYNACONF_MERGE", False)
83             )
84             if key and key in hook_dict:
85                 obj.set(key, hook_dict[key], tomlfy=False, merge=merge)
86             elif not key:
87                 obj.update(hook_dict, tomlfy=False, merge=merge)
88         obj._loaded_hooks[hook_module.__file__][hook] = hook_dict
89 
90 
91 def execute_hooks(
92     hook, obj, env=None, silent=True, key=None, modules=None, files=None
93 ):
94     """Execute dynaconf_hooks from module or filepath."""
95     if hook not in ["post"]:
96         raise ValueError(f"hook {hook} not supported yet.")
97 
98     # try to load hooks using python module __name__
99     modules = modules or obj._loaded_py_modules
100     for loaded_module in modules:
101         hook_module_name = ".".join(
102             loaded_module.split(".")[:-1] + ["dynaconf_hooks"]
103         )
104         try:
105             hook_module = importlib.import_module(hook_module_name)
106         except (ImportError, TypeError):
107             # There was no hook on the same path as a python module
108             continue
109         else:
110             _run_hook_module(
111                 hook=hook,
112                 hook_module=hook_module,
113                 obj=obj,
114                 key=key,
115             )
116 
117     # Try to load from python filename path
118     files = files or obj._loaded_files
119     for loaded_file in files:
120         hook_file = os.path.join(
121             os.path.dirname(loaded_file), "dynaconf_hooks.py"
122         )
123         hook_module = py_loader.import_from_filename(
124             obj, hook_file, silent=silent
125         )
126         if not hook_module:
127             # There was no hook on the same path as a python file
128             continue
129         _run_hook_module(
130             hook=hook,
131             hook_module=hook_module,
132             obj=obj,
133             key=key,
134         )
135 
136 
137 def settings_loader(
138     obj, settings_module=None, env=None, silent=True, key=None, filename=None
139 ):
140     """Loads from defined settings module
141 
142     :param obj: A dynaconf instance
143     :param settings_module: A path or a list of paths e.g settings.toml
144     :param env: Env to look for data defaults: development
145     :param silent: Boolean to raise loading errors
146     :param key: Load a single key if provided
147     :param filename: optional filename to override the settings_module
148     """
149     if filename is None:
150         settings_module = settings_module or obj.settings_module
151         if not settings_module:  # pragma: no cover
152             return
153         files = ensure_a_list(settings_module)
154     else:
155         files = ensure_a_list(filename)
156 
157     files.extend(ensure_a_list(obj.get("SECRETS_FOR_DYNACONF", None)))
158 
159     found_files = []
160     modules_names = []
161     for item in files:
162         item = str(item)  # Ensure str in case of LocalPath/Path is passed.
163         if item.endswith(ct.ALL_EXTENSIONS + (".py",)):
164             p_root = obj._root_path or (
165                 os.path.dirname(found_files[0]) if found_files else None
166             )
167             found = obj.find_file(item, project_root=p_root)
168             if found:
169                 found_files.append(found)
170         else:
171             # a bare python module name w/o extension
172             modules_names.append(item)
173 
174     enabled_core_loaders = [
175         item.upper() for item in obj.get("CORE_LOADERS_FOR_DYNACONF") or []
176     ]
177 
178     # add `.local.` to found_files list to search for local files.
179     found_files.extend(
180         [
181             get_local_filename(item)
182             for item in found_files
183             if ".local." not in str(item)
184         ]
185     )
186 
187     for mod_file in modules_names + found_files:
188         # can be set to multiple files settings.py,settings.yaml,...
189 
190         # Cascade all loaders
191         loaders = [
192             {"ext": ct.YAML_EXTENSIONS, "name": "YAML", "loader": yaml_loader},
193             {"ext": ct.TOML_EXTENSIONS, "name": "TOML", "loader": toml_loader},
194             {"ext": ct.INI_EXTENSIONS, "name": "INI", "loader": ini_loader},
195             {"ext": ct.JSON_EXTENSIONS, "name": "JSON", "loader": json_loader},
196         ]
197 
198         for loader in loaders:
199             if loader["name"] not in enabled_core_loaders:
200                 continue
201 
202             if mod_file.endswith(loader["ext"]):
203                 loader["loader"].load(
204                     obj, filename=mod_file, env=env, silent=silent, key=key
205                 )
206                 continue
207 
208         if mod_file.endswith(ct.ALL_EXTENSIONS):
209             continue
210 
211         if "PY" not in enabled_core_loaders:
212             # pyloader is disabled
213             continue
214 
215         # must be Python file or module
216         # load from default defined module settings.py or .secrets.py if exists
217         py_loader.load(obj, mod_file, key=key)
218 
219         # load from the current env e.g: development_settings.py
220         env = env or obj.current_env
221         if mod_file.endswith(".py"):
222             if ".secrets.py" == mod_file:
223                 tmpl = ".{0}_{1}{2}"
224                 mod_file = "secrets.py"
225             else:
226                 tmpl = "{0}_{1}{2}"
227 
228             dirname = os.path.dirname(mod_file)
229             filename, extension = os.path.splitext(os.path.basename(mod_file))
230             new_filename = tmpl.format(env.lower(), filename, extension)
231             env_mod_file = os.path.join(dirname, new_filename)
232             global_filename = tmpl.format("global", filename, extension)
233             global_mod_file = os.path.join(dirname, global_filename)
234         else:
235             env_mod_file = f"{env.lower()}_{mod_file}"
236             global_mod_file = f"global_{mod_file}"
237 
238         py_loader.load(
239             obj,
240             env_mod_file,
241             identifier=f"py_{env.upper()}",
242             silent=True,
243             key=key,
244         )
245 
246         # load from global_settings.py
247         py_loader.load(
248             obj, global_mod_file, identifier="py_global", silent=True, key=key
249         )
250 
251 
252 def enable_external_loaders(obj):
253     """Enable external service loaders like `VAULT_` and `REDIS_`
254     looks forenv variables like `REDIS_ENABLED_FOR_DYNACONF`
255     """
256     for name, loader in ct.EXTERNAL_LOADERS.items():
257         enabled = getattr(obj, f"{name.upper()}_ENABLED_FOR_DYNACONF", False)
258         if (
259             enabled
260             and enabled not in false_values
261             and loader not in obj.LOADERS_FOR_DYNACONF
262         ):  # noqa
263             obj.LOADERS_FOR_DYNACONF.insert(0, loader)
264 
265 
266 def write(filename, data, env=None):
267     """Writes `data` to `filename` infers format by file extension."""
268     loader_name = f"{filename.rpartition('.')[-1]}_loader"
269     loader = globals().get(loader_name)
270     if not loader:
271         raise OSError(f"{loader_name} cannot be found.")
272 
273     data = DynaBox(data, box_settings={}).to_dict()
274     if loader is not py_loader and env and env not in data:
275         data = {env: data}
276 
277     loader.write(filename, data, merge=False)
278
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dynaconf/loaders/__init__.py b/dynaconf/loaders/__init__.py
--- a/dynaconf/loaders/__init__.py
+++ b/dynaconf/loaders/__init__.py
@@ -263,7 +263,7 @@
             obj.LOADERS_FOR_DYNACONF.insert(0, loader)
 
 
-def write(filename, data, env=None):
+def write(filename, data, env=None, merge=False):
     """Writes `data` to `filename` infers format by file extension."""
     loader_name = f"{filename.rpartition('.')[-1]}_loader"
     loader = globals().get(loader_name)
@@ -274,4 +274,4 @@
     if loader is not py_loader and env and env not in data:
         data = {env: data}
 
-    loader.write(filename, data, merge=False)
+    loader.write(filename, data, merge=merge)

{"golden_diff": "diff --git a/dynaconf/loaders/__init__.py b/dynaconf/loaders/__init__.py\n--- a/dynaconf/loaders/__init__.py\n+++ b/dynaconf/loaders/__init__.py\n@@ -263,7 +263,7 @@\n             obj.LOADERS_FOR_DYNACONF.insert(0, loader)\n \n \n-def write(filename, data, env=None):\n+def write(filename, data, env=None, merge=False):\n     \"\"\"Writes `data` to `filename` infers format by file extension.\"\"\"\n     loader_name = f\"{filename.rpartition('.')[-1]}_loader\"\n     loader = globals().get(loader_name)\n@@ -274,4 +274,4 @@\n     if loader is not py_loader and env and env not in data:\n         data = {env: data}\n \n-    loader.write(filename, data, merge=False)\n+    loader.write(filename, data, merge=merge)\n", "issue": "[bug][Documentation] Exporting: write() got an unexpected keyword argument 'merge'\n**Describe the bug**\r\nFollowing the example on the documentation to [export](https://www.dynaconf.com/advanced/#exporting) Dynaconf data to a file raises an exception with the `merge` argument\r\n\r\n**To Reproduce**\r\n~~~Python\r\nloaders.write(\"/a/b/c\", DynaBox(config).to_dict(), merge=False)\r\n~~~\r\n\r\n**Expected behavior**\r\nThe file should have been written\r\n\r\n**Actual Behavior**\r\n`TypeError: write() got an unexpected keyword argument 'merge'`\r\n\r\nJust a quick documentation fix,\r\nthanks !\r\n\n", "before_files": [{"content": "from __future__ import annotations\n\nimport importlib\nimport os\n\nfrom dynaconf import constants as ct\nfrom dynaconf import default_settings\nfrom dynaconf.loaders import ini_loader\nfrom dynaconf.loaders import json_loader\nfrom dynaconf.loaders import py_loader\nfrom dynaconf.loaders import toml_loader\nfrom dynaconf.loaders import yaml_loader\nfrom dynaconf.utils import deduplicate\nfrom dynaconf.utils import ensure_a_list\nfrom dynaconf.utils.boxing import DynaBox\nfrom dynaconf.utils.files import get_local_filename\nfrom dynaconf.utils.parse_conf import false_values\n\n\ndef default_loader(obj, defaults=None):\n    \"\"\"Loads default settings and check if there are overridings\n    exported as environment variables\"\"\"\n    defaults = defaults or {}\n    default_settings_values = {\n        key: value\n        for key, value in default_settings.__dict__.items()  # noqa\n        if key.isupper()\n    }\n\n    all_keys = deduplicate(\n        list(defaults.keys()) + list(default_settings_values.keys())\n    )\n\n    for key in all_keys:\n        if not obj.exists(key):\n            value = defaults.get(key, default_settings_values.get(key))\n            obj.set(key, value)\n\n    # start dotenv to get default env vars from there\n    # check overrides in env vars\n    if obj.get(\"load_dotenv\") is True:\n        default_settings.start_dotenv(obj)\n\n    # Deal with cases where a custom ENV_SWITCHER_IS_PROVIDED\n    # Example: Flask and Django Extensions\n    env_switcher = defaults.get(\n        \"ENV_SWITCHER_FOR_DYNACONF\", \"ENV_FOR_DYNACONF\"\n    )\n\n    for key in all_keys:\n        if key not in default_settings_values.keys():\n            continue\n\n        env_value = obj.get_environ(\n            env_switcher if key == \"ENV_FOR_DYNACONF\" else key,\n            default=\"_not_found\",\n        )\n\n        if env_value != \"_not_found\":\n            obj.set(key, env_value, tomlfy=True)\n\n\ndef _run_hook_module(hook, hook_module, obj, key=None):\n    \"\"\"Run the hook function from the settings obj.\n\n    given a hook name, a hook_module and a settings object\n    load the function and execute if found.\n    \"\"\"\n    if hook in obj._loaded_hooks.get(hook_module.__file__, {}):\n        # already loaded\n        return\n\n    if hook_module and getattr(hook_module, \"_error\", False):\n        if not isinstance(hook_module._error, FileNotFoundError):\n            raise hook_module._error\n\n    hook_func = getattr(hook_module, hook, None)\n    if hook_func:\n        hook_dict = hook_func(obj.dynaconf.clone())\n        if hook_dict:\n            merge = hook_dict.pop(\n                \"dynaconf_merge\", hook_dict.pop(\"DYNACONF_MERGE\", False)\n            )\n            if key and key in hook_dict:\n                obj.set(key, hook_dict[key], tomlfy=False, merge=merge)\n            elif not key:\n                obj.update(hook_dict, tomlfy=False, merge=merge)\n        obj._loaded_hooks[hook_module.__file__][hook] = hook_dict\n\n\ndef execute_hooks(\n    hook, obj, env=None, silent=True, key=None, modules=None, files=None\n):\n    \"\"\"Execute dynaconf_hooks from module or filepath.\"\"\"\n    if hook not in [\"post\"]:\n        raise ValueError(f\"hook {hook} not supported yet.\")\n\n    # try to load hooks using python module __name__\n    modules = modules or obj._loaded_py_modules\n    for loaded_module in modules:\n        hook_module_name = \".\".join(\n            loaded_module.split(\".\")[:-1] + [\"dynaconf_hooks\"]\n        )\n        try:\n            hook_module = importlib.import_module(hook_module_name)\n        except (ImportError, TypeError):\n            # There was no hook on the same path as a python module\n            continue\n        else:\n            _run_hook_module(\n                hook=hook,\n                hook_module=hook_module,\n                obj=obj,\n                key=key,\n            )\n\n    # Try to load from python filename path\n    files = files or obj._loaded_files\n    for loaded_file in files:\n        hook_file = os.path.join(\n            os.path.dirname(loaded_file), \"dynaconf_hooks.py\"\n        )\n        hook_module = py_loader.import_from_filename(\n            obj, hook_file, silent=silent\n        )\n        if not hook_module:\n            # There was no hook on the same path as a python file\n            continue\n        _run_hook_module(\n            hook=hook,\n            hook_module=hook_module,\n            obj=obj,\n            key=key,\n        )\n\n\ndef settings_loader(\n    obj, settings_module=None, env=None, silent=True, key=None, filename=None\n):\n    \"\"\"Loads from defined settings module\n\n    :param obj: A dynaconf instance\n    :param settings_module: A path or a list of paths e.g settings.toml\n    :param env: Env to look for data defaults: development\n    :param silent: Boolean to raise loading errors\n    :param key: Load a single key if provided\n    :param filename: optional filename to override the settings_module\n    \"\"\"\n    if filename is None:\n        settings_module = settings_module or obj.settings_module\n        if not settings_module:  # pragma: no cover\n            return\n        files = ensure_a_list(settings_module)\n    else:\n        files = ensure_a_list(filename)\n\n    files.extend(ensure_a_list(obj.get(\"SECRETS_FOR_DYNACONF\", None)))\n\n    found_files = []\n    modules_names = []\n    for item in files:\n        item = str(item)  # Ensure str in case of LocalPath/Path is passed.\n        if item.endswith(ct.ALL_EXTENSIONS + (\".py\",)):\n            p_root = obj._root_path or (\n                os.path.dirname(found_files[0]) if found_files else None\n            )\n            found = obj.find_file(item, project_root=p_root)\n            if found:\n                found_files.append(found)\n        else:\n            # a bare python module name w/o extension\n            modules_names.append(item)\n\n    enabled_core_loaders = [\n        item.upper() for item in obj.get(\"CORE_LOADERS_FOR_DYNACONF\") or []\n    ]\n\n    # add `.local.` to found_files list to search for local files.\n    found_files.extend(\n        [\n            get_local_filename(item)\n            for item in found_files\n            if \".local.\" not in str(item)\n        ]\n    )\n\n    for mod_file in modules_names + found_files:\n        # can be set to multiple files settings.py,settings.yaml,...\n\n        # Cascade all loaders\n        loaders = [\n            {\"ext\": ct.YAML_EXTENSIONS, \"name\": \"YAML\", \"loader\": yaml_loader},\n            {\"ext\": ct.TOML_EXTENSIONS, \"name\": \"TOML\", \"loader\": toml_loader},\n            {\"ext\": ct.INI_EXTENSIONS, \"name\": \"INI\", \"loader\": ini_loader},\n            {\"ext\": ct.JSON_EXTENSIONS, \"name\": \"JSON\", \"loader\": json_loader},\n        ]\n\n        for loader in loaders:\n            if loader[\"name\"] not in enabled_core_loaders:\n                continue\n\n            if mod_file.endswith(loader[\"ext\"]):\n                loader[\"loader\"].load(\n                    obj, filename=mod_file, env=env, silent=silent, key=key\n                )\n                continue\n\n        if mod_file.endswith(ct.ALL_EXTENSIONS):\n            continue\n\n        if \"PY\" not in enabled_core_loaders:\n            # pyloader is disabled\n            continue\n\n        # must be Python file or module\n        # load from default defined module settings.py or .secrets.py if exists\n        py_loader.load(obj, mod_file, key=key)\n\n        # load from the current env e.g: development_settings.py\n        env = env or obj.current_env\n        if mod_file.endswith(\".py\"):\n            if \".secrets.py\" == mod_file:\n                tmpl = \".{0}_{1}{2}\"\n                mod_file = \"secrets.py\"\n            else:\n                tmpl = \"{0}_{1}{2}\"\n\n            dirname = os.path.dirname(mod_file)\n            filename, extension = os.path.splitext(os.path.basename(mod_file))\n            new_filename = tmpl.format(env.lower(), filename, extension)\n            env_mod_file = os.path.join(dirname, new_filename)\n            global_filename = tmpl.format(\"global\", filename, extension)\n            global_mod_file = os.path.join(dirname, global_filename)\n        else:\n            env_mod_file = f\"{env.lower()}_{mod_file}\"\n            global_mod_file = f\"global_{mod_file}\"\n\n        py_loader.load(\n            obj,\n            env_mod_file,\n            identifier=f\"py_{env.upper()}\",\n            silent=True,\n            key=key,\n        )\n\n        # load from global_settings.py\n        py_loader.load(\n            obj, global_mod_file, identifier=\"py_global\", silent=True, key=key\n        )\n\n\ndef enable_external_loaders(obj):\n    \"\"\"Enable external service loaders like `VAULT_` and `REDIS_`\n    looks forenv variables like `REDIS_ENABLED_FOR_DYNACONF`\n    \"\"\"\n    for name, loader in ct.EXTERNAL_LOADERS.items():\n        enabled = getattr(obj, f\"{name.upper()}_ENABLED_FOR_DYNACONF\", False)\n        if (\n            enabled\n            and enabled not in false_values\n            and loader not in obj.LOADERS_FOR_DYNACONF\n        ):  # noqa\n            obj.LOADERS_FOR_DYNACONF.insert(0, loader)\n\n\ndef write(filename, data, env=None):\n    \"\"\"Writes `data` to `filename` infers format by file extension.\"\"\"\n    loader_name = f\"{filename.rpartition('.')[-1]}_loader\"\n    loader = globals().get(loader_name)\n    if not loader:\n        raise OSError(f\"{loader_name} cannot be found.\")\n\n    data = DynaBox(data, box_settings={}).to_dict()\n    if loader is not py_loader and env and env not in data:\n        data = {env: data}\n\n    loader.write(filename, data, merge=False)\n", "path": "dynaconf/loaders/__init__.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport importlib\nimport os\n\nfrom dynaconf import constants as ct\nfrom dynaconf import default_settings\nfrom dynaconf.loaders import ini_loader\nfrom dynaconf.loaders import json_loader\nfrom dynaconf.loaders import py_loader\nfrom dynaconf.loaders import toml_loader\nfrom dynaconf.loaders import yaml_loader\nfrom dynaconf.utils import deduplicate\nfrom dynaconf.utils import ensure_a_list\nfrom dynaconf.utils.boxing import DynaBox\nfrom dynaconf.utils.files import get_local_filename\nfrom dynaconf.utils.parse_conf import false_values\n\n\ndef default_loader(obj, defaults=None):\n    \"\"\"Loads default settings and check if there are overridings\n    exported as environment variables\"\"\"\n    defaults = defaults or {}\n    default_settings_values = {\n        key: value\n        for key, value in default_settings.__dict__.items()  # noqa\n        if key.isupper()\n    }\n\n    all_keys = deduplicate(\n        list(defaults.keys()) + list(default_settings_values.keys())\n    )\n\n    for key in all_keys:\n        if not obj.exists(key):\n            value = defaults.get(key, default_settings_values.get(key))\n            obj.set(key, value)\n\n    # start dotenv to get default env vars from there\n    # check overrides in env vars\n    if obj.get(\"load_dotenv\") is True:\n        default_settings.start_dotenv(obj)\n\n    # Deal with cases where a custom ENV_SWITCHER_IS_PROVIDED\n    # Example: Flask and Django Extensions\n    env_switcher = defaults.get(\n        \"ENV_SWITCHER_FOR_DYNACONF\", \"ENV_FOR_DYNACONF\"\n    )\n\n    for key in all_keys:\n        if key not in default_settings_values.keys():\n            continue\n\n        env_value = obj.get_environ(\n            env_switcher if key == \"ENV_FOR_DYNACONF\" else key,\n            default=\"_not_found\",\n        )\n\n        if env_value != \"_not_found\":\n            obj.set(key, env_value, tomlfy=True)\n\n\ndef _run_hook_module(hook, hook_module, obj, key=None):\n    \"\"\"Run the hook function from the settings obj.\n\n    given a hook name, a hook_module and a settings object\n    load the function and execute if found.\n    \"\"\"\n    if hook in obj._loaded_hooks.get(hook_module.__file__, {}):\n        # already loaded\n        return\n\n    if hook_module and getattr(hook_module, \"_error\", False):\n        if not isinstance(hook_module._error, FileNotFoundError):\n            raise hook_module._error\n\n    hook_func = getattr(hook_module, hook, None)\n    if hook_func:\n        hook_dict = hook_func(obj.dynaconf.clone())\n        if hook_dict:\n            merge = hook_dict.pop(\n                \"dynaconf_merge\", hook_dict.pop(\"DYNACONF_MERGE\", False)\n            )\n            if key and key in hook_dict:\n                obj.set(key, hook_dict[key], tomlfy=False, merge=merge)\n            elif not key:\n                obj.update(hook_dict, tomlfy=False, merge=merge)\n        obj._loaded_hooks[hook_module.__file__][hook] = hook_dict\n\n\ndef execute_hooks(\n    hook, obj, env=None, silent=True, key=None, modules=None, files=None\n):\n    \"\"\"Execute dynaconf_hooks from module or filepath.\"\"\"\n    if hook not in [\"post\"]:\n        raise ValueError(f\"hook {hook} not supported yet.\")\n\n    # try to load hooks using python module __name__\n    modules = modules or obj._loaded_py_modules\n    for loaded_module in modules:\n        hook_module_name = \".\".join(\n            loaded_module.split(\".\")[:-1] + [\"dynaconf_hooks\"]\n        )\n        try:\n            hook_module = importlib.import_module(hook_module_name)\n        except (ImportError, TypeError):\n            # There was no hook on the same path as a python module\n            continue\n        else:\n            _run_hook_module(\n                hook=hook,\n                hook_module=hook_module,\n                obj=obj,\n                key=key,\n            )\n\n    # Try to load from python filename path\n    files = files or obj._loaded_files\n    for loaded_file in files:\n        hook_file = os.path.join(\n            os.path.dirname(loaded_file), \"dynaconf_hooks.py\"\n        )\n        hook_module = py_loader.import_from_filename(\n            obj, hook_file, silent=silent\n        )\n        if not hook_module:\n            # There was no hook on the same path as a python file\n            continue\n        _run_hook_module(\n            hook=hook,\n            hook_module=hook_module,\n            obj=obj,\n            key=key,\n        )\n\n\ndef settings_loader(\n    obj, settings_module=None, env=None, silent=True, key=None, filename=None\n):\n    \"\"\"Loads from defined settings module\n\n    :param obj: A dynaconf instance\n    :param settings_module: A path or a list of paths e.g settings.toml\n    :param env: Env to look for data defaults: development\n    :param silent: Boolean to raise loading errors\n    :param key: Load a single key if provided\n    :param filename: optional filename to override the settings_module\n    \"\"\"\n    if filename is None:\n        settings_module = settings_module or obj.settings_module\n        if not settings_module:  # pragma: no cover\n            return\n        files = ensure_a_list(settings_module)\n    else:\n        files = ensure_a_list(filename)\n\n    files.extend(ensure_a_list(obj.get(\"SECRETS_FOR_DYNACONF\", None)))\n\n    found_files = []\n    modules_names = []\n    for item in files:\n        item = str(item)  # Ensure str in case of LocalPath/Path is passed.\n        if item.endswith(ct.ALL_EXTENSIONS + (\".py\",)):\n            p_root = obj._root_path or (\n                os.path.dirname(found_files[0]) if found_files else None\n            )\n            found = obj.find_file(item, project_root=p_root)\n            if found:\n                found_files.append(found)\n        else:\n            # a bare python module name w/o extension\n            modules_names.append(item)\n\n    enabled_core_loaders = [\n        item.upper() for item in obj.get(\"CORE_LOADERS_FOR_DYNACONF\") or []\n    ]\n\n    # add `.local.` to found_files list to search for local files.\n    found_files.extend(\n        [\n            get_local_filename(item)\n            for item in found_files\n            if \".local.\" not in str(item)\n        ]\n    )\n\n    for mod_file in modules_names + found_files:\n        # can be set to multiple files settings.py,settings.yaml,...\n\n        # Cascade all loaders\n        loaders = [\n            {\"ext\": ct.YAML_EXTENSIONS, \"name\": \"YAML\", \"loader\": yaml_loader},\n            {\"ext\": ct.TOML_EXTENSIONS, \"name\": \"TOML\", \"loader\": toml_loader},\n            {\"ext\": ct.INI_EXTENSIONS, \"name\": \"INI\", \"loader\": ini_loader},\n            {\"ext\": ct.JSON_EXTENSIONS, \"name\": \"JSON\", \"loader\": json_loader},\n        ]\n\n        for loader in loaders:\n            if loader[\"name\"] not in enabled_core_loaders:\n                continue\n\n            if mod_file.endswith(loader[\"ext\"]):\n                loader[\"loader\"].load(\n                    obj, filename=mod_file, env=env, silent=silent, key=key\n                )\n                continue\n\n        if mod_file.endswith(ct.ALL_EXTENSIONS):\n            continue\n\n        if \"PY\" not in enabled_core_loaders:\n            # pyloader is disabled\n            continue\n\n        # must be Python file or module\n        # load from default defined module settings.py or .secrets.py if exists\n        py_loader.load(obj, mod_file, key=key)\n\n        # load from the current env e.g: development_settings.py\n        env = env or obj.current_env\n        if mod_file.endswith(\".py\"):\n            if \".secrets.py\" == mod_file:\n                tmpl = \".{0}_{1}{2}\"\n                mod_file = \"secrets.py\"\n            else:\n                tmpl = \"{0}_{1}{2}\"\n\n            dirname = os.path.dirname(mod_file)\n            filename, extension = os.path.splitext(os.path.basename(mod_file))\n            new_filename = tmpl.format(env.lower(), filename, extension)\n            env_mod_file = os.path.join(dirname, new_filename)\n            global_filename = tmpl.format(\"global\", filename, extension)\n            global_mod_file = os.path.join(dirname, global_filename)\n        else:\n            env_mod_file = f\"{env.lower()}_{mod_file}\"\n            global_mod_file = f\"global_{mod_file}\"\n\n        py_loader.load(\n            obj,\n            env_mod_file,\n            identifier=f\"py_{env.upper()}\",\n            silent=True,\n            key=key,\n        )\n\n        # load from global_settings.py\n        py_loader.load(\n            obj, global_mod_file, identifier=\"py_global\", silent=True, key=key\n        )\n\n\ndef enable_external_loaders(obj):\n    \"\"\"Enable external service loaders like `VAULT_` and `REDIS_`\n    looks forenv variables like `REDIS_ENABLED_FOR_DYNACONF`\n    \"\"\"\n    for name, loader in ct.EXTERNAL_LOADERS.items():\n        enabled = getattr(obj, f\"{name.upper()}_ENABLED_FOR_DYNACONF\", False)\n        if (\n            enabled\n            and enabled not in false_values\n            and loader not in obj.LOADERS_FOR_DYNACONF\n        ):  # noqa\n            obj.LOADERS_FOR_DYNACONF.insert(0, loader)\n\n\ndef write(filename, data, env=None, merge=False):\n    \"\"\"Writes `data` to `filename` infers format by file extension.\"\"\"\n    loader_name = f\"{filename.rpartition('.')[-1]}_loader\"\n    loader = globals().get(loader_name)\n    if not loader:\n        raise OSError(f\"{loader_name} cannot be found.\")\n\n    data = DynaBox(data, box_settings={}).to_dict()\n    if loader is not py_loader and env and env not in data:\n        data = {env: data}\n\n    loader.write(filename, data, merge=merge)\n", "path": "dynaconf/loaders/__init__.py"}]}