Python Module/Package Recommendations

Introduction to a Handy Python Package - structlog

When starting with Python’s logging module, many of us have encountered confusion, as with the following code example:

import logging

log = logging.getLogger(__name__)
log.info('Hello')

We might expect this code to print the string Hello, but it doesn’t.

This is because the default log level for Python’s logging module is WARNING, so only messages at WARNING, ERROR, or CRITICAL levels are displayed.

To properly use the logging module, setting it up is necessary, which often means consulting the Python documentation. This isn’t a problem with Python per se, but rather a design philosophy difference.

So, is there a package more intuitive and easier to use than the built-in logging module?

The answer is “yes,” and that is the structlog package, which this article introduces.

Posted on  Aug 30, 2023  in  Python Module/Package Recommendations , Python Programming - Beginner Level  by  Amo Chen  ‐ 4 min read

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

Python Module - jsonschema Part 3

This post is part of a series on the Python module - jsonschema:

In Part 2 of the Python Module - jsonschema, we covered the complex usage of types like number, string, array, and object. However, most examples focused on validating individual data types, while in practice, JSON data can often involve a mixture of multiple data types. For example, an array might contain object elements, and an object might include nested objects. Consider the following JSON data:

[
    {
        "user_id": 1,
        "preference": {
            "cooking": True,
            "fishing": False,
        }
    },
    {
        "user_id": 1,
        "preference": {
            "cooking": True,
            "fishing": False,
        }
    },
]

This section will introduce how to write JSON Schemas that are more practical for real-world use and easier to maintain.

Posted on  Mar 28, 2018  in  Python Module/Package Recommendations  by  Amo Chen  ‐ 4 min read

Python Module - jsonschema Part 2

This article is a part of a series on the Python module - jsonschema:

In the previous article, Python Module - jsonschema Part 1, we introduced six data types defined by JSON Schema and covered some basic validation techniques.

In this post, we will dive deeper into more complex usages of several types, namely number, string, array, and object.

Posted on  Mar 23, 2018  in  Python Module/Package Recommendations  by  Amo Chen  ‐ 6 min read

Python Module - jsonschema Part 1

This article is part of a tutorial series about the Python module - jsonschema:

JSON is currently one of the mainstream data interchange formats. However, if you want to validate the format of JSON data in your program, you’ll need to spend some effort writing validation code. Fortunately, JSON Schema simplifies the process of validating JSON formats. If you’re using JSON as the data exchange format for an API, you might consider using JSON Schema for validation.

JSON Schema is a vocabulary that allows you to annotate and validate JSON documents.

Posted on  Mar 20, 2018  in  Python Module/Package Recommendations  by  Amo Chen  ‐ 5 min read

Recording Test Duration with Python pytest

Recently, I read an article titled Timing Tests in Python for Fun and Profit, which is well worth a read. The article discusses how to find test cases that need speed improvement by recording their execution time (and in the process, you might also discover code with poor performance).

However, I often use pytest, so I spent some extra time finding out how to achieve the same in pytest.

Posted on  Nov 20, 2016  in  Python Module/Package Recommendations  by  Amo Chen  ‐ 2 min read