Click is a Python package for creating beautiful command-line interfaces with minimal code. Uses decorators for a clean, composable API. Powers Flask, AWS CLI, and many other tools. Use Case Use Click when you need to: Build CLI tools in Python Create nested command groups Handle complex option parsing Generate …
Read MoreVirtual environments isolate Python project dependencies, preventing conflicts between projects. Essential for reproducible research and clean dependency management. Use Case Use virtual environments when you need to: Isolate project dependencies Work on multiple projects with different requirements Ensure reproducible …
Read MoreFastAPI with automatic OpenAPI documentation using Pydantic models and docstrings. Installation 1pip install fastapi uvicorn[standard] 2pip install python-multipart # For form data Basic FastAPI App 1from fastapi import FastAPI 2 3app = FastAPI( 4 title="My API", 5 description="API documentation", 6 …
Read MoreFlask web framework essentials for building web applications and APIs. Installation 1pip install flask 2 3# With extensions 4pip install flask flask-sqlalchemy flask-migrate flask-login flask-wtf flask-cors Basic Flask App 1from flask import Flask 2 3app = Flask(name) 4 5@app.route('/') 6def hello(): 7 …
Read MoreSimple stdin chatbot using LangChain with tool calling (OpenRouter). Installation 1pip install langchain langchain-openai python-dotenv Environment Setup 1# .env 2OPENROUTER_API_KEY=your_api_key_here 3OPENROUTER_MODEL=openai/gpt-4-turbo-preview Basic Chatbot 1import os 2from dotenv import load_dotenv 3from …
Read MorePydantic - Data validation using Python type hints. Installation 1pip install pydantic 2 3# With email validation 4pip install 'pydantic[email]' 5 6# With dotenv support 7pip install 'pydantic[dotenv]' Basic Usage 1from pydantic import BaseModel 2 3class User(BaseModel): 4 id: int 5 name: str 6 email: …
Read MorePython dataclasses for clean, boilerplate-free data structures. Basic Usage 1from dataclasses import dataclass 2 3@dataclass 4class Point: 5 x: float 6 y: float 7 8# Automatically generates init, repr, eq 9p1 = Point(1.0, 2.0) 10p2 = Point(1.0, 2.0) 11 12print(p1) # Point(x=1.0, y=2.0) 13print(p1 == p2) # …
Read MorePython metaclasses with visual explanations using Mermaid diagrams. What are Metaclasses? Metaclasses are classes that create classes. In Python, everything is an object, including classes: $$ \text{type}(\text{instance}) = \text{class} $$ $$ \text{type}(\text{class}) = \text{metaclass} $$ Class Creation Flow Basic …
Read More