Digital recording of my learning/experience in software development and life.

FastAPI Request and Response Logging

FastAPI Logging Because of the Starlette ASGI server, it is more difficult to incorporate the Fastapi logging system in the middleware. In starlette, the request body is an async stream. In order to log the request body, this stream must be consumed. The request body can be consumed in a several ways, such as request.body() and request.stream(). Check out the below example of starlette is used to read the body request object....

February 18, 2023 · 2 min · arunkumar

Python Unittest Mock and Patch

Unittest.mock provides the stub to replace an external api call(HTTP request…) during the unittest. Mock and MagicMock create all attributes and methods for the Mock object . We can limit the return values and available attributes. Mock provides the return_value and side_effects. i) return_value just return value when the particular method is called in the test. ii) side_effects allows you to perform some operations(like raising exceptions) and is helpful to call the patch call with different results in sequential order return_value gives the same result in the entire test....

October 1, 2021 · 2 min · arunkumar

Deploy django postgresql in Heroku

Deploying Django to Heroku with PostgreSQL database is simple but we’ll miss some simple stuff and stuck. This article demystify those into simple steps. Initial Installation and setup Before changing any files we need to install require packages. Modules for development setup Decople and Psycopg2 pip install python-decouple pip3 install psycopg2 Decouple module helps us to handle the environment variables for the local development PostgreSQL database adaptor for python. Heroku modules...

January 5, 2021 · 5 min · arunkumar

Introduction to Container and Docker

Every developer has to come across this name containers after Dev-ops and micro-services introduced to them. Let us demystify Docker and Containers. To understand how container works we need to start with the brief history of container. History Is Docker introduced the container first ?. The answer is no. Then who introduced. Below are the Primitives for the Docker NameSpaces(2002) Namespace create a own isolated instance of the global resource....

April 22, 2020 · 7 min · arunkumar

Django Signals Introduction

Django has a signal dispatcher which notifies when certain event occurs in the framework. In simple this like a publisher and subscribers here sender is publisher and receiver is subscribers. The connection between the senders and the receivers is done through “signal dispatchers”. Django allow to create customer signals and has some build-ins too. Let’s look into them. Where should be signal code live: Django suggest it should be in inside the appconfig ready() method....

2 min · arunkumar