Python Libraries for DevOps

Unnati GuptaUnnati Gupta
2 min read

#day15

#90daysdevopschallenge

What is JSON?

JSON stands for "JavaScript Object Notation". It is a widely used data interchange format that is language-agnostic, meaning it can be used in various programming languages including Python and JAVA.

JSON in Python:

Python has a built-in module called JSON. It provides a function for working with JSON data.

Serialization (Python to JSON):

To convert a Python data structure such as a list & dictionary into a JSON string, use json.dumps() function.

import json as js

data = {"name" : "Tom","age": 20}

json_str= js.dumps(data) print(json_str)

Deserialization (JSON to Python):

To convert JSON string to Python data structure, use json.load() function.

import json as js

json_str = '{"name":"Tom","age":20}'

data=js.loads(json_str) print(data["name"])

What is YAML?

YAML stands for "Yet Another Markup Language". It is human human-readable data serialization language. It is often used for configuration but also used for data exchange.

YAML in Python:

The most commonly used Python YAML Parser is PyYAML. It is a library that allows you to load, parse, and write YAML.

Python converts into YAML:

import yaml

data = {"name":"Tom","age":20,"city":"NewYork"}

yaml_data = yaml.dump(data,default_flow_style = False)

YAML convert into Python:

python_data = yaml.safe.load(yaml_data)

print(f"name: {python_data["name"]}")

โ„Tasks:

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

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

    service.json:

    { "aws": { "name": "ec2" }, "azure": { "name": "VM" }, "gcp": { "name": "compute engine" } }

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

    In next article, will start our Docker journey....

    Thank you for giving your precious time to read this blog/article and if any suggestions or improvements are required on my blogs feel free to connect on Linkedin Unnati Gupta. Happy Learning !!!

0
Subscribe to my newsletter

Read articles from Unnati Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Unnati Gupta
Unnati Gupta

๐Ÿ‘จโ€๐Ÿ’ป DevOps Engineer at 6D Technology Passionate about bridging the gap between development and operations, I'm a dedicated DevOps Engineer at 6D Technology. With a strong belief in the power of automation, continuous integration, and continuous delivery, I thrive in optimizing software development pipelines for efficiency and reliability. ๐Ÿš€ Exploring the DevOps Universe In my articles, I delve into the fascinating world of DevOps, where I share insights, best practices, and real-world experiences. From containerization and orchestration to CI/CD pipelines and infrastructure as code, I'm here to demystify the complex and empower fellow developers and ops enthusiasts. ๐Ÿ“ Blogging for Knowledge Sharing As a tech enthusiast and a lifelong learner, I'm committed to sharing knowledge. My articles aim to simplify complex concepts and provide practical tips that help teams and individuals streamline their software delivery processes. ๐ŸŒ Connect with Me Let's connect and explore the ever-evolving landscape of DevOps together. Feel free to reach out, comment, or share your thoughts on my articles. Together, we can foster a culture of collaboration and innovation in the DevOps community. ๐Ÿ”— Social Links LinkedIn: https://www.linkedin.com/in/unnati-gupta-%F0%9F%87%AE%F0%9F%87%B3-a62563183/ GitHub: https://github.com/DevUnnati ๐Ÿ“ฉ Contact Have questions or looking to collaborate? You can reach me at unnatigupta527@gmail.com Happy Learning!!