Skip to main content

Boost productivity in Django projects with a comprehensive collection of reusable utilities and decorators.

Project description

License: GNU GPLv3

How to install

pip install AshUtils

Documentation

  • @cache_response_redis is a django specific decorator, works with get or list method of a class based DRF view. Used to cache the API response in Redis with a default timeout of 5 mins. which can be overridden.

    # Add this in settings.py file
    ENABLE_REDIS_RESPONSE_CACHING = os.getenv('ENABLE_REDIS_RESPONSE_CACHING', None)
    if ENABLE_REDIS_RESPONSE_CACHING is not None and ENABLE_REDIS_RESPONSE_CACHING != '' and bool(int(ENABLE_REDIS_RESPONSE_CACHING)):
        CACHES = {
            "default": {
                "BACKEND": "django_redis.cache.RedisCache",
                "LOCATION": "redis://127.0.0.1:6379/1",    # Adjust this based on your Redis configuration    # "redis://username:password@127.0.0.1:6379"
                "OPTIONS": {
                    "CLIENT_CLASS": "django_redis.client.DefaultClient",
                }
            }
        }
    else:
        CACHES = {
            "default": {
                "BACKEND": "django.core.cache.backends.dummy.DummyCache",
                # "LOCATION": "unique-snowflake",
            }
        }
    
    
    # Usage:-
    
    from AshUtils import cache_response_redis
    
    @cache_response_redis(timeout=15, key_prefix='API_NAME_AS_PREFIX_USED_IN_CACHE_KEY')    # ? cache_response_redis decorator should be used only for GET API's get or list method. And it should be the top most decorator.
    @sample_decorator
    def get(self, request, *args, **kwargs):
        response = super(__class__, self).get(self, request, args, kwargs)
        return response
    
  • @print_db_queries is a django specific decorator, works with any method of a class based DRF view. It prints out the raw SQL queries running behind Django's ORM.

    # Usage:-
    
    from AshUtils import print_db_queries
    
    @print_db_queries
    @sample_decorator
    def get(self, request, *args, **kwargs):
        response = super(__class__, self).get(self, request, args, kwargs)
        return response
    
  • @log_db_queries is a django specific decorator, works with any method of a class based DRF view. It logs the raw SQL queries running behind Django's ORM.

    • DJANGO_ROOT needs to be configured in settings.py, as the default log path is `DJANGO_ROOT/logs/db_query_logs.db_query_logger.log``
    • Default log file max size is 50 MB with 3 backups after rotation.
    # Usage:-

    from AshUtils import log_db_queries

    @log_db_queries
    @sample_decorator
    def get(self, request, *args, **kwargs):
        response = super(__class__, self).get(self, request, args, kwargs)
        return response

License

GNU GPLv3

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

AshUtils-0.1.tar.gz (19.0 kB view details)

Uploaded Source

File details

Details for the file AshUtils-0.1.tar.gz.

File metadata

  • Download URL: AshUtils-0.1.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for AshUtils-0.1.tar.gz
Algorithm Hash digest
SHA256 3f9fb23f5dc1f33c6f1a486107fed3c86e1965aee872feee17c4f4d994eb9494
MD5 e0a2e537b76ac3fcda8dc80090392089
BLAKE2b-256 0cff1b07bc57ccdcd13a6e6692a75d8ee26a6f05d8ee6fac3a35da2774adef7e

See more details on using hashes here.

Provenance

Supported by

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