Registry / web-framework / djangorestframework-gis

djangorestframework-gis

JSON →
library1.2.1pypypiunverified

Django REST Framework GIS (DRF-GIS) provides geographic add-ons for Django Rest Framework, enabling the creation of REST APIs for geospatial data. It offers GIS-specific fields and serializers, including GeoJSON support. The current version is 1.2.0. Releases are somewhat irregular, with major updates typically annually, and minor versions released as needed.

pip install djangorestframework-gis
INSTALL
IMPORT
SIG · DJANGORESTFRAMEWOR
D
djangorestframework-gis
web-frameworkpythonv1.2.1
Install
2.7s avg
Import
Disk
74MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 0.000s · 77.4MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 2.7s · import 0.000s · 72MB
74MB installed
● package 74MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GeometryField
from rest_framework_gis.fields import GeometryField
from rest_framework_gis import GeometryField

This quickstart illustrates a basic Django model with a GIS `PointField`, a `GeoFeatureModelSerializer` to output GeoJSON, and a DRF `ListCreateAPIView`. It shows the essential components needed to expose geospatial data via a REST API. Note that this requires a properly configured Django project with `django.contrib.gis` and a spatial database (e.g., PostGIS) backend. The Django setup within the snippet makes it runnable as a standalone script for component definition check.

import os import django from django.conf import settings from django.db import models from django.contrib.gis.db import models as gis_models from rest_framework_gis.serializers import GeoFeatureModelSerializer from rest_framework.generics import ListCreateAPIView # --- Minimal Django setup for demonstration --- # In a real Django project, these would be in settings.py, models.py, views.py, urls.py if not settings.configured: settings.configure( INSTALLED_APPS=[ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.gis', # Essential for DRF-GIS 'rest_framework', 'rest_framework_gis', 'myapp' # Placeholder for our app, add it to INSTALLED_APPS ], DATABASES={ 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': 'mydatabase_test', 'USER': os.environ.get('DB_USER', 'postgres'), 'PASSWORD': os.environ.get('DB_PASSWORD', ''), 'HOST': os.environ.get('DB_HOST', 'localhost'), 'PORT': os.environ.get('DB_PORT', '5432'), } }, SECRET_KEY=os.environ.get('DJANGO_SECRET_KEY', 'a-very-secret-key-for-dev-and-testing'), ROOT_URLCONF='__main__', USE_TZ=True, TIME_ZONE='UTC', STATIC_URL='/static/' ) django.setup() # --- Example Model (myapp/models.py) --- # Define a custom AppConfig for 'myapp' if needed, or simply ensure 'myapp' is in INSTALLED_APPS # and Django can find your models. class Place(gis_models.Model): name = models.CharField(max_length=100) location = gis_models.PointField(srid=4326) # WGS84 latitude/longitude def __str__(self): return self.name class Meta: app_label = 'myapp' # Required for models defined outside an app directory # --- Example Serializer (myapp/serializers.py) --- class PlaceSerializer(GeoFeatureModelSerializer): class Meta: model = Place geo_field = 'location' fields = ('id', 'name', 'location') # --- Example View (myapp/views.py) --- class PlaceListCreateAPIView(ListCreateAPIView): queryset = Place.objects.all() serializer_class = PlaceSerializer # --- Example URLs (project_root/urls.py or myapp/urls.py) --- # from django.urls import path # from myapp.views import PlaceListCreateAPIView # # urlpatterns = [ # path('api/places/', PlaceListCreateAPIView.as_view(), name='place-list-create'), # ] # This block checks if the components are defined. In a real project, # you would configure URLs and run the Django development server. assert issubclass(PlaceSerializer, GeoFeatureModelSerializer) assert issubclass(PlaceListCreateAPIView, ListCreateAPIView) print("DRF-GIS model, serializer, and view components defined successfully.")
Debug
Known issues
breakingVersion 1.1.0 dropped support for Python versions 3.6, 3.7 and Django versions 2.2, 3.0, 3.1, 4.0. It also dropped support for `djangorestframework < 3.12`.
fix
Upgrade Python to 3.8+ (3.13+ recommended), Django to 4.2+ (5.2+ recommended), and Django REST Framework to 3.12+ (3.16.0+ recommended).
affects: >=1.1.0
breakingVersion 0.14.0 introduced a dependency on `django-filters >= 2.0`, which itself requires Python >= 3.4. Ensure your Python version meets this requirement if using filtering.
fix
Upgrade Python to 3.4+ (see main breaking change for recommended versions) and `django-filters` to 2.0+.
affects: >=0.14.0
gotchaPrior to version 1.0.0, Django versions >= 3.2 would raise a `default_app_config` deprecation warning when using `djangorestframework-gis`.
fix
Upgrade `djangorestframework-gis` to version 1.0.0 or higher to resolve the `default_app_config` deprecation warning.
affects: <1.0.0
gotchaBefore version 0.16.0, passing additional arguments via `style` to `GeometryField` might have been unintentionally overridden. This was fixed to allow proper customization.
fix
If you relied on `GeometryField`'s `style` argument, upgrade to version 0.16.0 or higher to ensure custom styles are applied correctly without being overridden.
affects: <0.16.0
gotchaPrior to version 0.16.0, `djangorestframework-gis` had issues with the representation of empty geometries, potentially leading to errors or incorrect output.
fix
Upgrade `djangorestframework-gis` to version 0.16.0 or higher to correctly handle and represent empty geometries in your API responses.
affects: <0.16.0
gotchaThe deserialization of the `id_field` was fixed in version 1.0.0. If you experienced issues with `id_field` during deserialization (e.g., when creating or updating objects), this might have been the cause.
fix
Upgrade `djangorestframework-gis` to version 1.0.0 or higher to ensure correct deserialization of the `id_field`.
affects: <1.0.0
gotchaFor `GeoFeatureModelSerializer` to correctly handle models without a geometry field, you must be using version 1.1.0 or higher.
fix
Upgrade `djangorestframework-gis` to version 1.1.0 or higher if you need to serialize models that may or may not have a geometry field.
affects: <1.1.0
Upgrade
Version history
1.2.1latest on PyPI · released May 4, 2026
Audit
Dependencies
djangorequiredCore Django framework, requires Django 4.2+, 5.0+, 5.1+, 5.2+.
djangorestframeworkrequiredCore DRF framework, requires DRF 3.12+ (3.16.0+ recommended).
django-filteroptionalUsed for advanced filtering features, requires django-filter >= 2.0.
psycopg2-binaryoptionalPython adapter for PostgreSQL with PostGIS extension. Highly recommended for spatial databases.
Agent activity
19 hits · last 30 days
node
18
Resources
djangorestframework-gis — pip install djangorestframework-gis · libregistry