Releases: bagowix/ratelimit-io
Releases · bagowix/ratelimit-io
0.6.5
0.6.4
0.6.3
0.6.2
Features
- Asynchronous Context Manager Support:
- Added
__aenter__
and__aexit__
methods toRatelimitIO
for use as an asynchronous context manager. - Ensures Lua scripts are automatically loaded into Redis when entering the context.
- Simplifies resource management and integration in async frameworks like FastAPI and aiohttp.
- Added
0.6.1
0.6.0
Features
- Improved Error Handling:
- Introduced specific exception classes for better error categorization:
RatelimitIOError
: Base class for rate limit-related errors.RatelimitExceededError
: Raised when the rate limit is exceeded.ScriptLoadError
: Raised when the Lua script fails to load into Redis.
- Enhanced error messages for clarity and debugging.
- Introduced specific exception classes for better error categorization:
- Logging Support:
- Added logging for critical operations and errors:
- Logs errors when the Lua script fails to load into Redis.
- Logs exception details for debugging unexpected issues.
- Added logging for critical operations and errors:
Misc
- Code Simplification and Readability:
- Refactored exception handling for better readability and maintainability.
- Consolidated duplicated logic between synchronous and asynchronous methods.
- Documentation and Examples:
- Updated inline comments and docstrings for clarity.
- Included examples of error handling and logging usage.
- Testing Improvements:
- Increased test coverage for key generation, rate limit enforcement, and exception handling.
- Added edge case tests for
LimitSpec
and Redis Lua script loading.
0.5.0
Features
- Dynamic
is_incoming
Detection:- Added automatic inference for
is_incoming
in decorators based on usage context:- Incoming requests (e.g., API handlers): Raise
RatelimitIOError
when limits are exceeded. - Outgoing requests (e.g., client-side throttling): Wait until a slot is available.
- Incoming requests (e.g., API handlers): Raise
- Default behavior is now
is_incoming=True
, suitable for most incoming request use cases. - Explicit
is_incoming=False
can still be set during initialization for outgoing request handling.
- Added automatic inference for
- Removed
base_url
parameter:- Simplified the API by fully replacing
base_url
withdefault_key
. - Unified logic for key preparation and eliminated redundancy.
- Simplified the API by fully replacing
- Updated
_prepare_key
logic:- Adjusted key priority to:
provided_key > unique_key > default_key > kwargs["ip"] > "unknown_key"
. - Added
async/sync
prefixes to keys for better differentiation in mixed environments.
- Adjusted key priority to:
- Enhanced decorator functionality:
- Supports both synchronous and asynchronous functions.
- Automatically applies appropriate behavior for incoming or outgoing requests.
Fixes
- Fixed issues with key generation for mixed environments:
- Resolved edge cases where default keys were incorrectly prioritized.
- Ensured robust handling of
kwargs["ip"]
when nodefault_key
orunique_key
is provided.
Misc
- Updated README and examples:
- Added detailed explanation for
is_incoming
behavior and dynamic detection. - Removed all references to
base_url
and clarified usage ofdefault_key
. - Included examples for both incoming and outgoing request scenarios.
- Added detailed explanation for
- Improved error messages for missing rate limit specifications (
limit_spec
ordefault_limit
). - Increased test coverage to ensure robust handling of edge cases in key generation, rate limiting, and decorator functionality.
0.4.0
Fixes
- Updated
default_key
inRatelimitIO.__init__
to default toNone
instead of"unknown_key"
, ensuringkwargs["ip"]
is used whenunique_key
anddefault_key
are not provided. - Renamed
_prepare_key_and_limit
to_prepare_key
for clarity. - Refactored
_prepare_key
to simplify logic and resolve inconsistencies in key generation. - Fixed key handling in
wait
anda_wait
to correctly validate and apply rate limits. - Ensured proper rate-limiting behavior for async and sync decorators with function-specific keys.
- Addressed issues causing
NoneType
errors whenlimit_spec
was not provided inwait
anda_wait
.
Misc
- Enhanced key generation with async/sync-specific prefixes to distinguish between function call types.
- Updated
virtualenv
dependency from20.28.1
to20.29.0
viapoetry update
.
0.3.1
Fixes
- Removed
TypeAlias
import fromtyping_extensions
for better compatibility with Python 3.8 and 3.9, asTypeAlias
is now part oftyping
in Python 3.10+. - Replaced the
RedisBackend
alias with a direct use ofUnion[Redis, AsyncRedis]
in thebackend
parameter of the__init__
method for backward compatibility.
Misc
- Updated README with improved examples for:
- Using middleware for FastAPI: Enhanced to include proper error handling with
JSONResponse
for 429 responses, providing more clarity and correctness. - Using middleware for Django: Added a class-based middleware example leveraging
MiddlewareMixin
for better integration with Django's request/response lifecycle. Also demonstrated an example with DRF'sAPIView
.
- Using middleware for FastAPI: Enhanced to include proper error handling with
0.3.0
Features
- Introduced a custom error class
RatelimitIOError
, designed to mirror the behavior ofHTTPException
, making it easier to integrate with web frameworks like Flask, Django, and FastAPI. - Enhanced decorator functionality
- Automatically applies
base_limit
when the decorator is used without explicit arguments.
- Automatically applies
- Added seamless support for distinguishing between incoming and outgoing requests using the
is_incoming
flag. - Implemented 429 Too Many Requests handling:
- Provides examples for integrating with Flask, Django, and FastAPI to manage error responses gracefully.
Fixes
- Fixed an issue where
unique_key
fallback todefault_key
was inconsistent. - Improved Redis script loading to ensure proper error handling and robustness during high-concurrency operations.
Misc
- Updated README with examples for:
- Using decorators and context managers for both sync and async workflows.
- Handling
429 Too Many Requests
errors in popular frameworks.
- Enhanced test coverage to verify all added features and scenarios.