DRF IP Restrictions
A library that allows IP restrictions for views/endpoints in Django REST framework.
Installation
- Install using pip:
pip install drf-ip-restrictions
- Add the library to your INSTALLED_APPS list.
INSTALLED_APPS = [
...
'drf_ip_restrictions',
...
]
- Override the allowed IP addresses your
settings.pyaccording to your needs:
# within settings.py
DRF_IP_RESTRICTION_SETTINGS = {
"ALLOWED_IP_LIST": ["127.0.0.1"],
}
Usage
Add the AllowedIpList class to any views / endpoints that should only provide access for the configured IP addresses, e.g. to restrict a view set:
# within views.py
class MyViewSet(viewsets.ModelViewSet):
permission_classes = (AllowedIpList,)
...
or to restrict only a single action:
# within views.py
class MyViewSet(viewsets.ModelViewSet):
...
@action(
detail=False,
methods=["get"],
http_method_names=["get"],
authentication_classes=[],
permission_classes=[AllowedIpList], # <-- this is the important part for IP restrictions to work
url_path=r"my-method",
)
def my_method(self, request, *args, **kwargs):
# do stuff and return rest_framework.response.Response in the end
Django Compatibility Matrix
If your project uses an older verison of Django or Django Rest Framework, you can choose an older version of this project.
| This Project | Python Version | Django Version | Django Rest Framework |
|---|---|---|---|
| 1.0.* | 3.7, 3.8, 3.9, 3.10 | 3.2, 4.0 | 3.12, 3.13 |
Metadata
Release files for drf-ip-restrictions 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| drf-ip-restrictions-1.1.1.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| drf_ip_restrictions-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / drf-ip-restrictions-1.1.1.tar.gz
| Download URL | drf-ip-restrictions-1.1.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
44e8c3a0d7874ee283fde3c5e06b73614e784b40ff57b9a75b5c2415824c2e7c
|
|
BLAKE2b-256 checksum How to use checksums |
4d1c6e5d9a04acf51b36f287836b8e88dc69febf6251b319441eaeae96682e96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Release files / drf_ip_restrictions-1.1.1-py3-none-any.whl
| Download URL | drf_ip_restrictions-1.1.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
842700c9deb33aede18ff5432c0e27508a9f9732a71ff11bf284c55e867bf1f2
|
|
BLAKE2b-256 checksum How to use checksums |
d42b1787c6ec180b4484bbc240f6d5627ca5cba11576d67e390c9c2c2f0c996b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|