python

Introduction to the Python Package - JMESPath (A JSON Query Language Similar to jq)

JMESPath is a Python package with functions similar to jq, enabling Python developers to query and restructure JSON data with a syntax akin to jq. This is done by converting JSON into Python’s native data types using the json module. Proper use of JMESPath can simplify code and enhance readability.

This article will introduce the methods for using JMESPath.

Posted on  Jul 12, 2023  in  Python Module/Package Recommendations  by  Amo Chen  ‐ 5 min read

Great Article Share - Automating Kubernetes Deployments using Python

The article, “Automating Kubernetes Deployments using Python,” introduces how to automate the control of K8s-related resources using the Python Kubernetes package. It covers five major resources: Deployment, Service, ConfigMap, Secret, and Ingress. These are typically encountered when deploying applications to K8s. If you’re looking to automate the process of deploying applications to K8s with Python, this article is a great starting point and very valuable as a reference. Automating Deployment of Applications using Kubernetes Python SDK

Posted on  Jul 8, 2023  by  Amo Chen  ‐ 1 min read

What? You Haven't Used K8s Yet?

With the rise of containerization, more and more companies are adopting Kubernetes (or K8s) to run various containerized services within K8s clusters. Not only does this provide a standard approach for deployments (since everyone writes YAML configuration files to describe how services are deployed), it also offers more flexibility in system resource scheduling and scaling (using K8s commands makes it easy to adjust the number or resources of service containers). So usually, after learning Docker and docker-compose, the next step is to learn how to use K8s.

Posted on  Mar 30, 2023  by  Amo Chen  ‐ 1 min read

Python Module Tutorial - dataclasses

Python’s dataclasses is a new module added in Python 3.7, mainly used to define structured data in the form of classes.

The dataclasses module provides some convenient features to help automatically generate commonly used class methods such as __init__, __repr__, __eq__, etc., saving developers time in writing repetitive code.

Using dataclasses can make Python programs more concise and improve code readability.

Are you ready to show off your skills using dataclasses in your Python code?

Posted on  Feb 1, 2023  in  Python Programming - Intermediate Level  by  Amo Chen  ‐ 8 min read

Designed for Counting - Python Counter Class

The Python collections module provides several convenient classes for developers to use, among which the Counter class (a subclass of dict) can be applied in counting-related scenarios:

A Counter is a dict subclass for counting hashable objects.

This article will introduce the usage of the Counter class and compare its performance with dict and defaultdict.

Posted on  Apr 19, 2022  in  Python Programming - Beginner Level  by  Amo Chen  ‐ 5 min read

Python Module Tutorial - pathlib

Python’s os module provides many convenient functions for us to manipulate file/folder paths. After Python 3.4, a new module called pathlib was introduced, which encapsulates various file/folder related operations in classes such as Path, making file/folder operations more object-oriented.

This article will explain and demonstrate the pathlib module.

Posted on  Oct 19, 2020  in  Python Programming - Beginner Level  by  Amo Chen  ‐ 5 min read

Learn Python Multiprocessing Module Easily with Examples

Python’s built-in multiprocessing module is quite important if there are requirements for parallelism processing, in addition to the built-in threading module, another one is multiprocessing.

The advantage of using multiprocessing is that it can greatly avoid the impact of Python GIL on program performance, but the bad thing is that it consumes more memory. Even so, it is still a module that must be understood.

This article will learn how to use the multiprocessing module through several examples.

Last updated on  Feb 8, 2023  in  Python Programming - Beginner Level  by  Amo Chen  ‐ 8 min read

Easily manage settings with Pydantic

During development, configuration files are often needed to easily change the behavior of the system. For example, the switch of Debug mode, database related settings, etc. are usually placed in configuration files.

In addition to the built-in module configparser provided by Python to easily implement configuration files, it can also easily implement configuration files using classes, such as the following two files are examples of configuration

# settings.py
class Settings(object):
    DB_HOST = 'localhost'
    DB_PORT = 8888


settings = Settings()
# test.py
from settings import settings


print(settings.DB_HOST, settings.DB_PORT)

However, nowadays development projects also often use dotenv (e.g. python-dotenv) to make configuration easier.

In addition to developing the functionality of dotenv by yourself, you can actually choose to integrate class-style configuration files and dotenv easily with pydantic.

Posted on  Jul 1, 2020  in  Useful Python Modules , Python Programming - Advanced Level  by  Amo Chen  ‐ 5 min read