Skip to main content

A collection of advanced, production-ready Python decorators (Rate Limiting, 2FA, Caching, Retry, Hooks, Dynamic Behavior, Enterprise Security).

Project description

nexalware-decorator

Advanced, reusable Python decorators for production-ready applications.
Includes decorators for security, rate limiting, caching, retries, hooks, dynamic behavior, and enterprise-grade function management.


Features

1. Two-Factor Authentication / Access Control

  • Secure critical functions with roles, OTP, or login verification
  • Attributes: attempts, last_user, last_success_time
  • Example use-case: Banking, admin APIs, sensitive operations

2. Rate Limiter

  • Limit function calls per time window
  • Supports global or per-user limits
  • Optional cooldown after limit exceeded
  • Example use-case: API endpoints, messaging services, email sending

3. Cache / Memoization

  • Cache function outputs for performance
  • Attributes: hits, misses, cache_size
  • Supports TTL (time-to-live) for cached entries
  • Example use-case: Expensive computations, ML predictions, web API responses

4. Retry / Circuit Breaker

  • Retry function calls on failure
  • Circuit breaker disables functions after N failures
  • Attributes: fail_count, last_exception, is_open
  • Example use-case: Network requests, database queries, unstable services

5. Pre/Post Hook

  • Attach hooks dynamically before and after function execution
  • Modify inputs or outputs conditionally
  • Example use-case: Event systems, logging, monitoring pipelines

6. Dynamic Behavior / Configurable Functions

  • Change function behavior at runtime via attributes
  • Attributes: multiplier, mode, threshold
  • Enable/disable behaviors dynamically
  • Example use-case: Algorithmic trading, AI scoring, feature toggles

7. Combined “Security + Logging + Metrics”

  • Enterprise-grade decorator for sensitive operations
  • Features: access control, 2FA, rate limiting, metrics
  • Attributes: call_history, last_user, average_runtime
  • Example use-case: Admin panels, API endpoints, financial operations

Installation

Install from PyPI:

pip install nexalware-decorator
 
--- 

# Rate Limiter Example

from nexalware_decorator import RateLimiter, RateLimitExceeded
import asyncio

limiter = RateLimiter(limit=3, window=10, per_user=True, cooldown=5)

@limiter
async def send_message(text, user_id):
    print(f"Sent: {text}")

async def main():
    user = "user123"
    for i in range(5):
        try:
            await send_message(f"Hello {i}", user_id=user)
        except RateLimitExceeded as e:
            print(e)

asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nexalware_decorator-0.2.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nexalware_decorator-0.2.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file nexalware_decorator-0.2.0.tar.gz.

File metadata

  • Download URL: nexalware_decorator-0.2.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for nexalware_decorator-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1fd8484c30ff3a8c02ebace739e6aa8e0940af64120615175af535c9541a6648
MD5 4e3c1dd8349db2061adf1b7abf620991
BLAKE2b-256 3b5732fa6d2df833eed3e5fd6212763c41da9b512643a6f9d0e793e4d10e9f2a

See more details on using hashes here.

File details

Details for the file nexalware_decorator-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nexalware_decorator-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 efefbab4bc2d4880f84a3c6d924cd3463b42f356c7a8ee7679e0ebee2344e4ee
MD5 a192d82273eff31647a73bde58f146fe
BLAKE2b-256 4f485857718e2af49da71e473427f4dc3e2ac5ccfb7865510da53cb750d35b54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page