python

python
import json
import secrets
import time
from typing import Optional

import redis.asyncio as redis

Sliding-Window Session Token Expiry With FastAPI Middleware and Redis

fastapi redis sessions
by codesnips 3 tabs
python
from django.db import models


class Post(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()

Django model inheritance with proxy models

django python models
by Priya Sharma 1 tab
python
import base64
import json
from datetime import datetime
from typing import Optional, Tuple

Opaque Cursor Pagination for FastAPI Endpoints with SQLAlchemy

fastapi sqlalchemy pagination
by codesnips 3 tabs
python
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

sns.set_theme(style='whitegrid', palette='deep', context='talk')
plt.rcParams.update({

Matplotlib and Seaborn defaults that make charts publication ready

matplotlib seaborn visualization
by Dr. Elena Vasquez 1 tab
python
import uuid
from django.db import models


class Cart(models.Model):
    OPEN = "open"

Prevent Duplicate Order Submissions in Django with select_for_update Row Locking

django postgres concurrency
by codesnips 3 tabs
erb
{% load cache %}
<section class="dashboard">
  <h1>{{ team.name }} — Overview</h1>

  {% cache 3600 team_order_stats team.id stats_version %}
    <div class="stat-grid">

Cache an Expensive Dashboard Fragment with Django's Template Cache Tag and Signal-Based Invalidation

django caching template-cache
by codesnips 3 tabs
python
from datetime import datetime

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

Register a Custom Flask CLI Command to Seed the Database with Faker

flask cli click
by codesnips 3 tabs
python
import abc
from typing import IO


class Exporter(abc.ABC):
    name: str = ""

Plugin Registry with Class Decorators and setuptools Entry-Point Discovery

python plugins decorators
by codesnips 4 tabs
python
import asyncio
import time
from dataclasses import dataclass
from typing import Any, Dict

In-Memory TTL Cache for FastAPI Endpoints With a Cache-Key Builder Dependency

fastapi caching ttl
by codesnips 3 tabs
python
from flask import jsonify
from marshmallow import ValidationError as MarshmallowValidationError
from werkzeug.exceptions import HTTPException


class ApiError(Exception):

Structured JSON Error Handling for Flask API Validation Failures

flask rest-api error-handling
by codesnips 3 tabs
python
from sqlalchemy import select

from .models import Order, db


def stream_orders(batch_size=1000):

Stream a Large CSV Export in Flask With a Generator Response

flask streaming csv
by codesnips 3 tabs
python
from django.db import migrations


def populate_slugs(apps, schema_editor):
    """Generate slugs for existing posts."""
    Post = apps.get_model('blog', 'Post')

Django database migrations best practices

django python migrations
by Priya Sharma 1 tab