Skip to main content

90 posts tagged with "python"

python tag description

View All Tags

Casbin RBAC Guide: Standard vs. Hierarchical Roles, Maintenance, and Configuration

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

A common misconception about using Casbin Hierarchical RBAC is that the entire policy storage must be updated every time a user performs an action or changes state. This is incorrect. The system is designed to separate the static, structural hierarchy (which rarely changes) from the dynamic user assignments (which change frequently).

The efficiency of Hierarchical RBAC lies in this separation, minimizing the required policy updates and reducing redundancy.

QR Codes in Python: The Complete Developer Guide to Generation and Decoding

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

Quick Response (QR) codes are two-dimensional matrix barcodes widely used for encoding URLs, text, contact information, and authentication tokens. Integrating QR code generation and decoding into Python applications is straightforward using robust libraries like qrcode, pyzbar, and Pillow.

This guide details how to generate basic QR codes, apply custom styles and colors, embed brand logos safely, output print-ready vector formats (SVG), host large files like PDFs via encoded links, and decode QR code images (including NumPy video streams).

Create and use a private python library on github in your projects

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

Creating a private Python library on GitHub and using it in your projects is a great way to manage internal code, share reusable components across teams, and protect proprietary intellectual property. This process involves setting up a private repository, configuring your local environment for authentication, and then installing the library using a dependency manager like pip or poetry [1].

Python Mocking: The Ultimate Guide from Basics to Advanced Test Double Patterns

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

Unit tests must execute in complete isolation from external resources like databases, networks, and file systems. Python's built-in unittest.mock library and the pytest-mock plugin are the standard tools for creating test doubles, enabling you to inspect invocations, mock complex class initializers, verify function signatures, and control time.

This guide provides a comprehensive manual on Python mocking: foundational concepts, interface enforcement via spec/autospec, stateful simulations with side_effect, class constructor and instance method patching, Pytest mocker fixture workflows, asynchronous coroutines, and time freezing.

Python Mocking Guide: External Dependencies, Test Doubles, and Pytest Best Practices

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

External dependencies are a major source of pain in unit testing. Network calls, persistent databases, and file systems are inherently slow, non-deterministic, and prone to environmental failures. Mocking these boundaries isolates your unit tests and delivers sub-second test execution suites.

However, over-mocking leads to brittle tests that pass while production code breaks. This guide provides a complete manual on Python test doubles: the architectural framework of when to mock, test double taxonomy (stubs, fakes, spies, mocks), hands-on unittest.mock examples for HTTP APIs, databases, and file systems, plus Pytest mocking pitfalls to avoid.

Given-When-Then vs. Alternative Python Test Structuring Patterns

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

For docstrings in Python tests, there isn't a single technique that's universally "better" than Given-When-Then. The best technique depends on your project's needs, your team's familiarity with different styles, and the specific type of testing you're doing.

Benchmark & Architecture Guide: msgspec vs. Pydantic v2

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

High-throughput Python microservices, data ingestion pipelines, and web APIs frequently bottleneck on serialization and data validation. While Pydantic v2 (re-written with a Rust core) revolutionized Python data validation, msgspec offers extreme performance advantages for specialized data workloads.

This guide provides a comprehensive benchmark analysis and architectural breakdown comparing msgspec and Pydantic v2, detailing throughput metrics, validation mechanics, ecosystem trade-offs, and selection criteria.

Msgspec FastAPI Integration: High Performance, Validation, and OpenAPI Docs

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

msgspec is a Python library designed for high-performance serialization and validation, which makes it a powerful partner for FastAPI. It can be used as a drop-in replacement for FastAPI's default Pydantic models to handle data validation and schema generation, often leading to a significant speedup in API performance.

Msgspec Struct: High-Performance Data Classes and Why Choose Msgspec Over Pydantic

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

msgspec.Struct is a powerful data class in the msgspec library that's used to define the schema of your data. It's similar to Python's built-in dataclasses or typing.NamedTuple, but it's specifically optimized for high-performance serialization and validation. When you use a Struct, msgspec can perform operations like JSON encoding and decoding significantly faster than standard Python methods because it has a predefined, static understanding of your data's layout.

Ultimate pre-commit Configuration for Python: Complete setup & Advanced practices

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

Maintaining code consistency and preventing quality regressions across a development team can be challenging. Manually checking styles or reminding teammates about formatting imports leads to cognitive overhead and code reviews cluttered with style arguments.

By implementing pre-commit, you can automate code formatting, import sorting, stylistic linting, and static type checking directly into your Git commit lifecycle. This guide outlines the ultimate pre-commit configuration for Python, demonstrates how to centralize settings, and provides advanced optimization tips.