User Attribute-Based Authorization in Multitenant Apps - Django-tenants

Context: This article assumes you’re using django-tenants for schema-based multitenancy (separate PostgreSQL schema per tenant). The authorization pattern described here works specifically with django-tenants’ schema_context() approach. If you’re curious, read the AWS cognito part as well. The Problem When building a multitenant application with django-tenants, we needed to control which PostgreSQL schema each user could access. Each tenant has its own isolated schema, but we needed a lightweight authorization mechanism to ensure users could only access their assigned tenant’s data. ...

May 15, 2025 · 6 min

Python - A Clean Way to Traverse Nested Dict/List

I had to work with some complex structured JSON responses having multiple levels of nesting. The issue has always been that the API would return nested JSON where I have to walk different levels to get data by using x.get('y')[0].get... chains. For this very reason, I was looking for an optimal and efficient solution so that at least I can avoid calling get() many times. The Problem Let’s say you’re working with user data from an API: ...

August 28, 2024 · 3 min

Global variables in AWS λ are dirty!

Hello everyone, I know that it has been a long time since i wrote a post. I hope every thing is going well with you. I always wanted to consistently write here. But lets see if I can make it possible sometime soon :) What is this post about? Today, as usual i started off the job in the morning. I’m at a juncture point of building a part of the project. There again, we need yet another micro-service. So, I started writing a piece of script (Python) that needs to be deployed in AWS Lambda. This usually should only take couple of hours, max. But, after that i wrote it, I realized that, half the time writing the script was spent on debugging an issue that i did not even understand how/why it happens. After finding the why/how, I thought it’ll good to share it here and someone will find it useful on the way. ...

November 1, 2023 · 4 min