Day 15 : Python Libraries for DevOps

What are python libraries?

Python libraries are collections of pre-written code that provide functions, methods, and classes to perform specific tasks, eliminating the need to write code from scratch. Libraries extend Python's capabilities by offering solutions for various domains such as data analysis, web development, machine learning, DevOps automation, and more

Types of Python Libraries

  1. Standard Libraries
    These come pre-installed with Python and cover a wide range of functionalities like file handling, OS interaction, mathematics, and more.
    Examples:

    • os: OS-level interactions

    • sys: System-specific parameters and functions

    • math: Mathematical operations

    • datetime: Date and time manipulation

    • json: Handling JSON data

  2. Third-Party Libraries
    These are external libraries created by the community or organizations, installed via tools like pip.
    Examples:

    • requests: HTTP requests

    • numpy: Numerical computations

    • pandas: Data manipulation and analysis

    • boto3: AWS service automation

    • Flask: Web application development

  3. Domain-Specific Libraries
    Libraries tailored for specific fields or tasks.
    Examples:

    • Data Science: matplotlib, seaborn, scikit-learn

    • DevOps: boto3, paramiko, docker

    • Web Development: Django, Flask

    • Machine Learning: TensorFlow, PyTorch

    • Database Interaction: sqlalchemy, psycopg2

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.

    { "services": { "debug": "on", "aws": { "name": "EC2", "type": "pay per hour", "instances": 500, "count": 500 }, "azure": { "name": "VM", "type": "pay per hour", "instances": 500, "count": 500 }, "gcp": { "name": "Compute Engine", "type": "pay per hour", "instances": 500, "count": 500 } } }

    output

    aws : ec2

    azure : VM

    gcp : compute engine

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


    services: debug: 'on' aws: name: EC2 type: pay per hour instances: 500 count: 500 azure: name: VM type: pay per hour instances: 500 count: 500 gcp: name: Compute Engine type: pay per hour instances: 500 count: 500