Skip to Content
CorePublic API

Public API and Lazy Imports

django_cfg has no separate registry module. Its public API is the explicit facade in django_cfg/__init__.py: a list of imports grouped by area, an __all__, and a small module-level __getattr__ for the few names that cannot be imported eagerly.

How It Works

Most public names are plain imports at the top of django_cfg/__init__.py:

from django_cfg import DjangoConfig, DatabaseConfig, CacheConfig from django_cfg import DjangoEmailService, send_email, send_telegram_message from django_cfg import ConfigurationError, ValidationError

Names that read Django settings at import time are resolved lazily on first access:

# django_cfg/__init__.py (shape) _LAZY_IMPORTS: dict[str, tuple[str, str]] = { "DefaultPagination": ("django_cfg.middleware.pagination", "DefaultPagination"), "ImportExportModelAdmin": ("django_cfg.modules.django_import_export", "ImportExportModelAdmin"), "check_python_version": ("django_cfg.utils.version_check", "check_python_version"), # ... } def __getattr__(name: str): if name in _LAZY_IMPORTS: module_path, class_name = _LAZY_IMPORTS[name] import importlib return getattr(importlib.import_module(module_path), class_name) raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

The lazy set is: the DRF pagination classes (DefaultPagination, LargePagination, SmallPagination, NoPagination), the django_import_export classes (ImportForm, ExportForm, SelectableFieldsExportForm, ImportExportMixin, ImportExportModelAdmin, ExportMixin, ImportMixin, BaseResource) and check_python_version. They import Django models or read REST_FRAMEWORK, which fails before django.setup().

Public Names by Area

AreaNames
CoreDjangoConfig, StartupInfoMode, set_current_config, add_django_cfg_urls, get_django_cfg_urls_info, admin_urlpatterns
ExceptionsDjangoCfgException, ConfigurationError, ValidationError, DatabaseError, CacheError, EnvironmentError
InfrastructureDatabaseConfig, CacheConfig, SecurityConfig, LoggingConfig
APIDRFConfig, SpectacularConfig, JWTConfig, OAuthConfig, GitHubOAuthConfig, GoogleOAuthConfig, LimitsConfig, ApiKeys, TwoFactorConfig, AccountEmailsConfig
Django modelsEnvironmentConfig, AxesConfig, DjangoRQConfig, RQQueueConfig, RQScheduleConfig, CurrencyConfig, PaymentsConfig, GeoConfig, StorageConfig, S3StorageConfig, ConstanceConfig, OpenAPIClientConfig, Site, SiteConfig and others
ServicesEmailConfig, TelegramConfig, NotionConfig, DjangoEmailService, send_email, DjangoTelegram, send_telegram_message, send_telegram_photo
AdminAdminConfig, FieldConfig, FieldsetConfig, ActionConfig, WidgetRegistry, Icons, IconCategories
Admin siteAdminSiteConfig, AdminSidebar, NavigationItem, NavigationSection, NavigationItemType, SiteDropdownItem
MCPDjangoMCPModuleConfig, MCPConfigBuilder, MCPProfile and the MCP_* helpers
TestingSmartTestRunner, FastTestRunner

The complete list is django_cfg.__all__:

import django_cfg print(django_cfg.__all__)

Guarding the API

  • tests/test_public_api.py compares django_cfg.__all__ with tests/public_api_snapshot.json, so a removed name fails the test.
  • tests/test_import_budget.py measures import django_cfg in a clean subprocess: a ceiling on loaded django_cfg modules, and heavy packages (openai, boto3, pandas, …) that must stay unloaded.

See System Architecture for the layering contracts.

Best Practices

Import what you need

from django_cfg import DjangoConfig, DatabaseConfig # good from django_cfg import * # avoid: pulls the whole facade

Optional dependencies

MCP names are None when the MCP optional dependency is missing:

from django_cfg import DjangoMCPModuleConfig if DjangoMCPModuleConfig is None: ... # the MCP dependency is not installed

Import modules by their own path when a name is not in the facade

Not every class is re-exported. Import it from its module:

from django_cfg.modules.django_admin.base import PydanticAdmin from django_cfg.modules.django_currency.widgets import MoneyFieldWidget
Last updated on