← Back to all products

API Versioning Toolkit

$9

Three versioning strategies with deprecation headers, version registry, and migration helpers.

📁 9 files
JSONMarkdownPythonExcel

📄 Product Preview

Try the interactive reader and demo tools below, or get the full product with all content unlocked.

📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample

📁 File Structure 9 files

api-versioning-toolkit/ ├── LICENSE ├── README.md ├── examples/ │ └── config.example.json ├── free-sample.zip ├── guide/ │ ├── 01_api-versioning-toolkit.md │ ├── 02_features.md │ └── 03_quick-start.md ├── index.html └── src/ └── main.py

📖 Documentation Preview README excerpt

API Versioning Toolkit

Three versioning strategies (URL path, header, query param) with deprecation headers and version registry. Zero dependencies.

Part of the API Launchpad toolkit by [CodeVault](https://codevault.dev).

Features

  • Three strategies: URL path (/v1/users), header (X-API-Version: 2), query param (?version=2)
  • Version registry: track active, deprecated, and sunset versions
  • Deprecation headers: automatic Deprecation, Sunset, and X-Deprecation-Notice headers
  • Version middleware: extract version from request, reject unsupported versions
  • Versioned router: dispatch to version-specific handlers with handler reuse
  • Demo server with 3 API versions showing real migration patterns
  • Zero dependencies — runs on Python stdlib only

Quick Start


# Start with URL path versioning
python3 src/main.py --strategy url --port 8000

# Test different versions
curl http://localhost:8000/v1/users        # Version 1 (deprecated)
curl http://localhost:8000/v2/users        # Version 2
curl http://localhost:8000/v3/users        # Version 3 (latest)

# Start with header versioning
python3 src/main.py --strategy header
curl -H "X-API-Version: 2" http://localhost:8000/users

# Start with query param versioning
python3 src/main.py --strategy query
curl "http://localhost:8000/users?version=2"

Strategy Comparison

StrategyURLCacheabilityBrowser-FriendlyRESTful
URL Path/v1/usersExcellentYesDebatable
HeaderX-API-Version: 2VariesNoYes
Query Param?version=2VariesYesNo

When to Use Each

  • URL Path: Most common. Clear, explicit, works everywhere. Choose this if unsure.
  • Header: Keeps URLs clean. Good for internal APIs with controlled clients.
  • Query Param: Easy to test. Good for public APIs where browser testing matters.

Using as a Library


from main import VersionRegistry, URLPathStrategy, VersionMiddleware, VersionedRouter

# 1. Set up version registry
registry = VersionRegistry(default_version=2)
registry.register(1, status="deprecated",
                  deprecation_date="2025-06-01",
                  sunset_date="2026-06-01")

*... continues with setup instructions, usage examples, and more.*

📄 Code Sample .py preview

src/main.py #!/usr/bin/env python3 """ API Versioning Toolkit — URL Path, Header, and Query Param Versioning ======================================================================= Implements three API versioning strategies: URL path (/v1/users), custom header (X-API-Version), and query parameter (?version=1). Includes version negotiation, deprecation warnings, and migration helpers. Zero dependencies. Import or run as demo server. Part of the API Launchpad toolkit by DataNest. License: MIT """ from __future__ import annotations import json import logging import re import time from dataclasses import dataclass, field from datetime import datetime, timezone from http.server import HTTPServer, BaseHTTPRequestHandler from typing import Any, Callable from urllib.parse import parse_qs, urlparse # --------------------------------------------------------------------------- # Configuration # --------------------------------------------------------------------------- DEFAULT_HOST = "0.0.0.0" DEFAULT_PORT = 8000 logging.basicConfig( level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s", datefmt="%Y-%m-%dT%H:%M:%S", ) logger = logging.getLogger("api-versioning") # --------------------------------------------------------------------------- # Version Registry — Track supported, deprecated, and sunset versions # --------------------------------------------------------------------------- @dataclass class VersionInfo: """Metadata about a single API version.""" version: int # ... 471 more lines ...
Buy Now — $9 Back to Products