Utilizing WebSockets, Queue and APScheduler for batch processing in FastAPI
In this tutorial, I am going to share a simple experiment that I have conducted over the weekend. The basic idea is to queue up all the incoming requests and process them in batches at certain interval each time. To do so, we are going to
The architecture is fairly straightforward and good enough for our case study. Please be reminded that if you are looking for production-ready solutions, you should be using RabbitMQ (message broker) or Celery (distributed task queue) instead based on your use cases. …
One simple trick to make your life easier
By reading this piece, you will learn to create a bash script that automates the restart process for your FastAPI server (production). As you have known, you can restart the server by using the reload argument during development.
uvicorn myapp:app --reload
When FastAPI (uvicorn ASGI) detects changes in the files, it will trigger a reload for you. However, you should not use the
reload argument for the production server. This is simply because it will hog your CPU resources in order to detect changes to the local files.
Most of the time, you are going to deploy it using
& argument which allows the process to continue running in the background. As a result, there might arise situations in which you just want to restart FastAPI…
10000 to 10K | 999999 to 1M | 1234567890 to 1.23B
By reading this piece, you will learn to format an integer (123456) into its own string representation (123K) in Python. This helps to improve the user experience in your application as displaying the number as string representation is a lot more coherent to the users. In this tutorial, I am going to showcase two different implementations:
Having said that, this article does not cover string representation that is less than 0 such as micro and nano. …
Build a monitoring dashboard with AJAX, Promise and React Hooks
By reading this piece, you will learn to create a simple React-based monitoring dashboard which shows the air quality information based on a city selected by the users. Here is an example of the monitoring dashboard.
5 useful tips I wish I had known earlier
By reading this article, you will learn about a few important tricks which help to manage your expectations when integrating with any external third-party APIs. A while ago, I have gone through a painful integration process when dealing with APIs provided by an external vendor. I am a lot wiser now and would like to share the lessons that I have learned from it.
By reading this piece, you will learn to save a drawing on the HTML5 canvas element of your web application as an image. In this tutorial, I will be showcasing two methods to save it.
The first method is to store the image data inside a hyperlink (using the
As for the second method, I am going to convert the canvas as blob data and send it via
FormData to a remote server. After that, you can easily save it on your server. This method is preferred if you are going to do data collection or saving a large amount of images from time to time. …
The topic for today is sets and hashes in Redis. These are two of the most useful data types in Redis and they’re often neglected by developers. It’s important to understand the fundamental concepts behind them because choosing the right data types helps a lot when trying to scale your application.
In this tutorial, I’m using Redis-Py to showcase the functionalities. The concept behind it is the same whichever programming language you use. Redis-Py uses the same name for function call as the original comand, with some minor exceptions. …
A curated list of nine lesser-known Python packages for your machine learning projects
This article will showcase a list of curated Python packages that are meant for machine learning. Over the past few years, there have been quite a number of amazing repositories specialized on machine learning in Github. Hence, I have compiled a list of 9 useful packages that are in active development. The last package release must be within a year from the time of this writing.
It is highly recommended to check them out regardless if you are a beginner or an expert in machine learning as you might find one that is useful to your projects. …
Step-by-step guide to receive files and save them locally
The topic for today is on saving images or text files that users have uploaded to your FastAPI server locally in disk. If you have used Flask before, you should know that it comes with its own built-in
file.save function for saving files. Unfortunately, such feature is not present in FastAPI at the time of this writing. In this tutorial, you will learn to implement this functionality based on your own use cases.
For your information, the bare minimum code for a simple FastAPI server that accepts an image or a file uploaded via
FormData is as…
Rasa Open Source is a machine learning framework used to build text- and voice-based chatbots. Recently, the team behind it successfully reached a notable milestone and released their first official version 2.0 on October 2020. The new version aims at unifying training data formats, configuration files, and the way to handle models. As a result, there are quite a number of major breaking changes compared to the previous version.
In this tutorial, we are going to dive deep into some of the major differences between Rasa 1.10 and the latest release candidate version. …