Skip to main content

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.

FastAPI Dependency Injection (DI) VS. Depends

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

That's an excellent question that gets right to the core of FastAPI's design.

Yes, FastAPI Dependency Injection (DI) and FastAPI Depends are two different but closely related concepts. You can think of them as the system and the tool used to activate that system.

Here's a breakdown of the difference:

Testing FastAPI Dependency Injection: Where to Start

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

For beginners, testing FastAPI dependencies should start with one fundamental goal: isolation. You must ensure your route logic is tested without making real network calls, hitting a live database, or relying on complex configuration settings.

The key to achieving this is using FastAPI's built-in app.dependency_overrides dictionary. This allows you to replace any real dependency function with a simple, predictable mock function for the duration of a test.

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.

Testing FastAPI Dependency Injection: A Comprehensive Guide

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

Testing code that uses Dependency Injection (DI) is crucial because it allows you to isolate the logic of your route handlers from the complexity of external services (like databases, security checks, or configuration). FastAPI makes this straightforward using the app.dependency_overrides dictionary.

By implementing overrides, you replace the original, complex dependency function with a simple mock function that returns predictable test data, ensuring your tests run fast and consistently.

Advanced FastAPI Dependency Injection for Experts

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

For expert programmers, FastAPI Dependency Injection (DI) is not just about injecting configuration; it's a foundational tool for managing application state, enforcing transaction integrity, and implementing complex authorization logic cleanly and reliably. These advanced patterns leverage yield and nested dependencies to ensure stability and separation of concerns.

Looking for more content?
Hrekov Blog contains 240 articles. Browse the blog archive or Explore the full timeline.