{"id":27211,"library":"optional-django","title":"optional-django","description":"Utilities for providing optional support for Django in Python packages, allowing conditional feature loading depending on whether Django is installed. Version 0.3.0 appears to be the latest; release cadence is low (last release years ago).","status":"active","version":"0.3.0","language":"python","source_language":"en","source_url":"https://github.com/markfinger/optional-django","tags":["django","optional","conditional","utilities"],"install":[{"cmd":"pip install optional-django","lang":"bash","label":"default install"}],"dependencies":[],"imports":[{"note":"Users often expect Django-like submodules; the main module is at the top level.","wrong":"from optional_django.models import ...","symbol":"optional_django","correct":"import optional_django"}],"quickstart":{"code":"import optional_django\n\n# Check if Django is available\nprint(optional_django.is_available())  # True or False\n\n# Conditionally import Django models\nif optional_django.is_available():\n    from django.db import models\n    print('Django models available')","lang":"python","description":"Basic usage: check availability and conditionally import Django components."},"warnings":[{"fix":"Use pkg_resources or importlib.metadata to check Django version independently.","message":"The library only checks whether Django is installed, not a specific version. If your package requires a minimum Django version, you must check separately.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider using try/except ImportError blocks instead of this library for simplicity.","message":"The library has not been updated in years and may not work with modern Django versions (e.g., 4.x, 5.x). Verify compatibility in your environment.","severity":"deprecated","affected_versions":">=0.3.0"},{"fix":"Use extras_require in setup.py/setup.cfg to keep Django optional.","message":"Using this library does not prevent Django from being a top-level dependency. You still need to package Django in extras_require if you want optional support.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'pip install optional-django'.","cause":"Library not installed.","error":"ImportError: No module named optional_django"},{"fix":"Upgrade to version 0.3.0: 'pip install --upgrade optional-django'.","cause":"Using an older version of the library.","error":"AttributeError: module 'optional_django' has no attribute 'is_available'"},{"fix":"Call 'django.setup()' or set the DJANGO_SETTINGS_MODULE environment variable before using Django.","cause":"Trying to use Django features without setting up Django settings.","error":"django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}