A practical guide to structured logging for production services, with emphasis on observability platforms like Datadog, Splunk, and CloudWatch.
CRITICAL → System is unusable, wake someone up at 3am
| # Python Project Refactor Playbook | |
| A comprehensive guide for refactoring monolithic Python applications (Flask, Django, FastAPI) into maintainable, production-ready codebases. | |
| ## 📋 Pre-Refactoring Assessment | |
| ### 1. Current State Analysis | |
| ```bash | |
| # Analyze codebase structure | |
| find . -name "*.py" -exec wc -l {} + | sort -nr |
Based on the successful refactoring patterns I've seen before, here's a comprehensive playbook for refactoring another frontend. This guide will help another agent execute the same high-quality refactoring.
📋 Pre-Refactoring Checklist
1. Analyze Current Structure
- Map out all files in the dashboard directory
| #!/bin/bash | |
| # cycle_stack.sh - Script to tear down and rebuild Docker Compose services | |
| # Usage: ./cycle_stack.sh [service_name1] [service_name2] ... | |
| set -e # Exit on error | |
| # Check if Docker Compose is installed | |
| if ! command -v docker compose &>/dev/null; then | |
| echo "Error: docker compose is not installed or not in PATH" |
| # Makefile for managing Python dependencies with uv | |
| # | |
| # I built this because I got tired of juggling uv, pip, pyproject.toml, | |
| # and requirements.txt by hand. This Makefile gives me fast, reproducible | |
| # dependency management without forgetting to freeze, clean, or sync anything. | |
| # | |
| # Were I smarter I'd probably not have to do this. But, alas, I'm not. | |
| # | |
| # Key commands: | |
| # |
#!/bin/zsh
# Usage:
# ./download_site.sh {URL}
url=$1
output_dir="./sites"Switching from a synchronous setup to an asynchronous one in your FastAPI/SQLModel app can bring some challenges. When making this switch, several important details need attention, especially around async sessions, avoiding misuse of await, and correctly handling relationships between tables.
# sync version
engine = create_engine(database_settings.pg_connection_string)
session = sessionmaker(bind=engine)You might have run into a situation where your SQLModel app unexpectedly runs out of database connections. If that sounds familiar, you probably have something like this in your code:
# utils/db.py
def get_db():
"""A utility function to grab a database session."""Introduction:
Enums are a great way to represent a fixed set of values in your database. In this example, we'll model an IceCreamShop that serves various flavors of ice cream using SQLModel and PostgreSQL. We'll demonstrate how to store these flavors using enums and how to query for specific flavors using SQLAlchemy's powerful querying capabilities.
import os
from enum import Enum
from typing import List, Optional