Skip to main content

158 posts tagged with "python"

python tag description

View All Tags

Consuming Path Arguments Directly in FastAPI Dependency Functions

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

The short answer is: Yes, it is fundamentally possible and encouraged to pass Path arguments directly into FastAPI dependency functions.

This feature is a core component of FastAPI's Dependency Injection (DI) system, allowing dependencies to be highly contextual. A dependency can perform validation, authentication, or data fetching based on the URL or request inputs before the route handler ever executes.

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.

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.