# Python Libraries for DevOps

**#Day 15 of 90daysofdevops**

Hi Friends,

Let's discuss libraries in Python. As a DevOps engineer, we should know how to parse the file. the file could be JSON or yaml or txt etc.,

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

**<mark>What is JSON?</mark>**

JSON(JavaScript Object Notation) is a popular data format used for representing structured data. We can transmit our data over the network using either XML or JSON. For simpler data, we use JSON for the complexity we can use XML.

*<mark>How to read JSON files?</mark>*

1. Import Json module
    
2. Provide the file path which you want to read.(e.g. my\_file="c:/ptyhon/myfile.json")
    
3. Open the file to read the content of a file e.g.open(my\_file, "r").
    
4. Use json.load() function will convert JSON data into Python understandable format.
    

## Tasks:

1. Create a Dictionary in Python and write it to a JSON File.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684770577064/fa3d080f-82a8-4293-9b78-c9182e0f3b47.jpeg align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684770599128/94604d89-2a38-4201-901d-928ad96eb6e6.jpeg align="center")
    
2. Read a JSON file `services.json` kept in this folder and print the service names of every cloud service provider.
    
    ```plaintext
    output
    
    aws : ec2
    azure : VM
    gcp : compute engine
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684780148094/3c2bec1f-143e-4def-a5bb-b80ef032b29d.jpeg align="center")
    
3. Read YAML file using Python, file `services.yaml` and read the contents to convert YAML to JSON
    

Here we have to read YAML file using Python. So we must have YAML module otherwise we can't read YAML file.

So before writing import yaml. Download YAML module otherwise your yaml code would not run.Here i have solved this isse.Just type below command:

```bash
pip install pyyaml
```

Here i am sharing screenshot for your reference.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684781804073/d7fda4a5-1af6-4831-913d-6607b19c9fee.png align="center")

Here we have finished our first task reading YAML file using python.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684782050451/d6beb5ee-6262-415a-bfd4-bee85abd4a11.jpeg align="center")

Now our next task is to convert YAML to JSON.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684782299506/b0689b3e-3166-49d2-aed7-6d5dc2914a67.jpeg align="center")

Thank you for reading this blog.Happy Learning!!!!!

You can follow me on LinkedIn for my daily updates:- [**linkedin.com/in/parimal-pradhan-b62021168**](http://linkedin.com/in/parimal-pradhan-b62021168)

Great initiative by the #trainwithshubham community. Thank you @[Shubham Londhe](@TrainWithShubham)
