{"id":31742872,"url":"https://github.com/vishalanandl177/general-methods","last_synced_at":"2025-10-09T11:19:43.843Z","repository":{"id":57433502,"uuid":"293872163","full_name":"vishalanandl177/General-Methods","owner":"vishalanandl177","description":"A general utility for your Django Rest Framework project.","archived":false,"fork":false,"pushed_at":"2020-09-08T20:58:37.000Z","size":30,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-12T06:37:53.710Z","etag":null,"topics":["django-rest-framework","encryption-algorithms","hashing-algorithm","python","python3","response","utility-library"],"latest_commit_sha":null,"homepage":"https://github.com/vishalanandl177/General-Methods","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vishalanandl177.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-08T16:51:42.000Z","updated_at":"2024-05-15T12:54:55.000Z","dependencies_parsed_at":"2022-08-28T04:41:11.988Z","dependency_job_id":null,"html_url":"https://github.com/vishalanandl177/General-Methods","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/vishalanandl177/General-Methods","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishalanandl177%2FGeneral-Methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishalanandl177%2FGeneral-Methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishalanandl177%2FGeneral-Methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishalanandl177%2FGeneral-Methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vishalanandl177","download_url":"https://codeload.github.com/vishalanandl177/General-Methods/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vishalanandl177%2FGeneral-Methods/sbom","scorecard":{"id":923439,"data":{"date":"2025-08-04","repo":{"name":"github.com/vishalanandl177/General-Methods","commit":"6ddbd5566211c379d932efa3feefd7c87d4b4c98"},"scorecard":{"version":"v5.2.1-28-gc1d103a9","commit":"c1d103a9bb9f635ec7260bf9aa0699466fa4be0e"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/5 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: GNU General Public License v3.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-25T07:07:20.329Z","repository_id":57433502,"created_at":"2025-08-25T07:07:20.329Z","updated_at":"2025-08-25T07:07:20.329Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001290,"owners_count":26083058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django-rest-framework","encryption-algorithms","hashing-algorithm","python","python3","response","utility-library"],"created_at":"2025-10-09T11:19:38.824Z","updated_at":"2025-10-09T11:19:43.839Z","avatar_url":"https://github.com/vishalanandl177.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# General-Methods\n![version](https://img.shields.io/badge/version-0.0.2-blue.svg)\n\nA general utility for your Django Rest Framework project.\n\n## Installation\n\nInstall or add general-methods.\n```\npip install general-methods\n```\n\n## Utils functions\nImport utils.\n```\nfrom general_methods import utils\n```\n### Get Headers\nTo get headers (Dictionary type) from request.\n\n```\nheaders = utils.get_headers(request)\n```\n\n### Get Client IP Address\nTo get client IP Address.\n\n```\nclient_ip_address = utils.get_client_ip_address(request)\n```\n\n### Generate Random Token\nTo generate random alpha-numeric string. Default string length is 20.\n\n```\ntoken = utils.generate_token()  // Default token length is 20 characters.\n```\n```\ntoken = utils.generate_token(length=50)  // Token length is 50 characters.\n```\n\n### Get UUID\nTo get UUID string.\n\n```\nuuid = utils.get_uuid()\n```\n\n### Hash algorithms.\nThe available algorithms are : 'sha256', 'sha384', 'sha224', 'sha512', 'sha1', 'md5'\n##### SHA1\n```\nhashed_string = utils.sha1('string_to_hash')\n```\n##### SHA224\n```\nhashed_string = utils.sha224('string_to_hash')\n```\n##### SHA256\n```\nhashed_string = utils.sha256('string_to_hash')\n```\n##### SHA384\n```\nhashed_string = utils.sha384('string_to_hash')\n```\n##### SHA512\n```\nhashed_string = utils.sha512('string_to_hash')\n```\n##### MD5\n```\nhashed_string = utils.md5('string_to_hash')\n```\n### Encode String Data\nTo encode string data using django SECRET_KEY (available in settings.py file) as key to encode.\n\nNote: If you changed the secret key of your django application then it won't decode the string back. Use only in run time use-cases for example encode user id before sending it to client side so client will never get to know the actual user id.\n```\nencoded_data = utils.encode('MY_DATA_TO_ENCODE')\n```\n### Decode String Data\nTo decode string data using django SECRET_KEY (available in settings.py file) as key to decode.\n```\ndecoded_data = utils.decode('MY_DATA_TO_DECODE')\n```\n\n### Is Valid JSON\nTo identify JSON data is valid or not. If valid, returns True else False.\n\n```\nis_valid_json = utils.is_valid_json({'key': 'value'})\n```\n### Is Valid EMAIL ID\nTo identify email is valid or not. If valid, returns True else False.\n\n```\nis_valid_email = utils.is_valid_email('abc@mail.com')\n```\n## Response functions\nNote: Returns application/json response.\n\nImport response.\n```\nfrom general_methods import response\n```\n\n### Success Response 200\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 200\n\nFunction:\nresponse.success('Any Type of Data')\n\n```\nclass MyView(APIView):\n    def get(self, request, *args, **kwargs):\n        return response.success('Any Type of Data')  // returning response to client.\n```\n### Bad Request 400\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 400\n\nFunction:\nresponse.bad_request('Username is required.')\n\n```\nclass MyView(APIView):\n    def get(self, request, *args, **kwargs):\n        return response.bad_request('Username is required.')  // returning response to client.\n```\n### Server Error 500\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 500\n\nFunction:\nresponse.server_error('Optional Message')\n\n```\nclass MyView(APIView):\n    def get(self, request, *args, **kwargs):\n        return response.server_error()  // returning response to client.\n```\n### No Data Found 200\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 200\n\nFunction:\nresponse.no_data_found()\n\n```\nclass MyView(APIView):\n    def get(self, request, *args, **kwargs):\n        return response.no_data_found()  // returning response to client.\n```\n### Parameter Missing 400\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 400\n\nFunction:\nresponse.param_missing(key, message)\n\n```\nclass MyView(APIView):\n    def get(self, request, *args, **kwargs):\n        return response.param_missing('username', 'This field is required.')  // returning response to client.\n```\n### Unauthorized 401\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 401\n\nFunction:\nresponse.unauthorized()\n\n```\nclass MyView(APIView):\n    def get(self, request, *args, **kwargs):\n        return response.unauthorized()  // returning response to client.\n```\n### Forbidden 403\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 403\n\nFunction:\nresponse.forbidden()\n\n```\nclass MyView(APIView):\n    def get(self, request, *args, **kwargs):\n        return response.forbidden()  // returning response to client.\n```\n### Method Not Allowed 405\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 405\n\nFunction:\nresponse.method_not_allowed()\n\n```\nclass MyView(APIView):\n    def get(self, request, *args, **kwargs):\n        return response.method_not_allowed()  // returning response to client.\n```\n### Not Acceptable 406\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 406\n\nFunction:\nresponse.not_acceptable()\n\n```\nclass MyView(APIView):\n    def get(self, request, *args, **kwargs):\n        return response.not_acceptable()  // returning response to client.\n```\n### Custom Error\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: User Specified\n\nFunction:\nresponse.custom_error(status_code: int, result)\n\n```\nclass MyView(APIView):\n    def get(self, request, *args, **kwargs):\n        return response.custom_error(status_code=200, result='Login Successful.')  // returning response to client.\n```\n\n## Exception functions\nNote: Returns application/json response. Can be used in API exceptions. for example in API authorization or permission classes.\n\nImport exceptions.\n```\nfrom general_methods import exceptions\n```\n### Server Exception 500\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 500\n```\nraise exceptions.ServerException()\n```\n### Unauthorized Exception 401\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 401\n```\nraise exceptions.UnauthorizedException()\n```\n### Session Expired Exception 401\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 401\n```\nraise exceptions.SessionExpiredException()\n```\n\n### Missing Header Exception 400\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 400\n```\nraise exceptions.MissingHeaderException()\n```\n\n### Blocked Client Exception 401\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 401\n```\nraise exceptions.BlockedClientException()\n```\n\n### Authentication Failed Exception 401\nReturns dictionary\n{\n    status: boolean,\n    message: str,\n    result: any\n}\n\nResponse code: 401\n```\nraise exceptions.AuthenticationFailedException()\n```\n\n## Validators functions\nCan be used in defining Models.\n\nImport validators.\n```\nfrom general_methods import validators\n```\n### Email Validator\nFunction: email_validator\n```\nclass MyModel(models.Model):\n    email = models.CharField(max_length=100, validators=[validators.email_validator])\n```\n### Mobile Number Validator (10 Length)\nFunction: mobile_number_validator\n```\nclass MyModel(models.Model):\n    mobile = models.CharField(max_length=15, validators=[validators.mobile_number_validator])\n```\n### Country Code Validator (Example: +91, +1 etc.)\nFunction: country_code_validator\n```\nclass MyModel(models.Model):\n    mobile = models.CharField(max_length=15, validators=[validators.country_code_validator])\n```\n### String with Space Validator [ a-zA-Z]\nFunction: string_with_space_validator\n```\nclass MyModel(models.Model):\n    mobile = models.CharField(max_length=15, validators=[validators.string_with_space_validator])\n```\n## Country Codes\nAll country codes are available.\n\nArray of Objects like:\n\n{\n    'country_code': \"IN\",\n    'calling_code': \"+91\",\n    'name': 'India (+91)'\n}\n\nImport country_codes.\n```\nfrom general_methods import country_codes\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvishalanandl177%2Fgeneral-methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvishalanandl177%2Fgeneral-methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvishalanandl177%2Fgeneral-methods/lists"}