Skip to main content

72 posts tagged with "python"

python tag description

View All Tags

Pyproject.toml: The Definitive Guide to Modern Python Packaging

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

For years, the Python packaging world was a Wild West of setup.py, setup.cfg, and requirements.txt. It was messy, often insecure, and required executing arbitrary Python code just to install a library.

In modern Python development, pyproject.toml is the undisputed king. It is a single, human-readable configuration file that tells Python exactly how to build, install, and manage your project.

Quick Reference

pyproject.toml (PEP 517/518/621) replaces setup.py, setup.cfg, and requirements.txt with a single declarative configuration. Key sections:

  • [build-system]: Declares the packaging engine (setuptools, hatchling, flit_core, or poetry-core).
  • [project]: Standard metadata (name, version, dependencies, license).
  • [project.scripts]: CLI entry point executables.

The `__main__.py` File: The Front Door to Your Python Package

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

If __init__.py is the receptionist that organizes your package, then __main__.py is the front door. It's the specific file Python looks for when you try to execute a directory as if it were a single script.

As Python applications become more modular, __main__.py has become the standard way to provide a clean Command Line Interface (CLI) for your tools.

How to Use `__init__.py` in Python Packages: Role, Patterns, and Best Practices

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

While the existence of __init__.py makes a directory a package, how you fill that file separates a messy script from a professional library. In 2026, the goal of a well-crafted __init__.py is to provide a "Clean Facade"-hiding the messy internal plumbing of your project while offering a polished interface to the user.

Here are the industry-standard best practices for utilizing this file effectively.

How to Fix the 'ModuleNotFoundError: No module named pre_commit' Error

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

Getting the ModuleNotFoundError: No module named 'pre_commit' error is a classic "Lost in Translation" moment between your terminal and your Python environment. You know you want to commit code, and Git knows it needs to run a hook, but the Python interpreter looking for the pre_commit package is coming up empty-handed.

Here is the straightforward guide to finding that missing module and getting your hooks back on track.

Fix Firestore Error: A Document Must Have an Even Number of Path Elements

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

If you are working with Firebase and suddenly see the error fatal: A document must have an even number of path elements, don't worry-you haven't broken your database. This is Firestore's way of telling you that you've gotten lost in the "Map" of your data.

In Firestore, there is one unbreakable rule: Collections and Documents must always alternate.

How to create a 5-color palette where EVERY color is readable against EVERY other color with Python

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

Creating a color palette where every color is readable against every other color is a high-level design challenge. As the number of colors in your palette increases, the "contrast space" shrinks significantly.

In this article, we'll build a script that uses an iterative "Collision-Check" algorithm. It generates a candidate color, checks it against every color already in the palette, and only keeps it if it passes the WCAG AA threshold against all of them.

Contrast Checker: How to Calculate Color Contrast in Python

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

Designing a beautiful UI is pointless if half your users can't read it. Whether it's a person with a visual impairment or someone trying to check their phone on a sunny day, color contrast is the secret sauce of accessible design.

The WCAG (Web Content Accessibility Guidelines) provides a mathematical way to ensure text stands out against its background. Let's integrate a "Contrast Checker" into our Python toolkit.

How to convert colors in Python: A Comprehensive Guide to RGB, HSL, HWB, CMYK, and HEX

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

Converting colors in Python is a fascinating mix of dictionary lookups (for names like "tomato") and coordinate geometry. While we can use the built-in colorsys module for some parts, we'll need the webcolors library to handle CSS names and some custom math to reach the more "exotic" formats like HWB and CMYK.

SimpleEval with Examples

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

While simpleeval is great for basic calculators, its true power shines in production environments where you need to let users define their own logic-like setting up custom alerts, dynamic pricing discounts, or conditional triggers-without exposing your server to malicious code execution.

Emoji.demojize() vs. clean-text Performance Comparison

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

Performance Showdown: emoji.demojize() vs. clean-text for Emoji Handling​

When choosing a library for high-throughput text preprocessing, performance is often as important as accuracy. Both the emoji library's demojize() function and the comprehensive clean-text library can remove or replace emojis, but they serve different purposes, which impacts their speed and efficiency.

Since no direct, widely-published benchmark comparing only these two specific functions exists, this analysis focuses on their architectural differences and their respective performance profiles, based on typical NLP use cases.