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. Also you need to set ENABLE_REDIS_RESPONSE_CACHING=1 in your project's .env file if you want to enable caching API response in redis using this decorator.

    # 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.2.tar.gz (19.2 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for AshUtils-0.2.tar.gz
Algorithm Hash digest
SHA256 1f70459fc34fc88a71aa824ff7677e7afc85fc1630d007d3150a6a547bf84a23
MD5 2be882886fa45313672d4a03b17c519e
BLAKE2b-256 063f338f06352782055a2a2d2e157ec818d5a58aafa9a890460a21f79554aeb1

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