python

python
INSTALLED_APPS += ['silk']

MIDDLEWARE += ['silk.middleware.SilkyMiddleware']

# Silk configuration
SILKY_PYTHON_PROFILER = True

Django performance monitoring with django-silk

django python performance
by Priya Sharma 3 tabs
python
import csv


class _LineBuffer:
    def __init__(self):
        self._data = ""

Stream a Large CSV Export in Chunks from a Flask Endpoint

flask streaming csv
by codesnips 3 tabs
python
from argon2 import PasswordHasher

password_hasher = PasswordHasher(
    time_cost=3,
    memory_cost=65536,
    parallelism=4,

Password hashing with Argon2 and bcrypt migration paths

passwords argon2 bcrypt
by Kai Nakamura 1 tab
python
from sqlalchemy import select
from sqlalchemy.orm import Session

from .models import User

BATCH_SIZE = 1000

Stream a Large CSV Export in FastAPI With StreamingResponse and a Generator

fastapi streaming csv
by codesnips 3 tabs
python
from dataclasses import dataclass, field
from datetime import datetime, timezone
from decimal import Decimal


def _now():

Synchronous Domain Event Bus with a Registry-Based Publisher in Python

domain-events event-bus pubsub
by codesnips 3 tabs
python
import base64
import json
from datetime import datetime


class InvalidCursor(Exception):

Cursor-Based Pagination for a Flask JSON API Blueprint

flask pagination cursor
by codesnips 3 tabs
python
import errno
import fcntl
import os
import time

File-Based Locking to Prevent Concurrent Cron Job Runs in Python

locking concurrency fcntl
by codesnips 3 tabs
python
import functools
import threading


def debounce(wait):
    def decorator(func):

Debounce Repeated Function Calls With a Thread-Safe Python Decorator

python decorators debounce
by codesnips 2 tabs
python
from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.template.loader import render_to_string
from django.conf import settings
import os

Django email with attachments and templates

django python email
by Priya Sharma 1 tab
python
import base64
import json

from django.core.exceptions import BadRequest

Cursor-Paginated JSON Feed with a Django Class-Based ListView

django pagination cursor-pagination
by codesnips 3 tabs
python
CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/1',
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',

Django redis caching strategies

django python redis
by Priya Sharma 2 tabs
python
import io
import os
from uuid import uuid4
from PIL import Image, UnidentifiedImageError

ALLOWED_FORMATS = {"JPEG", "PNG", "WEBP"}

Validate and Generate Image Thumbnails on a Flask Upload Endpoint With Pillow

flask pillow image-processing
by codesnips 3 tabs