Skip to main content

154 posts tagged with "python"

python tag description

View All Tags

How to enforce type hinting in Python: Static vs Runtime Strategies

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

Python is famous for being a "consenting adults" language. By default, type hints (like name: str) are just polite suggestions. If you pass an integer into a function expecting a string, Python will happily execute it-and probably crash three lines later.

In 2026, relying on "polite suggestions" isn't enough for production-grade code. To actually enforce type hinting, you have to move beyond the built-in typing module and use external guardians.

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

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

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.

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

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

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
software engineer, creator, artist, programmer, projects founder

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
software engineer, creator, artist, programmer, projects founder

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.

Detect Google AdSense on "Tough" Sites with Playwright

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

When standard requests scripts fail with a 403 Forbidden or a Cloudflare "Verify you are human" challenge, it's usually because the website is looking for real browser behavior (like rendering JavaScript or moving a mouse).

Playwright is a modern browser automation library that acts like a real human using Chrome, Firefox, or Safari. It can bypass simple bot detection and see exactly what a user sees, making it the ultimate tool for AdSense detection on "tough" sites.

How to Detect Google AdSense on a Website with Python

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

Detecting whether a website is running Google AdSense is a common task for digital marketers, SEO researchers, and competitive analysts. From a technical perspective, AdSense works by injecting a specific JavaScript library into the page, usually accompanied by a unique "Publisher ID" (formatted as pub-xxxxxxxxxxxxxxxx).

In Python, we can identify these markers by "scraping" the HTML and searching for the signature AdSense scripts.

How to Download YouTube Thumbnails in Python (Without Pytube)

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

Downloading a YouTube thumbnail is a classic Python task that involves two main steps: extracting the unique Video ID from a URL and then fetching the image from Google's thumbnail servers.

Because YouTube uses a predictable URL structure for its images, you don't actually need the heavy pytube library just to get the thumbnail-standard requests will do the trick!

Pydantic for JSON Validation in Python

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

In our last article(python simpleeval examples), we built a dynamic rules engine using simpleeval. But there is a golden rule in software engineering: Garbage In, Garbage Out.

If your rules engine expects a checkout cart to have a cart_total (a number) and a user_role (a string), but the frontend accidentally sends {"cart_total": "free", "role": null}, your engine will crash. Before untrusted JSON data ever reaches your core logic, it needs to pass through a strict gatekeeper. In modern Python, that gatekeeper is Pydantic.

Analyzing YouTube Comment Sentiment with Python

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

Analyzing the "vibe" of a YouTube comment section is a fantastic way to use Python for data science. Since yt-dlp doesn't always handle large-scale comment scraping easily, we'll use the YouTube Data API v3 (the official way) and the TextBlob library to perform the sentiment analysis.

This script will tell you if the first 100 commenters are mostly happy, angry, or neutral.