Skip to main content

72 posts tagged with "python"

python tag description

View All Tags

Preserve the original literal block format

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

No, it is not possible for standard Python YAML libraries like PyYAML to preserve the original literal block format (e.g., | or >) when you load a YAML file and then dump it back. This is because the parser converts the literal block content into a standard Python string, discarding the original formatting. When you dump the string back to YAML, the dumper uses its own rules to represent the string, which typically defaults to a quoted style or a folded block style, but not necessarily the original one.

JSON Encoding and Validation in Python: Msgspec vs. Pydantic

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

To JSON-encode a Python object using msgspec, you use the msgspec.json.encode() function. This function takes a Python object and returns a bytes object containing the JSON representation. msgspec is known for its high performance and correctness in handling data serialization.

Here's a simple guide with examples.

Convert msgspec Struct to Python Dictionary

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

When building high-throughput Python backend services, I frequently rely on msgspec as a lightweight, high-performance alternative to Pydantic and standard dataclasses. While msgspec.Struct objects provide blazing-fast serialization and low memory overhead thanks to their C-extension implementation, integration with legacy libraries, database ORMs, or third-party SDKs often requires converting these structures into native Python dictionaries (dict).

In this article, I will walk through the primary techniques for converting msgspec objects to dictionaries, compare their performance characteristics, and explain when to use each method in production backend systems.

Fixing Vercel Python Import Errors: Causes, Solutions, and Helper Functions

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

The primary cause for import errors on Vercel is often a mismatch between your local development environment's flexibility and Vercel's strict, serverless build process. Beyond the crucial __init__.py file, you need to pay attention to your project's overall structure, the way you write imports, and Vercel's build configuration.

Whats the point of __init__.py on Vercel

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

The imports working perfectly fine locally, but failed after deploying on Vercel. The error I've experiencing is common when deploying Python applications with a specific file structure. My local environment likely handles imports differently than Vercel's serverless environment(because of the folder structure), which can cause import errors. The solution is to ensure that my project structure is recognized as a Python package

Switching Python Versions: Complete Developer Guide to pyenv, Poetry, CLI Cheatsheet, and Troubleshooting

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

Managing active Python interpreters is a fundamental workflow requirement, particularly when developing across multiple backend microservices with competing runtime constraints or legacy dependencies. Directly altering system Python binaries breaks core OS utilities.

Cloning a list in Python

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

Cloning a list in Python is essential to avoid unintended side effects, as simply assigning one list to another with the equals sign (=) creates a reference, not a new copy [1]. This means both variables point to the same list object in memory, and modifying one will modify the other. To properly clone a list, you need to understand the difference between a shallow copy and a deep copy.

Choosing the right Python environment and package management tool in 2025

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

Choosing the right Python environment and package management tool in 2025 depends on your project's complexity and your team's workflow. The tools available can be categorized into two main groups: those that manage Python versions (pyenv, asdf) and those that manage project dependencies (venv, virtualenv, Poetry). Combining these tools is often the most effective approach.

Install pyenv on MacOs

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

Homebrew is the recommended and easiest way to install pyenv on macOS, but you can install it without Homebrew by cloning the repository from GitHub. This method requires a few extra steps, including manually configuring your shell and installing dependencies.

Python's @property vs. @classmethod - A No-Nonsense Guide

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

When you're diving into Python's Object-Oriented Programming (OOP) features, decorators like @property and @classmethod pop up all the time. They might seem similar at first glance, but they serve fundamentally different purposes. Getting them straight is key to writing clean, Pythonic code.

Let's cut through the noise and get straight to what they do and when you should use them.