-
Compare Dictionary, Named Tuple, Data Class, and Pydantic Model in Python
Python is an object-oriented programming language and there are various ways to represent data as objects. Simple objects can be represented by dictionaries with key-value pairs. And more complex ones can be represented by some special data classes including namedtuple, data class, and Pydantic models. In this post, we will introduce these data types with… Continue reading
-
How to Debug Your Microservice Python Code Running Remotely in Docker
Nowadays, it’s a good practice to Dockerize our Python API code running as microservices, which can make the code easier to develop, deploy, and maintain. During the development or maintenance stages, we often need to debug our code that doesn’t run properly. We cannot use the traditional PDB library to debug API code. Instead, some… Continue reading
-
Build an Autocomplete Search Project Using Elasticsearch, FastAPI, and Angular (Part I — Backend)
Autocomplete search (search as you type) is a very user-friendly feature implemented on almost all websites providing search services. Users can see results popping up as they type. It will be easier to find the product a user is searching for and also help them correct the typos they made if no results are shown.… Continue reading
-
Use Triggers and Audit/Log Tables to Track Table Changes in MySQL
In MySQL and any relational databases, a trigger is some code that is executed automatically when some event is fired. Depending on the event, there are triggers that are run before or after a table row is inserted, updated, or deleted. In this post, we will introduce how to use triggers to keep track of… Continue reading
-
Important MySQL Data Definition Language (DDL) commands we should know for managing our tables
As a data engineer, checking and updating the schemas of tables is our bread and butter. There are plenty of tutorials online already but few of them focus on the conventions that should be followed. SQL is very flexible and can work in a “robust” way. You can use both lowercase and uppercase queries and… Continue reading
-
How to Add Command-line Arguments for a Python Program with argparse
When writing executable Python programs, we should always add some command-line arguments to make them easier to use. Most users will run the program with the -h or–help option to see the usage instructions of the program. A native way to parse command-line arguments is by using sys.argv. However, it’s not user-friendly and we need… Continue reading
-
How to Connect to GCP Cloud SQL with Cloud SQL Auth Proxy in Docker
Cloud SQL on the Google Cloud Platform (GCP) is a great service if you want to host your relational databases in the cloud. There are some standard ways to connect to Cloud SQL from your GCP resources like Cloud Run, Compute engine, etc. However, it’s not as well documented regarding how to connect your dockerized… Continue reading
-
How to Handle Errors and Exceptions Properly in Python
Error or exception handling in Python may seem pretty simple to us, as we just need to use try and except to catch the exception and deal with it. Yes, it is simple to use. However, some bad habits of dealing with exceptions can make our code buggy and difficult to maintain. Many developers may… Continue reading
-
How to Send Emails in Python with GCP Cloud Function as a Microservice
Learn different ways to send emails in Python and trigger GCP Cloud Functions It’s common to send emails programmatically in an application. For example, emails can be sent to developers when critical API errors occur. Besides, emails need to be sent out to users automatically for registration, password reset, or service confirmation. In this post,… Continue reading
-
Build a WebSocket Application with FastAPI and Angular
Learn to build a two-way interactive communication application with the WebSocket protocol. Similar to HTTP, WebSocket is also a communication protocol used in client-server communications. However, unlike HTTP, WebSocket is a bidirectional interactive protocol that allows the client to send messages to the server and also receive event-driven responses passively from the server without having… Continue reading