Azure Resources Visualization

Introduction In this blog, I want to talk about how to leverage az cli to visualize a graph in Python. Note that Azure portal has a tab that shows the visualization of the resources. The reason why I am still interested in this topic is that I want to turn azure resource definition into a data structure, which can then be leveraged to generate different form of diagrams: dependency graph of azure resources data flow diagram (for threat modeling) mermaid diagram (for documentation) sequence diagram (need to get sequence information from users) There are also other tools for visualizing azure resources: ...

March 6, 2025

SQLAlchemy

Intro SQLAlchemy is a very popular ORM Python library. Key Concepts Engine See Engine Configuration. The engine is the starting point for SQLAlchemy application. The very basic usage is to create an engine from a postgresql url: from sqlalchemy import create_engine engine = create_engine("postgresql+psycopg2://scott:tiger@localhost:5432/mydatabase") Session See Session Basics. A session is a “holding zone” for the orm-mapped objects and the database. we can configure properties like autocommit and autoflush, and these settings can impact the performance of the application. ...

March 4, 2025

Pydantic

Pydantic Why do we have multiple classes for the same model? For example: from pydantic import BaseModel class UserBase(BaseModel): name: str email: str class UserCreate(UserBase): password: str class User(UserBase): id: int class Config: orm_mode = True Here’s the response from copilot: In Pydantic, we often define multiple schemas like UserBase, UserCreate, and User to handle different use cases and ensure clear separation of concerns. Here’s why we do this: ...

March 3, 2025

FastAPI

Overview FastAPI is a modern, fast web framework for building APIs with Python. It can provide high performance on par with Node.js and Go. Starlette & Uvicorn Both Starlette and Uvicorn are essential components in the FastAPI ecosystem. Starlette starlette is a lightweight ASGI (Async Server Gateway Interface) framework for building web apps FastAPI is built on top of starlette and pydantic, and it abstracts most of the complexity of starlette starlette provides core functionality for handling web requests, responses, routing, middleware and more. Uvicorn: ...

March 3, 2025

Poetry

Overview Poetry is a dependency management and packaging tool for Python. I have been using it for a while and I really love it since it help simplify the process of managing dependencies and virtual environments. Installation If you have pip installed in your machine. Run the following command to install Poetry. Otherwise, follow this guide. pip install poetry Check if Poetry is installed successfully: $ poetry --version Poetry (version 1.8.2) Create New Project To create a new project: ...

March 3, 2025