HTTP Persistent Connection

Python requests Connection Pool

Summary Recently I was working on a project that integrated with some internal and external APIs using HTTP requests. You probably have heard about or worked with the requests package in Python which is lile the de-facto HTTP client package which is much more easier to work with compared to the built-in HTTP module of Python. The previous implementation in our project was using the requests library and for each new request it did something like requests....

February 16, 2023 · 4 min · 720 words · Amin

Pydantic Settings with AWS Secrets Manager

Intro If you are already familiar with Pydantic, one of the useful components of Pydantic is the Settings Management. This will allow you to read settings variables from different sources and parse and validate them into class(es) using Pydantic. Let’s see a minimal example. First we need to set up the variable: $ export API_KEY=xxx And then we can read it into the Settings class with: from pydantic import BaseSettings class Settings(BaseSettings): api_key: str print(Settings()....

January 26, 2023 · 5 min · 1002 words · Amin
JSON Logging

Python JSON Logging

Use-case It’s very common for projects to do JSON logging if you are working with third-party tools or open-source projects like Logstash to process your logs. These tools usually need more complex filtering on the structured data, so using JSON is preferred there. We also wanted to integrate with a third-party tool at work and we needed to add the JSON formatting logs in our projects. I will not go into the details of why or why not you should decide JSON logging, as each approach will have it’s pros and cons....

September 14, 2022 · 3 min · 484 words · Amin