helpers for yaml

loadYamlUrl

loadYamlUrl[source]

loadYamlUrl(url:str, headers:dict={}, loader=FullLoader)

load yaml from url as a dictionary for example: testUrl = 'https://raw.githubusercontent.com/thanakijwanavit/villaMasterSchema/dev/coupon/testData/buyXGetY.yaml' loadYamlUrl(testUrl) input: url:str: url of the file headers:Optional[dict]:headers loader:yaml.Loader: optional yaml loader default is yaml.FullLoader response: dict: yaml load of the file

testUrl = 'https://raw.githubusercontent.com/thanakijwanavit/villaMasterSchema/dev/coupon/testData/buyXGetY.yaml'
loadYamlUrl(testUrl)
{404: 'Not Found'}

load yaml from path

put in a pat and you should get a dictionary return

loadYaml[source]

loadYaml(path:str)

loadYaml('../docker-compose.yml')
{'version': '3',
 'services': {'fastai': {'restart': 'unless-stopped',
   'working_dir': '/data',
   'image': 'fastai/codespaces',
   'logging': {'driver': 'json-file', 'options': {'max-size': '50m'}},
   'stdin_open': True,
   'tty': True,
   'volumes': ['.:/data/']},
  'notebook': {'restart': 'unless-stopped',
   'working_dir': '/data',
   'image': 'fastai/codespaces',
   'logging': {'driver': 'json-file', 'options': {'max-size': '50m'}},
   'stdin_open': True,
   'tty': True,
   'volumes': ['.:/data/'],
   'command': 'bash -c "pip install -e . && jupyter notebook --allow-root --no-browser --ip=0.0.0.0 --port=8080 --NotebookApp.token=\'\' --NotebookApp.password=\'\'"',
   'ports': ['8080:8080']},
  'watcher': {'restart': 'unless-stopped',
   'working_dir': '/data',
   'image': 'fastai/codespaces',
   'logging': {'driver': 'json-file', 'options': {'max-size': '50m'}},
   'stdin_open': True,
   'tty': True,
   'volumes': ['.:/data/'],
   'command': 'watchmedo shell-command --command nbdev_build_docs --pattern *.ipynb --recursive --drop',
   'network_mode': 'host'},
  'jekyll': {'restart': 'unless-stopped',
   'working_dir': '/data',
   'image': 'fastai/codespaces',
   'logging': {'driver': 'json-file', 'options': {'max-size': '50m'}},
   'stdin_open': True,
   'tty': True,
   'volumes': ['.:/data/'],
   'ports': ['4000:4000'],
   'command': 'bash -c "cp -r docs_src docs && pip install . && nbdev_build_docs && cd docs && bundle i && chmod -R u+rwx . && bundle exec jekyll serve --host 0.0.0.0"\n'}}}

Save yaml

saveYaml[source]

saveYaml(item:dict, path:str)

path = '../testData/testSaveYaml.yaml'
saveYaml({'test':'test'}, path)
loadYaml(path)
{'test': 'test'}