Implementing Content Security Policy (CSP) Headers in Flask to Prevent XSS
Implement CSP headers in Flask using @after_request, nonces, and report-only mode to mitigate XSS risks. Covers directives, common violations, and verification.
The go-to resource for upgrading Python, Django, Flask, and your dependencies.
69 articles on upgrading Python, Django, Flask, and managing dependencies
Implement CSP headers in Flask using @after_request, nonces, and report-only mode to mitigate XSS risks. Covers directives, common violations, and verification.
Implement OAuth2 password flow in FastAPI with JWT tokens: secure authentication using PyJWT and passlib, including login endpoint, protected routes, and curl tests with a fake user database.
Step-by-step guide to migrate from pyenv to mise for Python version management and upgrades from Python 3.12 to 3.13. Mise offers multi-language support, tasks, and project-specific environments.
Step-by-step guide to migrate Flask apps from requirements.txt to pyproject.toml using Poetry for reproducible builds, efficient installs, and modern packaging standards.
Migrate Django tests from unittest to pytest: Replace setUp with 7 fixture patterns for faster, parallel tests. Django 5.1 + pytest-django 5.0 examples.
Mise prebuilt binaries vs source compilation: up to 8x faster Python installs in benchmarks on Ubuntu/macOS. Includes setup, workflow, and when to use each.
Install and manage Python 3.11, 3.12, and 3.13 simultaneously using mise on Windows WSL2. Covers installation, per-project configuration with .tool-versions, and virtual environment integration.
Compare mise and asdf Python version managers on M1/M2 Macs with real benchmarks. Discover which is faster for Python development on Apple Silicon.
pip-tools vs Poetry vs uv comparison for conflicting setuptools versions: Benchmarks, resolution strategies, and which Python dependency manager prevents build failures in complex environments.
poetry add vs pip install comparison: Learn how Poetry lock files prevent production dependency conflicts, ensure reproducible builds, and solve Python dependency hell for reliable deployments.
Pydantic v2 @model_validator(mode='before') receives model instances in some cases like field assignment. Fixes for FastAPI migration, including code examples and tests.
Configure .coveragerc to omit virtual environments (venv, .tox), migrations, and other non-source files from pytest-cov reports, focusing on application code. Includes configuration example and Django demo.
pytest-mock vs unittest.mock: MagicMock false positives hide KeyError/AttributeError bugs. pytest mocker.patch with autospec=True catches issues early. Python mocking pitfalls, migration guide, strict mocking best practices. Keywords: pytest-mock vs unittest.mock, MagicMock false positive, pytest mocker fixture, mock spec=Dict, python mocking best practices.
Python 3.12 EOL: Active support ended April 2025, security fixes until Oct 2028. Upgrade to 3.13 guide using mise/asdf/uv: timelines, steps, compatibility, new features.
We benchmark a minimal FastAPI application on Python 3.12 and 3.13 to measure real-world performance differences in RPS and latency for JSON GET and POST endpoints using Locust and uvicorn workers.
Python performance optimization guide: Profile with cProfile/py-spy, fix memory leaks with memory_profiler, speed up with Numba JIT and multiprocessing. Examples demonstrate up to 5-10x speedups and memory savings in loops, pandas, and APIs. Tested with Python 3.13 tools. Keywords: python performance optimization, optimize python code, python profiling cProfile py-spy, reduce python memory usage, python numba speedup, python multiprocessing performance.
Compare the best Python version managers: pyenv for Python-specific control, asdf for multi-language support, and mise for speed and versatility. Learn installation, usage, and which to choose in 2026.
Django ORM N+1 query optimization: select_related for ForeignKey (joins), prefetch_related for ManyToMany/reverse FK (separate queries+caches). Blog example: 501→151 queries, 500ms→150ms (70% faster). django-debug-toolbar verify. Keywords: 'django select_related prefetch_related', 'django n+1 fix', 'django orm performance', 'reduce django queries', 'select_related vs prefetch_related django'.
Reduce FastAPI Docker images from 1.2 GB to 145 MB using Alpine multistage builds and uv. Includes benchmarks, production Dockerfile, .dockerignore, and pitfalls.
Flask startup optimization: Diagnose slow imports/extensions with py-spy/cProfile, implement lazy loading, disable debug mode, gunicorn preload/app factory. Benchmarks: 8.2s → 0.82s (90% faster). Fix dev restarts, serverless cold starts, k8s deployments.
Need help maintaining or upgrading your Python application? Durable Programming specializes in keeping Python apps secure, performant, and up-to-date.
Hire Durable Programming