Skip to main content

8 posts tagged with "enum"

enum tag description

View All Tags

Python Logging Levels Enum Usage

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

While Python's built-in logging module uses integer constants (logging.DEBUG, logging.INFO, etc.) for log levels, modern Python practice encourages using the enum.Enum class for defining symbolic names, especially for configurations and custom values.

Using an Enum to wrap or reference standard logging levels significantly enhances code readability, prevents hard-to-debug typos, and aids type checking when passing levels as function arguments.

Python Enum conversion to Collections and Serialization

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

This article focuses on the practical necessity of converting an entire enum.Enum class into standard Python collections (list, dict) and preparing them for data interchange formats like JSON. This is essential when presenting options in an API response, generating documentation, or storing structured data.

Python Enum Foundation, Basic and Naming

· 5 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

🐍 Python Enum: Foundation, Naming, and Primitive Conversion

This article focuses on the necessity of the enum.Enum class, proper definition, standard naming conventions, and the fundamental process of converting Enum members to and from primitive types like integers and strings.

Python Enum Number reverse lookup

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Reverse lookup is the process of retrieving the symbolic member name (e.g., NOT_FOUND) or the member object itself from its associated raw value (e.g., 404). This is an essential technique when dealing with external inputs like HTTP status codes, database keys, or configuration settings.

This article details the most efficient and robust methods for performing reverse lookup using the standard Python enum.Enum library.

Python Enum to String without Class Name

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

When using Python Enums, the default string output includes the class name (e.g., <MyEnum.MEMBER: 'value'>), which is often unsuitable for clean logging, API responses, or direct printing. This article demonstrates how to leverage Python's dunder methods (__str__, __repr__, __format__) to gain complete control over the string representation of your Enum members.

Python enum framework

· 8 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Python enum.Enum Advanced Practices for Expert Programmers

For veteran Python engineers, the enum.Enum class is more than just a container for constants; it is a powerful framework for metaprogramming, runtime validation, and object identity. These advanced techniques leverage Python's dunder methods (__new__, _missing_, __format__) and the underlying metaclass to inject behavior and data in highly customized ways, solving obscure but critical architectural problems.

Python Enum Integration with Typing

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

The combination of the standard enum.Enum class and the typing module is a powerful best practice in modern Python. By using an Enum class as a type hint, you signal to static type checkers (like MyPy, Pyright) and fellow developers that only specific, named constants are valid inputs or outputs, enforcing both type safety and value safety.