Skip to main content

66 posts tagged with "python"

python tag description

View All Tags

Generate QR code using a URL link

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

Generating a QR code for a PDF file is not a matter of embedding the entire file's data into the QR code. QR codes have a strict data limit (typically up to about 4,000 characters), which is far too small for most PDF documents 1.

The correct, industry-standard approach is to host the PDF online and encode the resulting direct URL into the QR code. When a user scans the code, their device opens the URL, which automatically downloads or displays the PDF.

Here is the guide for generating the QR code using a URL link.

QR code reader in Python

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

Python QR code reader from image or How to decode a QR-code image in python?

Decoding a QR code from an image in Python is primarily achieved using the pyzbar library, which reads various bar codes and QR codes 1, 2.

Create QR code generator with logo

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

How to create QR code generator with logo with Python

Creating a QR code generator with logo in Python is best done using the qrcode library, specifically its advanced image capabilities, combined with Pillow (PIL) for image handling. This guide provides two methods: a simple, modern approach and a manual, detailed approach.

QR code generator in Python

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

Creating a QR code generator in Python is remarkably straightforward, thanks to robust, community-maintained libraries. The most popular and simplest choice is the qrcode library. This article will focus on using this library to generate, customize, and save QR codes with minimal code.

Since there are multiple excellent libraries available for QR code generation in Python, I propose we focus this article on the simple and popular qrcode library, and then follow up with another article on the modern, standard-compliant segno library for advanced use cases (MicroQR codes, superior vector output, etc.).

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

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

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].

When to mock

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

The final act of mastering testing isn't just knowing how to mock, but understanding when to mock. Over-mocking can lead to brittle tests that provide a false sense of security, while a lack of mocks can make your test suite slow and unreliable. This article will conclude our series by clarifying the different types of test doubles and providing a robust framework for when to use each one, including when a real dependency is the better choice.

Python mocking frameworks

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

Mocking becomes particularly valuable when testing code that interacts with complex frameworks and libraries. While the core concepts of unittest.mock remain the same, the specific objects and functions you need to patch can vary. This article will provide practical, in-depth examples of how to apply mocking to three common Python ecosystems: web frameworks (Django/Flask), asynchronous programming (asyncio), and data science (pandas).

Python mocking: advanced side_effect and spec usage

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

side_effect and spec are powerful but often underutilized features of Python's unittest.mock library. Mastering them is key to writing tests that are both robust and expressive. This article will dive deep into these advanced concepts, showing you how to simulate complex scenarios and prevent common mocking pitfalls.

Mocking __init__ methods in Python

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

Patching a class's __init__ method is a common and powerful technique for unit testing code that relies on objects whose initialization performs unwanted side effects. These side effects can include making API calls, connecting to a database, or performing other time-consuming or stateful operations [1]. By mocking __init__, you can prevent these actions and verify that the class was instantiated correctly.