Skip to main content

141 posts tagged with "python"

python tag description

View All Tags

gRPC in Python Example

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

gRPC in Python: A Practical Example and When to Choose It​

gRPC (gRPC Remote Procedure Calls) is a modern, high-performance, open-source framework developed by Google that enables communication between services. It relies on Protocol Buffers (protobuf) for its Interface Definition Language (IDL) and uses HTTP/2 for transport.

It has become the standard choice for communication in microservices and polyglot (multi-language) environments where performance, efficiency, and strong typing are critical.

When to Use Multiple try-except Blocks in Python

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

🚧 When to Use Multiple try...except Blocks in Python​

While it is possible to wrap an entire function in a single try...except block, experienced Python developers know that strategically using multiple, smaller try...except blocks is often superior. This approach enhances clarity, improves error granularity, and aids recovery.

This article details the specific scenarios where breaking down your code into multiple guarded sections is the recommended best practice.

Catching Multiple Exception Types in Python

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

🎣 Catching Multiple Exception Types in Python​

In robust Python development, it is often necessary to catch and handle several different types of exceptions that might arise from a single block of code. Python provides flexible and concise syntax to manage multiple exceptions in a single try...except structure.

This article details the three primary methods for catching multiple exceptions, focusing on efficiency and best practice.

The Right Way to Print Stack Traces in Python

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

πŸ–¨οΈ The Right Way to Print Stack Traces in Python​

In Python, displaying the stack trace (or traceback) is essential for debugging. It provides a historical record of all function calls leading up to the point where an exception occurred. However, simply using print() within an except block is insufficient and incorrect.

This article details the correct methods for capturing, formatting, and logging the stack trace, emphasizing the difference between developer debugging and production logging.

Custom Classes for Python Exceptions: Extending the Error Toolkit

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

✨ Custom Classes for Python Exceptions: Extending the Error Toolkit​

Defining custom exception classes is a hallmark of professional-grade Python code. Instead of relying on generic built-in exceptions (like ValueError or TypeError) for every application-specific failure, custom exceptions provide clear, unambiguous signals about why an operation failed.

This article details the necessity, structure, and best practices for creating and utilizing your own exception hierarchy.

Understanding the Python Exception Hierarchy

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

🌳 Understanding the Python Exception Hierarchy​

In Python, all exceptions are organized into a strict, single-rooted hierarchy of classes. Understanding this hierarchy is not just academic; it is fundamental to writing reliable exception handlers. When you catch an exception, you are actually catching that specific class and all classes that inherit from it.

This article breaks down the core structure of the Python exception hierarchy and demonstrates how inheritance dictates the behavior of your except blocks.

Everything You Want to Know About Python Error Handling

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

🚨 Everything You Want to Know About Python Error Handling​

Effective error handling is the foundation of writing robust, maintainable, and reliable Python code. It ensures that your application can gracefully manage unexpected conditions without crashing, providing clean feedback to the user or logging useful data for debugging.

This article details the comprehensive toolkit Python provides for managing errors, covering structure, best practices, and advanced techniques.

Python Exception Propagation: How Errors Travel Up the Python Call Stack

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

πŸ”₯ Exception Propagation: How Errors Travel Up the Python Call Stack​

When an exception occurs deep inside a function call, the Python interpreter stops the normal flow of execution and immediately begins searching for a way to handle that exception. This search process, where the exception moves outward from the point of failure, is known as propagation.

Linking Logs Across Python Microservices(Distributed Tracing)

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

πŸ”— Distributed Tracing: Linking Logs Across Python Microservices​

In modern microservices architectures, a single user request might flow through an API Gateway, an authentication service, a business logic service, and several data services. While structured logging makes each service's log output clean, it doesn't automatically connect the dots.

Distributed Tracing is the operational practice of adding unique identifiers to every log and header related to a single request, allowing you to reconstruct the entire request path across all services.

Python Logging Best Practices: The Expert's Handbook

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

⭐ The Expert's Handbook: Python Logging Best Practices​

Logging is not just about tracing execution; it's about creating an intelligent, observable, and auditable application. A truly experienced software engineer approaches Python logging with a strategic mindset, treating log data as a primary source of truth for operations and debugging.

This guide outlines the critical best practices, complete with detailed code examples, to elevate your Python logging from simple print statements to a powerful operational asset.