{"id":20793713,"url":"https://github.com/anexia/drf-ip-restrictions","last_synced_at":"2025-05-05T23:43:20.285Z","repository":{"id":62592520,"uuid":"506135509","full_name":"anexia/drf-ip-restrictions","owner":"anexia","description":"A library that allows IP restrictions for views/endpoints in Django REST framework.","archived":false,"fork":false,"pushed_at":"2024-11-05T13:19:01.000Z","size":18,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-13T21:16:26.290Z","etag":null,"topics":["django","django-rest-framework","drf"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anexia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-22T07:05:44.000Z","updated_at":"2025-01-09T02:26:19.000Z","dependencies_parsed_at":"2022-11-03T23:00:14.550Z","dependency_job_id":null,"html_url":"https://github.com/anexia/drf-ip-restrictions","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anexia%2Fdrf-ip-restrictions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anexia%2Fdrf-ip-restrictions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anexia%2Fdrf-ip-restrictions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anexia%2Fdrf-ip-restrictions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anexia","download_url":"https://codeload.github.com/anexia/drf-ip-restrictions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252596320,"owners_count":21773842,"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","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","django-rest-framework","drf"],"created_at":"2024-11-17T16:11:07.722Z","updated_at":"2025-05-05T23:43:20.259Z","avatar_url":"https://github.com/anexia.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DRF IP Restrictions\n\n[![PyPI version](https://img.shields.io/pypi/v/drf-ip-restrictions.svg)](https://pypi.org/project/drf-ip-restrictions/)\n[![Run linter and tests](https://github.com/anexia/drf-ip-restrictions/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/anexia/drf-ip-restrictions/actions/workflows/test.yml)\n[![Codecov](https://img.shields.io/codecov/c/gh/anexia/drf-ip-restrictions)](https://codecov.io/gh/anexia/drf-ip-restrictions)\n\nA library that allows IP restrictions for views/endpoints in Django REST framework.\n\n## Installation\n\n1. Install using pip:\n\n```sh\npip install drf-ip-restrictions\n```\n\n2. Add the library to your INSTALLED_APPS list.\n\n```python\nINSTALLED_APPS = [\n    ...\n    'drf_ip_restrictions',\n    ...\n]\n```\n\n4. Override the allowed IP addresses your `settings.py` according to your needs:\n\n```python\n# within settings.py\n\nDRF_IP_RESTRICTION_SETTINGS = {\n    \"ALLOWED_IP_LIST\": [\"127.0.0.1\"],\n}\n```\n\n## Usage\n\nAdd the AllowedIpList class to any views / endpoints that should only provide access for the \nconfigured IP addresses, e.g. to restrict a view set:\n\n```python\n# within views.py\n\nclass MyViewSet(viewsets.ModelViewSet):\n    permission_classes = (AllowedIpList,)\n    ...\n```\n\nor to restrict only a single action:\n\n```python\n# within views.py\n\nclass MyViewSet(viewsets.ModelViewSet):\n    ...\n    \n    @action(\n        detail=False,\n        methods=[\"get\"],\n        http_method_names=[\"get\"],\n        authentication_classes=[],\n        permission_classes=[AllowedIpList],  # \u003c-- this is the important part for IP restrictions to work\n        url_path=r\"my-method\",\n    )\n    def my_method(self, request, *args, **kwargs):\n        # do stuff and return rest_framework.response.Response in the end\n```\n\n## Django Compatibility Matrix\n\nIf your project uses an older verison of Django or Django Rest Framework, you can choose an older version of this project.\n\n| This Project | Python Version              | Django Version | Django Rest Framework  |\n|--------------|-----------------------------|----------------|------------------------|\n| 1.1.*        | 3.9, 3.10, 3.11, 3.12. 3.13 | 4.2, 5.0, 5.1  | 3.12, 3.13, 3.14, 3.15 |\n| 1.0.*        | 3.7, 3.8, 3.9, 3.10         | 3.2, 4.0       | 3.12, 3.13             |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanexia%2Fdrf-ip-restrictions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanexia%2Fdrf-ip-restrictions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanexia%2Fdrf-ip-restrictions/lists"}