Skip to main content

90 posts tagged with "python"

python tag description

View All Tags

FastAPI Dependency Injection: The Complete Guide from Basics to Advanced Patterns

· 9 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Dependency Injection (DI) is one of the core architectural design choices that makes FastAPI so powerful. It handles cross-cutting concerns-such as database connections, security, authentication, and request parsing-with minimal boilerplate.

Whether you are a beginner looking to understand the Depends syntax or an expert building complex authorization layers and mockable tests, this guide covers everything you need to master FastAPI's dependency injection system.

Python Enums: Complete Developer Guide from Basics to Metaprogramming

· 8 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

In Python, the enum.Enum class is far more than a simple container for constants. It provides a robust, type-safe framework for data validation, serialization, metaprogramming, and static type checking.

Using Enums eliminates fragility across your codebase by replacing raw magic numbers and string literals with structured, immutable objects. By utilizing custom properties and dunder methods (__init__, __new__, _missing_, __str__, __format__), you can embed rich domain logic directly into your constant definitions.

This guide provides a comprehensive manual on Python Enums, covering core foundations, automatic values (auto()), uniqueness validation (@unique), primitive conversions, iteration, type hinting, JSON serialization, and advanced metaprogramming.

Fixing PIL/Pillow IOError: decoder zip not available

· 4 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

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.

Pendulum vs. Python Built-In datetime: Performance, Timezones, and Best Practices

· 7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Working with dates, times, and timezones in Python often involves choosing between the standard library's built-in datetime module and third-party libraries like Pendulum.

While Python's native datetime provides maximum raw execution speed due to its low-level C implementation, Pendulum provides default timezone awareness, Daylight Saving Time (DST) safety, and an intuitive fluent API for arithmetic and parsing.

This guide provides a comprehensive comparison covering execution benchmarks, architectural differences, timezone safety, and code examples for choosing the right tool.

Python Pip most useful commands and use cases

· 5 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

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.

All Possible Ways to Remove Timezone Information from a Python `datetime` Object

· 7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

A Python datetime object is considered timezone-aware if its tzinfo attribute is set, and timezone-naive if tzinfo is None. Removing timezone information, or "making it naive," is the process of setting this attribute to None.

The key consideration when stripping the timezone is which time value you want to keep: the time as it was originally represented, or the time converted to a standard reference (like UTC or local time) before stripping the timezone.

Poetry Fails to Install Multidict: Pyenv, Compilers, and Wheels

· 6 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

If your poetry install command is failing specifically when trying to install multidict (or packages that depend on it, like aiohttp or discord.py), the root cause is almost always a failure to compile the optional C extensions for the package.

Since multidict offers pre-compiled binaries (wheels) for standard Python versions on common operating systems, a compilation error indicates one of two things: the wheel is unavailable for your specific setup, or the local build tools are missing. Your use of pyenv often exacerbates the issue by complicating the environment setup.

Authorization in the App Layer: Using Casbin Flask Middleware

· 5 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

If your deployment environment doesn't support a service mesh like Envoy or an external authorization server (common in simpler, monolithic, or traditional hosting setups), you can certainly move the Casbin authorization check into your Flask application using middleware or decorators.

This approach centralizes authorization logic within the Python code, relying on dedicated extensions like flask-authz or Flask-Casbin.

Casbin Policy Storage in Python: SQLite, Firestore, and SQLAlchemy Adapter Guide

· 7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Using SQLite as the database adapter for Casbin policy storage is the ideal solution for local development, unit testing, and small-scale applications due to its lightweight, file-based nature.

In the Python Casbin ecosystem, this is achieved using the casbin-sqlalchemy-adapter, as SQLAlchemy natively supports SQLite without needing separate driver installations [2].

Implement Casbin sidecar pattern

· 5 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

1. The Casbin Sidecar Pattern

A sidecar is a helper container that runs alongside your main application container (the Flask app) inside the same Kubernetes Pod [4]. The sidecar, in this case, is the Envoy Proxy, which intercepts all incoming and outgoing traffic for your Flask application.