Skip to content

v0.2.0 - Multi-Rate Policies & Selectors

Latest

Choose a tag to compare

@dbtreasure dbtreasure released this 11 Aug 05:36

πŸŽ‰ FastAPI Pacer v0.2.0

This release introduces multi-rate policies, flexible selectors, and OpenTelemetry integration.

✨ New Features

Multi-Rate Policies

Apply multiple rate limits simultaneously - all rates must pass:

policy = Policy(
    rates=[
        Rate(1000, "1h"),  # Hourly limit
        Rate(100, "1m"),   # Minute limit  
        Rate(10, "1s"),    # Second limit
    ],
    key="api_key",
    name="tiered"
)

Flexible Selectors

  • Built-in selectors: "ip", "api_key", "user", "org"
  • Compose multiple selectors: compose(key_user, key_ip)
  • Custom selector functions for any identity extraction

OpenTelemetry Integration

from pacer import create_otel_hooks

on_decision, on_error = create_otel_hooks("my-service")
limiter = Limiter(
    redis_url="redis://localhost:6379",
    on_decision=on_decision,
    on_error=on_error,
)

πŸ”„ Breaking Changes

  • Rate objects must now be wrapped in Policy objects
  • Removed extractor parameter from Limiter - use Policy.key instead
  • Removed backward compatibility RedisStorage class

πŸ› Bug Fixes

  • Fixed Lua script error when using multiple rates with padding
  • Fixed Redis KEYS array handling for multi-rate evaluation
  • Fixed burst capacity calculation (immediate requests = 1 + burst)

πŸ“š Documentation

  • Updated README with v0.2.0 examples
  • Added comprehensive migration guide
  • Expanded test coverage to 72+ tests

πŸ—οΈ Technical Improvements

  • Full type safety with mypy clean
  • Replaced deprecated FastAPI on_event with lifespan handlers
  • Improved error handling for multi-rate policies
  • Atomic multi-rate evaluation in single Redis RTT

πŸ“¦ Dependencies

  • FastAPI >= 0.100.0
  • Redis >= 4.5.0
  • Python >= 3.8

πŸ™ Acknowledgments

Thanks to all contributors and users for feedback and testing!


Full Changelog: https://github.com/dan/fastapi-pacer/compare/v0.1.0...v0.2.0