Day 15 of #90DaysOfDevOps

Day 15 of #90DaysOfDevOps

Libraries

Normally, a library is a collection of books or is a room or place where many books are stored to be used later. Similarly, in the programming world, a library is a collection of precompiled codes that can be used later on in a program for some specific well-defined operations. Other than pre-compiled codes, a library may contain documentation, configuration data, message templates, classes, and values, etc.

Libraries in Python

A Python library is a collection of related modules. It contains bundles of code that can be used repeatedly in different programs. It makes Python Programming simpler and convenient for the programmer.

Python has numerous libraries like os, sys, json, yaml etc that a DevOps Engineer uses in day to day tasks.

  1. os Library

    Python has a built-in os module with methods for interacting with the operating system, like creating files and directories, management of files and directories, input, output, environment variables, process management, etc.

  2. sys Library

    The sys module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. It allows operating on the interpreter as it provides access to the variables and functions that interact strongly with the interpreter.

  3. json Library

    Python has a built-in package called json, which can be used to work with JSON(JavaScript Object Notation) data.

    Parse JSON - Convert from JSON to Python :

    If you have a JSON string, you can parse it by using the json.loads() method.

    Convert from Python to JSON :

    If you have a Python object, you can convert it into a JSON string by using the json.dumps() method.

  4. yaml Library

    YAML, a recursive acronym for “YAML Ain’t Markup Language,” is a human-readable data serialization language. It is often used for configuration files but also for data exchange. The most used python YAML parser is PyYAML, a library that allows you to load, parse, and write YAML, much like Python’s JSON library helps you to work with JSON.

Task 1: Create a Dictionary in Python and write it to a json File.

Task 2: Read a json file services.json kept in this folder and print the service names of every cloud service provider.

Task 3: Read YAML file using python, file services.yaml and read the contents to convert yaml to json