
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
A Django app for patching `django.contrib.gis` to lazily load the GDAL library
A Django app that patches django.contrib.gis
to lazily load the GDAL library, functioning as a drop-in replacement that follows the same pattern used for the GEOS library.
Install the package from PyPI:
python -m pip install django-lazy-gdal
# or if you like the new hotness
uv add django-lazy-gdal
uv sync
Import and call the monkeypatch
function at the top of your Django project's settings module:
# settings.py - add these lines at the TOP of the file
import django_lazy_gdal
django_lazy_gdal.monkeypatch()
# ... rest of your settings file
[!IMPORTANT] Timing matters! It's crucial to call
django_lazy_gdal.monkeypatch()
before any GeoDjango modules are imported. This is because Django imports models, which in turn imports the existing eager GDAL loading via imports indjango.contrib.gis.models
, before running appready()
methods. Calling the monkeypatch function at the top of your settings ensures the patching occurs before any other imports that might accessdjango.contrib.gis.gdal.libgdal
.
django.contrib.gis.gdal.libgdal
module to use lazy loading.By default, Django's django.contrib.gis.gdal.libgdal
module loads the GDAL library immediately upon import, which can cause issues if GDAL isn't installed. In contrast, the GEOS library in django.contrib.gis.geos.libgeos
is lazily loaded using SimpleLazyObject
, meaning errors are deferred until GEOS is actually used.
This provides several benefits:
django.setup()
in projects using django.contrib.gis
without requiring GDAL installation, allowing for runtime interaction with non-GIS parts of the projectThis project originated from the need to work with GeoDjango projects without requiring GDAL to be installed locally. While developing django-language-server, I needed to set up Django to access information such as the template tags of the apps in INSTALLED_APPS
.
However, I encountered errors when testing the language server on a project that uses GeoDjango but relies on Docker containers for development, thus bypassing the need to install Geospatial libraries locally.
This library uses monkeypatching as a temporary solution to modify Django's behavior regarding GDAL loading. The goal is to test the viability of lazily loading GDAL before proposing these changes upstream to Django. Hopefully, in the future, this library can be deprecated if/when this functionality is integrated into Django itself.
django-lazy-gdal is licensed under the MIT license. See the LICENSE
file for more information.
FAQs
A Django app for patching `django.contrib.gis` to lazily load the GDAL library
We found that django-lazy-gdal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.