[![License: GNU GPLv3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/ashfaque/AshUtils/blob/main/LICENSE)
## How to install
```sh
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.
```python
# 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.
```python
# 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.
```python
# 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](LICENSE)
Raw data
{
"_id": null,
"home_page": "https://github.com/ashfaque/AshUtils",
"name": "AshUtils",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "ASHFAQUE,ASHFAQUE ALAM,DJANGO,UTILS,DRF,DECORATORS",
"author": "Ashfaque Alam",
"author_email": "ashfaquealam496@yahoo.com",
"download_url": "https://files.pythonhosted.org/packages/06/3f/338f06352782055a2a2d2e157ec818d5a58aafa9a890460a21f79554aeb1/AshUtils-0.2.tar.gz",
"platform": null,
"description": "[![License: GNU GPLv3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/ashfaque/AshUtils/blob/main/LICENSE)\r\n\r\n\r\n\r\n## How to install\r\n```sh\r\npip install AshUtils\r\n```\r\n\r\n\r\n\r\n## Documentation\r\n- @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.\r\n ```python\r\n # Add this in settings.py file\r\n ENABLE_REDIS_RESPONSE_CACHING = os.getenv('ENABLE_REDIS_RESPONSE_CACHING', None)\r\n if ENABLE_REDIS_RESPONSE_CACHING is not None and ENABLE_REDIS_RESPONSE_CACHING != '' and bool(int(ENABLE_REDIS_RESPONSE_CACHING)):\r\n CACHES = {\r\n \"default\": {\r\n \"BACKEND\": \"django_redis.cache.RedisCache\",\r\n \"LOCATION\": \"redis://127.0.0.1:6379/1\", # Adjust this based on your Redis configuration # \"redis://username:password@127.0.0.1:6379\"\r\n \"OPTIONS\": {\r\n \"CLIENT_CLASS\": \"django_redis.client.DefaultClient\",\r\n }\r\n }\r\n }\r\n else:\r\n CACHES = {\r\n \"default\": {\r\n \"BACKEND\": \"django.core.cache.backends.dummy.DummyCache\",\r\n # \"LOCATION\": \"unique-snowflake\",\r\n }\r\n }\r\n\r\n\r\n # Usage:-\r\n\r\n from AshUtils import cache_response_redis\r\n\r\n @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.\r\n @sample_decorator\r\n def get(self, request, *args, **kwargs):\r\n # response = super(__class__, self).get(self, request, args, kwargs)\r\n # return response\r\n ...\r\n ```\r\n\r\n\r\n- @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.\r\n ```python\r\n # Usage:-\r\n\r\n from AshUtils import print_db_queries\r\n\r\n @print_db_queries\r\n @sample_decorator\r\n def get(self, request, *args, **kwargs):\r\n # response = super(__class__, self).get(self, request, args, kwargs)\r\n # return response\r\n ...\r\n ```\r\n\r\n\r\n- @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.\r\n + 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``\r\n + Default log file max size is 50 MB with 3 backups after rotation.\r\n ```python\r\n # Usage:-\r\n\r\n from AshUtils import log_db_queries\r\n\r\n @log_db_queries\r\n @sample_decorator\r\n def get(self, request, *args, **kwargs):\r\n # response = super(__class__, self).get(self, request, args, kwargs)\r\n # return response\r\n ...\r\n ```\r\n\r\n\r\n\r\n## License\r\n[GNU GPLv3](LICENSE)\r\n",
"bugtrack_url": null,
"license": "GNU GPLv3",
"summary": "Boost productivity in Django projects with a comprehensive collection of reusable utilities and decorators.",
"version": "0.2",
"project_urls": {
"Download": "https://github.com/ashfaque/AshUtils/archive/refs/tags/v_02.tar.gz",
"Homepage": "https://github.com/ashfaque/AshUtils"
},
"split_keywords": [
"ashfaque",
"ashfaque alam",
"django",
"utils",
"drf",
"decorators"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "063f338f06352782055a2a2d2e157ec818d5a58aafa9a890460a21f79554aeb1",
"md5": "2be882886fa45313672d4a03b17c519e",
"sha256": "1f70459fc34fc88a71aa824ff7677e7afc85fc1630d007d3150a6a547bf84a23"
},
"downloads": -1,
"filename": "AshUtils-0.2.tar.gz",
"has_sig": false,
"md5_digest": "2be882886fa45313672d4a03b17c519e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 19234,
"upload_time": "2024-01-28T07:51:38",
"upload_time_iso_8601": "2024-01-28T07:51:38.216184Z",
"url": "https://files.pythonhosted.org/packages/06/3f/338f06352782055a2a2d2e157ec818d5a58aafa9a890460a21f79554aeb1/AshUtils-0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-28 07:51:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ashfaque",
"github_project": "AshUtils",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ashutils"
}