1"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[2865],{22546(e,n,i){i.r(n),i.d(n,{assets:()=>l,contentTitle:()=>c,default:()=>u,frontMatter:()=>a,metadata:()=>t,toc:()=>d});const t=JSON.parse('{"id":"tutorials/basic/your_first_app/config_file","title":"Specifying a config file","description":"It can get tedious to type all those command line arguments.","source":"@site/versioned_docs/version-1.0/tutorials/basic/your_first_app/2_config_file.md","sourceDirName":"tutorials/basic/your_first_app","slug":"/tutorials/basic/your_first_app/config_file","permalink":"/docs/1.0/tutorials/basic/your_first_app/config_file","draft":false,"unlisted":false,"editUrl":"https://github.com/hydra-ecosystem/hydra/edit/main/website/versioned_docs/version-1.0/tutorials/basic/your_first_app/2_config_file.md","tags":[],"version":"1.0","sidebarPosition":2,"frontMatter":{"id":"config_file","title":"Specifying a config file"},"sidebar":"docs","previous":{"title":"A simple command-line application","permalink":"/docs/1.0/tutorials/basic/your_first_app/simple_cli"},"next":{"title":"Using the config object","permalink":"/docs/1.0/tutorials/basic/your_first_app/using_config"}}');var o=i(11684),s=i(32435),r=i(68625);const a={id:"config_file",title:"Specifying a config file"},c=void 0,l={},d=[];function p(e){const n={a:"a",br:"br",code:"code",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(r.C,{to:"examples/tutorials/basic/your_first_hydra_app/2_config_file"}),"\n",(0,o.jsx)(n.p,{children:"It can get tedious to type all those command line arguments.\nYou can solve it by creating a configuration file next to my_app.py.\nHydra configuration files are yaml files and should have the .yaml file extension."}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-yaml",metastring:'title="config.yaml"',children:"db: \n driver: mysql\n user: omry\n password: secret\n"})}),"\n",(0,o.jsxs)(n.p,{children:["Specify the config name by passing a ",(0,o.jsx)(n.code,{children:"config_name"})," parameter to the ",(0,o.jsx)(n.code,{children:"@hydra.main()"})," decorator.\nNote that you should omit the ",(0,o.jsx)(n.code,{children:".yaml"})," extension."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-python",metastring:'title="my_app.py" {1}',children:"@hydra.main(config_name='config')\ndef my_app(cfg):\n print(OmegaConf.to_yaml(cfg))\n"})}),"\n",(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"config.yaml"})," is loaded automatically when you run your application."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-yaml",children:"$ python my_app.py\ndb:\n driver: mysql\n user: omry\n password: secret\n"})}),"\n",(0,o.jsxs)(n.p,{children:["You can override values in the loaded config from the command line.",(0,o.jsx)(n.br,{}),"\n","Note the lack of the ",(0,o.jsx)(n.code,{children:"+"})," prefix."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-yaml",metastring:"{4-5}",children:"$ python my_app.py db.user=root db.password=1234\ndb:\n driver: mysql\n user: root\n password: 1234\n"})}),"\n",(0,o.jsxs)(n.p,{children:["You can enable ",(0,o.jsx)(n.a,{href:"/docs/1.0/tutorials/basic/running_your_app/tab_completion",children:"tab completion"})," for your Hydra applications."]})]})}function u(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(p,{...e})}):p(e)}},68625(e,n,i){i.d(n,{A:()=>c,C:()=>l});i(12888);var t=i(65528),o=i(69920),s=i(13530),r=i(11684);function a(e){var n;const i=(0,s.ir)();return(0,o.A)().siteConfig.customFields.githubLinkVersionToBaseUrl[null!=(n=null==i?void 0:i.name)?n:"current"]+e}function c(e){return(0,r.jsx)(t.A,Object.assign({},e,{to:a(e.to),target:"_blank"}))}function l(e){var n;const i=null!=(n=e.text)?n:"Example (Click Here)";return(0,r.jsxs)(c,Object.assign({},e,{children:[(0,r.jsx)("span",{children:"\xa0"}),(0,r.jsx)("img",{src:"https://img.shields.io/badge/-"+i+"-informational",alt:"Example (Click Here)"})]}))}},32435(e,n,i){i.d(n,{R:()=>r,x:()=>a});var t=i(12888);const o={},s=t.createContext(o);function r(e){const n=t.useContext(s);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(s.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.