InnSight-Backend / api /performance.py
jackonthemike's picture
feat: Sync backend updates including AI Revenue Analyst
cef0de3
"""
API Performance Utilities
This module provides easy access to all performance-related
components including caching, rate limiting, compression, and HTTP client.
Usage:
from performance import (
cache, cached, CacheTTL,
rate_limiter, RateLimitConfig,
http_client, fetch_json,
CompressionMiddleware
)
"""
from .cache import (
InMemoryCache,
CacheEntry,
CacheTTL,
cached,
cache,
create_cache_key,
invalidate_pattern
)
from .rate_limit import (
SlidingWindowRateLimiter,
RateLimitExceeded,
RateLimitInfo,
RateLimitConfig,
rate_limiter,
get_rate_limit_headers,
create_rate_limit_dependency
)
from .compression import (
CompressionMiddleware,
ETaggerMiddleware,
get_compression_stats,
BROTLI_AVAILABLE
)
from .async_http import (
AsyncHTTPClient,
HTTPResponse,
CircuitBreaker,
CircuitBreakerConfig,
CircuitBreakerError,
CircuitState,
http_client,
fetch_json,
post_json
)
__all__ = [
# Cache
"InMemoryCache",
"CacheEntry",
"CacheTTL",
"cached",
"cache",
"create_cache_key",
"invalidate_pattern",
# Rate Limiting
"SlidingWindowRateLimiter",
"RateLimitExceeded",
"RateLimitInfo",
"RateLimitConfig",
"rate_limiter",
"get_rate_limit_headers",
"create_rate_limit_dependency",
# Compression
"CompressionMiddleware",
"ETaggerMiddleware",
"get_compression_stats",
"BROTLI_AVAILABLE",
# HTTP Client
"AsyncHTTPClient",
"HTTPResponse",
"CircuitBreaker",
"CircuitBreakerConfig",
"CircuitBreakerError",
"CircuitState",
"http_client",
"fetch_json",
"post_json"
]
def get_performance_stats() -> dict:
"""Get combined performance statistics"""
return {
"cache": cache.stats,
"rate_limiter": rate_limiter.stats,
"http_client": http_client.stats,
"brotli_available": BROTLI_AVAILABLE
}