Skip to main content

FastAPI Dependency Injection: Best Use Cases for Beginners

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

FastAPI's Dependency Injection (DI) system, powered by the Depends function, is a powerful concept built on simple Python functions. For beginners, the best use cases are those that demonstrate code reuse, logic separation, and early request validation without requiring complex external libraries.

By focusing on these three patterns, you learn to keep your route functions clean and focus only on the core business logic.

Singleton Pattern in FastAPI Dependency Injection

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

The Singleton pattern ensures that a class has only one instance and provides a global point of access to it. In web development, this is essential for managing resources like database pools, configuration objects, logging handlers, or complex machine learning models that are costly to initialize.

In FastAPI, while dependencies are generally executed once per request and the result is cached, this does not guarantee that the underlying class is instantiated only once across the entire application's lifecycle. To enforce a true global Singleton, we must use Python's built-in methods, typically overriding __new__.

FastAPI Dependency Injection: A Complete Guide to `Depends` and `yield`

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

Dependency Injection (DI) is a core principle in FastAPI, allowing you to seamlessly integrate reusable logic, external resources (like database connections), configuration settings, and security checks into your API routes. FastAPI's DI system is built on standard Python features: type hinting and function calls, using the special Depends callable.

Fixing PIL/Pillow IOError: decoder zip not available

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

The error IOError: decoder zip not available (or zip decoder not available) is a common hurdle when working with image processing in Python, particularly when handling PNG or TIFF files using the Pillow library.

This error indicates that the underlying C library responsible for image compression (Zlib) was missing or not detected when Pillow was compiled on your system.

GCP IAM vs. AWS IAM: A Deep Dive into Architectural Differences

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

While both Google Cloud Platform (GCP) and Amazon Web Services (AWS) Identity and Access Management (IAM) systems share the same goal—controlling who can do what on which resources—they are built on fundamentally different architectural philosophies.

Understanding these differences is crucial for multi-cloud engineers, as applying AWS logic to GCP (or vice versa) often leads to security gaps or unmanageable complexity.

Enable "Last Updated" Docusaurus Dates on Vercel

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

Docusaurus provides a powerful feature that displays the last updated time and last updated author for every blog post and documentation page.
However, when deploying a Docusaurus website on Vercel, many developers encounter the same confusing issue:

Every page shows the exact same “last updated” date — or no date at all.

This guide explains precisely why this happens and the exact configuration you must enable on Vercel to make Docusaurus timestamps work correctly.

Why and when to use the Pendulum module in Python

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

Pendulum is a Python library designed to simplify working with dates and times, often serving as a more developer-friendly and robust replacement for Python's built-in datetime module. You should use Pendulum whenever your application involves timezone handling, complex arithmetic, or serialization/parsing of date strings, as it provides clear, unambiguous, and efficient methods for these tasks.

Python Pip most useful commands and use cases

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

Pip is the standard package installer for Python. It allows you to manage the libraries and dependencies needed for your projects. Mastering a few core commands can significantly streamline your Python development workflow.

Switching Python Versions: Comprehensive Guide

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

Managing the active Python version is critical for development, especially when working on projects with different dependencies or legacy requirements. The methods vary significantly depending on whether you are using a dedicated version manager, a package manager, or system-level tools.

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