Tag: Python
-
MagicMock with Python

MagicMock is an essential Python tool for testing, allowing developers to simulate external dependencies like databases and APIs, ensuring unit tests are fast and isolated. It provides flexible mock objects, enabling control over behavior and verification of interactions. Techniques like using the @patch decorator enhance its usability in tests.
-
Publish a Python Wheel to GCP Artifact Registry with Poetry

In this article, I’m building a Python project that outputs a runnable file instead of a Docker image, as I need to directly communicate with GPU drivers. Using Poetry and GCP’s artifact registry, I must create and publish a wheel file, configuring dependencies, and deploying the project on a virtual machine, resolving issues with versioning…
-
Python Unittest Mocking Constructors

Writing effective unit tests can be challenging, especially with mocks. The post discusses issues with mocking constructors in Python’s unittest framework, suggesting that imports be structured differently to enable successful mocking. By importing the module instead of the class directly, the @patch decorator can function correctly, allowing for effective testing.
-
Architecture for my Generative AI Application

In this article, I explore using AI image generation models accessed via platforms like Hugging Face but faces challenges with high GPU costs and inefficient resource management. The solution involves a web application and a backend service that auto-scales GPU usage via asynchronous messaging, ensuring resources are only used when necessary.
-
I’ve Created a RAG in Two Days

In the AI era, web developers must integrate AI into projects to stay relevant. I’ve built a Retrieval-Augmented Generation (RAG) system in two days, combining a knowledge database with an LLM. Key components included data chunking and retrieval. The project showcased AI’s ability to provide specific responses, using creative datasets for testing.
-
SQLAlchemy and JSON values

Storing JSON in a relational database? Sounds like a contradiction, but sometimes, it’s the best solution. SQLAlchemy makes it easy to use a JSON column in Postgres—until you try to update a single value inside it. Turns out, SQLAlchemy doesn’t track those changes by default, leading to silent failures. The fix? Marking the column as…
-
Handle The Errors with Flask Correctly

Effective error management in Flask applications is crucial for security, usability, and debugging. Implement custom exceptions to centralize handling and use blueprints for clean error responses. Additionally, log useful details while avoiding exposing sensitive information. This strategy ensures a better user experience and maintains application integrity.
-
How to Handle AttributeError: ‘NoneType’ Object Has No Attribute X’ Like a Pro

The AttributeError: ‘NoneType’ object error in Python indicates an attempt to access a non-existent attribute. Instead of applying quick fixes, it’s essential to address the root cause, ensuring data integrity. Enforcing data rules prevents errors, while clear communication about optional attributes assists in handling them appropriately across the application.
-
How to Solve the CORS error with Flask

This article addresses the common CORS error faced by web developers when connecting a front-end application to a Flask API. It explains the security reasons behind CORS policies, the role of preflight requests, and provides solutions using Flask-CORS.
-
Check Those 2 Methods to Quickly Deploy Your Python API to AWS Lambda

2 methods to deploy a Python API to AWS Lambda. How to deploy a small Python API quickly, and how to deploy a big Python API with external dependencies or with a Docker image
