Skip to main content

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

Metadata

Release files for AshUtils 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for AshUtils 0.2
File Size Uploaded Provenance
AshUtils-0.2.tar.gz 19.2 kB Without provenance Details

Release files / AshUtils-0.2.tar.gz

Download URL AshUtils-0.2.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1f70459fc34fc88a71aa824ff7677e7afc85fc1630d007d3150a6a547bf84a23
BLAKE2b-256 checksum
How to use checksums
063f338f06352782055a2a2d2e157ec818d5a58aafa9a890460a21f79554aeb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Security for AshUtils 0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page