Skip to content

Releases: Msameim181/Fastrict

v0.1.3

15 Oct 07:11

Choose a tag to compare

v0.1.2

06 Oct 08:21

Choose a tag to compare

Full Changelog: v0.1.1...v0.1.2

v0.1.1

03 Oct 14:42

Choose a tag to compare

[0.1.1] - 2025-10-03

Fixed

  • Type Validation Improvements: Resolved TypeAdapter compatibility issues when using the @throttle decorator with complex Query Parameter extraction scenarios
  • Query Parameter Handling: Enhanced robustness for nested and multi-type query parameter processing in rate limiting contexts
  • Decorator Stability: Improved error handling and type coercion for edge cases in parameter-based key extraction strategies

Full Changelog: v0.1.0...v0.1.1

v0.1.0

03 Oct 10:31

Choose a tag to compare

πŸš€ Fastrict v0.1.0 - Advanced Fallback Key Extraction

The most powerful FastAPI rate limiter just got smarter!

We're excited to announce Fastrict v0.1.0, featuring revolutionary fallback key extraction strategies that bring enterprise-grade flexibility to your rate limiting needs.

✨ Major New Features

🎯 Middleware Default Key Extraction

Set a default key extraction strategy for your entire application that applies to all routes unless overridden.

# Create intelligent fallback strategy for middleware
default_strategy = create_api_key_fallback(
    api_key_header="X-API-Key",
    auth_header="Authorization"
    # Automatically falls back to IP if headers are missing
)

app.add_middleware(
    RateLimitMiddleware,
    rate_limit_use_case=rate_limiter,
    default_key_extraction=default_strategy  # πŸ†• NEW!
)

πŸ”„ Intelligent Fallback Key Extraction

Try multiple extraction methods in sequence until one succeeds - perfect for real-world authentication scenarios.

# Try API key β†’ Auth header β†’ IP address (in that order)
@app.get("/api/data")
@throttle(
    limit=100, ttl=3600,
    key_extraction_strategy=create_api_key_fallback()  # πŸ†• NEW!
)
async def protected_endpoint():
    return {"data": "intelligently rate limited"}

πŸ› οΈ Pre-built Helper Functions

Get started instantly with production-ready fallback patterns:

  • create_auth_header_fallback() - Authorization header β†’ IP
  • create_api_key_fallback() - API key β†’ Auth header β†’ IP
  • create_user_id_fallback() - User ID param β†’ header β†’ IP

🎨 Enhanced Decorator Support

Pass complete KeyExtractionStrategy objects directly to the @throttle decorator:

@throttle(
    limit=50, ttl=600,
    key_extraction_strategy=custom_fallback_strategy  # πŸ†• NEW!
)
async def my_endpoint():
    return {"data": "advanced rate limiting"}

πŸ—οΈ Technical Enhancements

πŸ”§ New Enum Value

  • Added KeyExtractionType.FALLBACK for sequential extraction strategies

πŸ“Š Enhanced Data Models

  • KeyExtractionStrategy now supports fallback_strategies field for nested fallback logic

🎯 Smart Priority System

  1. Route-specific config (highest priority)
  2. Middleware default strategy
  3. IP address fallback (always works)

πŸ”„ Backward Compatibility

  • All existing code continues to work without changes
  • Default behavior preserved when no strategy is specified
  • Existing middleware and decorator parameters function as before

🎯 Real-World Use Cases

🏒 Multi-Tenant SaaS

# Perfect for tenant isolation with graceful fallbacks
middleware_strategy = create_api_key_fallback()
app.add_middleware(
    RateLimitMiddleware,
    rate_limit_use_case=rate_limiter,
    default_key_extraction=middleware_strategy
)

πŸ” Authentication APIs

# Handle authenticated and anonymous users intelligently
@app.post("/api/secure")
@throttle(
    limit=100, ttl=3600,
    key_extraction_strategy=create_auth_header_fallback()
)
async def secure_endpoint():
    return {"data": "authenticated or IP-based limiting"}

πŸ“± Mobile Applications

# Graceful degradation for mobile apps with inconsistent headers
@app.get("/api/mobile-data")
@throttle(
    limit=200, ttl=3600,
    key_extraction_strategy=create_user_id_fallback()
)
async def mobile_api():
    return {"data": "mobile-optimized rate limiting"}

πŸ“Š Performance

Fastrict v0.1.0 maintains our exceptional performance standards:

  • ⚑ 0.37ms average response time
  • πŸš€ 3,600+ RPS concurrent throughput
  • 🎯 100% success rate under load
  • πŸ›‘οΈ 100% rate limiting accuracy

πŸ”„ Migration Guide

For Existing Users

No action required! v0.1.0 is fully backward compatible. Your existing rate limiting configurations will continue to work exactly as before.

To Use New Features

Simply add the new parameters when ready:

# Before (still works)
app.add_middleware(
    RateLimitMiddleware,
    rate_limit_use_case=rate_limiter
)

# After (enhanced)
app.add_middleware(
    RateLimitMiddleware,
    rate_limit_use_case=rate_limiter,
    default_key_extraction=create_api_key_fallback()  # Add when ready
)

πŸ“¦ Installation

# Install the latest version
pip install fastrict==0.1.0

# Or upgrade from previous version
pip install --upgrade fastrict

πŸ”— Links & Resources

πŸ™ Acknowledgments

Special thanks to our community for the feedback and feature requests that shaped this release. Your real-world use cases drive our development priorities!

πŸš€ What's Next?

Stay tuned for upcoming features:

  • 🌐 GraphQL support
  • πŸ“Š Prometheus metrics
  • πŸ”„ Circuit breaker integration
  • 🎯 Rate limit warming

Happy rate limiting! πŸŽ‰

The Fastrict Team


πŸ“‹ Full Changelog

Added:

  • Middleware Default Key Extraction via default_key_extraction parameter
  • Fallback Key Extraction with KeyExtractionType.FALLBACK
  • Helper functions: create_auth_header_fallback(), create_api_key_fallback(), create_user_id_fallback()
  • Enhanced decorator with key_extraction_strategy parameter
  • Flexible priority system: Route-specific > Middleware default > IP fallback

Enhanced:

  • Key extraction logic supports complex fallback scenarios
  • Middleware can set default extraction strategy for all routes
  • Decorator supports complete KeyExtractionStrategy objects
  • Comprehensive documentation with fallback examples

Fixed:

  • No breaking changes - fully backward compatible

v0.0.3

02 Oct 20:24

Choose a tag to compare

πŸš€ Fastrict - Enterprise FastAPI Rate Limiter

The most powerful, flexible, and production-ready rate limiting system for FastAPI applications.

Fastrict provides enterprise-grade rate limiting with Redis and in-memory backends, supporting everything from simple API throttling to complex multi-tenant rate limiting strategies.

πŸ“¦ Installation

# Install from PyPI
pip install fastrict

# Install with development dependencies
pip install fastrict[dev]

# Install with documentation dependencies
pip install fastrict[docs]

πŸ”§ System Requirements

Component Version Purpose
Python 3.8+ Core runtime
FastAPI 0.68+ Web framework
Redis 4.0+ Primary storage backend
Pydantic 1.8+ Data validation
Starlette 0.14+ ASGI framework

πŸš€ Quick Start

🎯 1. Basic Setup (30 seconds)

from fastapi import FastAPI
from fastrict import RateLimitMiddleware, RedisRateLimitRepository
from fastrict import RateLimitUseCase, KeyExtractionUseCase

# Create FastAPI app
app = FastAPI(title="My Rate Limited API")

# Setup rate limiting (Redis)
repository = RedisRateLimitRepository.from_url("redis://localhost:6379")
key_extraction = KeyExtractionUseCase()
rate_limiter = RateLimitUseCase(repository, key_extraction)

# Add global rate limiting middleware
app.add_middleware(
    RateLimitMiddleware,
    rate_limit_use_case=rate_limiter,
    excluded_paths=["/health", "/docs", "/metrics"]
)

@app.get("/api/data")
async def get_data():
    return {"message": "This endpoint is globally rate limited"}

πŸ“š Resources & Documentation

πŸ“– Documentation

πŸ†˜ Support Channels

  • πŸ› Issue Tracker - Bug reports & feature requests
  • πŸ’¬ Discussions - Community Q&A
  • πŸ“§ Email - Direct support for enterprise users
  • πŸ’Ό LinkedIn - Professional inquiries

πŸ”— Related Projects

  • FastAPI - Modern, fast web framework for building APIs
  • Redis - In-memory data structure store
  • Starlette - Lightweight ASGI framework
  • Pydantic - Data validation using Python type hints