Smarter Waffle

Smarter’s feature switches are defined in SmarterWaffleSwitches, and created, with their defaults, by manage.py initialize_waffle. Among them, two widen how plugin selectors match their search terms: enable_plugin_fuzzy_matching, on by default, tolerates typos, and enable_plugin_thesaurus_matching, on by default, matches synonyms from the WordNet thesaurus. See Natural Language Processing.

A managed wrapper of django-waffle, with short-lived caching and database readiness checks.

Features:

  • Caching: each process remembers a switch’s state for a few seconds, on top of waffle’s own Redis cache.

  • Database Readiness Handling: Implements safeguards to prevent errors when the database is not ready.

  • Feature Flag Management: Centralized mechanism to check if a feature flag (switch) is active.

  • Custom Django Admin: Customized Django Admin class for managing waffle switches.

  • Fixed Set of Switches: Defines a fixed set of waffle switches for the Smarter API.

Important

These are managed feature flags; add any new switches to the SmarterWaffleSwitches class. These switches are verified during deployments to ensure that they exist in the database. A switch that is checked before it exists is created with its default from SmarterWaffleSwitches.

Important

django-waffle relies on database tables as well as Redis for storing and caching feature flags. If the database is not ready, waffle switch values will default to inactive (False) to prevent application errors.

Example

from smarter.lib.django.waffle import SmarterWaffleSwitches, switch_is_active

if switch_is_active(SmarterWaffleSwitches.ACCOUNT_LOGGING):
    print("Account logging is enabled.")

Dependencies:

class smarter.lib.django.waffle.SmarterWaffleSwitch(name, comment, default)[source]

Bases: object

The definition of one managed waffle switch: its name, its admin comment, and its default state.

__init__(name, comment, default)
comment: str
default: bool
name: str
to_json()[source]

Return the switch’s name, comment and default as a dict.

Return type:

dict[str, str | bool]

class smarter.lib.django.waffle.SmarterWaffleSwitches[source]

Bases: object

Enumerated data type for predefined, managed Smarter waffle switches.

This class defines the fixed set of feature flags (Waffle switches) used by the Smarter Platform. Each class attribute represents a unique, centrally managed switch. These switches are automatically verified and created (if missing) during deployments, ensuring consistency and preventing runtime errors due to missing flags.

Note

Only switches defined in this class are considered valid for use in the Smarter codebase. To add a new feature flag, declare it as a class attribute here.

Example

from smarter.lib.django.waffle import SmarterWaffleSwitches, switch_is_active

if switch_is_active(SmarterWaffleSwitches.API_LOGGING):
    print("API logging is enabled.")
ACCOUNT_LOGGING = 'log_account'

Enables logging throughout the smarter.app.account namespace.

ACCOUNT_MIXIN_LOGGING = 'log_account_mixin'

Enables logging within the smarter.apps.account.mixins.AccountMixin class.

ALLOW_API_GET = 'allow_api_get'

Allows GET requests to the API endpoints, which are normally restricted to POST requests.

API_LOGGING = 'log_api'

Enables logging throughout the smarter.api namespace.

CACHE_LOGGING = 'log_caching'

Enables detailed logging for caching operations including cache hits, misses, and errors.

CHATAPP_LOGGING = 'log_chatapp'

For the React Prompt UI component.

Enables debug-level javascript console logging inside the browser

CONNECTION_LOGGING = 'log_connection'

Enables logging throughout the smarter.app.connection namespace.

CSRF_SUPPRESS_FOR_LLM_CLIENTS = 'disable_csrf_middleware_for_llmclients'

Disables CSRF middleware checks for prompt completion endpoints.

DOODLE_LOGGING = 'log_doodle'

Enables logging throughout the smarter.app.doodle namespace.

ENABLE_ACCOUNT_REGISTRATION = 'enable_account_registration'

Enables account registration link.

ENABLE_DEBUG_MODE = 'enable_debug_mode'

Enables debug mode for the entire Smarter application, which may include additional logging and diagnostic information.

ENABLE_DOODLE = 'enable_doodle'

Enables the Doodle, the sign-in page’s illustration of the day.

Inactive, the page shows the plain base scene.

ENABLE_DOODLE_AI_CREDIT = 'enable_doodle_ai_credit'

Enables the credit below a doodle that a Smarter AI application chose or drew, in place of the project’s description.

ENABLE_DOODLE_ANIMATION = 'enable_doodle_animation'

Enables the Doodle’s animations.

Inactive, every doodle is a still image.

ENABLE_DOODLE_AUTO_APPROVE = 'enable_doodle_auto_approve'

Shows a doodle that the Smarter Doodle Artist drew without a superuser’s approval in the admin.

ENABLE_DOODLE_CAPTION = 'enable_doodle_caption'

Enables the caption below a themed Doodle, e.g. Happy Diwali!, and its link.

ENABLE_DOODLE_LLM_ARTWORK = 'enable_doodle_llm_artwork'

Lets the Smarter Doodle Editor choose a holiday that the catalog has no theme for, which the Smarter Doodle Artist draws.

ENABLE_DOODLE_LLM_EDITOR = 'enable_doodle_llm_editor'

Lets the Smarter Doodle Editor, an LLMClient, choose each region’s doodle of each new day.

ENABLE_DOODLE_REGIONAL = 'enable_doodle_regional'

Enables regional doodles, by the browser’s time zone.

Inactive, every visitor sees the global doodle.

Tells the Smarter Doodle Editor what each region is reading about on Wikipedia, for today and tomorrow.

ENABLE_FORMATTED_LOGGING = 'enable_formatted_logging'

Enables formatted logging with ANSI color codes for enhanced readability in logs.

ENABLE_JOURNAL = 'enable_journal'

Enables the Smarter Journal feature.

ENABLE_LLMCLIENT_ENDPOINTS_PAGE = 'llmclient_enable_endpoints_page'

Enables the page that a browser receives from a GET of a deployed LLMClient’s endpoints.

ENABLE_LLM_PRICE_CHECKER = 'enable_llm_price_checker'

Lets the Smarter LLM Price Checker, an LLMClient, update the LLM prices every week from the providers’ pricing pages.

Enables additional links in the login page footer, such as ‘Legal’ and ‘Contact’.

ENABLE_MIDDLEWARE_CORS = 'enable_middleware_cors'

Enables SmarterCorsMiddleware.

ENABLE_MIDDLEWARE_CSRF = 'enable_middleware_csrf'

Enables Django’s built-in CSRF middleware for enhanced security against cross-site request forgery attacks.

ENABLE_MIDDLEWARE_EXCESSIVE_404 = 'enable_middleware_block_excessive_404'

Enables SmarterBlockExcessive404Middleware.

ENABLE_MIDDLEWARE_HTML_MINIFY = 'enable_middleware_html_minify'

Enables HTML minification for responses with ‘text/html’ content type using BeautifulSoup, while skipping minification for certain paths and content types to avoid issues with non-HTML responses.

ENABLE_MIDDLEWARE_SECURITY = 'enable_middleware_security'

Enables SmarterSecurityMiddleware.

ENABLE_MIDDLEWARE_SENSITIVE_FILES = 'enable_middleware_block_sensitive_files'

Enables SmarterBlockSensitiveFilesMiddleware.

ENABLE_MIDDLEWARE_SMARTER_JSON_ERROR = 'enable_middleware_smarter_json_error'

Enables SmarterJsonErrorMiddleware, which converts error responses to JSON format when the client expects JSON.

ENABLE_MIDDLEWARE_SMARTER_TOKEN_AUTH = 'enable_middleware_smarter_token_auth'

Enables SmarterTokenAuthenticationMiddleware, which provides token-based authentication for API endpoints.

ENABLE_MULTITENANT_AUTHENTICATION = 'enable_multitenant_authentication'

Enables multi-tenant authentication support for hosted Smarter platforms.

ENABLE_NEW_USER_PASSWORD_EMAIL = 'enable_new_user_password_email'

Enables sending textemail with password to new users.

ENABLE_OAUTH2 = 'enable_oauth2'

Enables OAuth2 authentication support.

ENABLE_PLUGIN_FUZZY_MATCHING = 'enable_plugin_fuzzy_matching'

Enables typo tolerant (Levenshtein distance) matching of plugin selector search terms.

ENABLE_PLUGIN_THESAURUS_MATCHING = 'enable_plugin_thesaurus_matching'

Enables synonym (WordNet thesaurus) matching of plugin selector search terms.

ENABLE_REACTAPP_DEBUG_MODE = 'enable_reactapp_debug_mode'

Enables React app debug mode within the Smarter React Prompt component.

ENABLE_SLACK_INVITATION_EMAIL = 'enable_slack_invitation_email'

Enables the Celery Beat task that invites account contacts to the Slack workspace, two days after their welcome email.

ENABLE_SMARTER_PAGE_CACHING = 'enable_smarter_page_caching'

Enables the Smarter user-based page caching decorator for user-facing pages to improve performance.

ENABLE_WEB_CONSOLE_DID_YOU_KNOW = 'enable_web_console_did_you_know'

Enables the Did you know? note, a fact of the day about The Smarter Project, below the web console’s title.

ENABLE_WEB_CONSOLE_ONBOARDING_HINTS = 'enable_web_console_onboarding_hints'

Enables the onboarding hints, which point a new user from the sidebar to the Get Weather LLMClient, and the workbench’s guided tour.

ENABLE_WEB_CONSOLE_SERVER_LOGS = 'enable_web_console_server_logs'

Enables SmarterRequestLogContextMiddleware, which adds request-specific context to log records for enhanced logging capabilities.

EXTENSION_LOGGING = 'log_extension'

Enables logging within the smarter.apps.llmtool.extension namespace.

GUARDRAIL_LOGGING = 'log_guardrail'

Enables logging throughout the smarter.app.guardrail namespace.

INFRASTRUCTURE_LOGGING = 'log_infrastructure'

Enables logging throughout the smarter.app.infrastructure namespace.

LLM_CLIENT_HELPER_LOGGING = 'log_llmclienthelper'

Enables logging within the smarter.apps.llmclient.model.LLMClientHelper class.

LLM_CLIENT_LOGGING = 'log_llmclient'

Enables logging throughout the smarter.app.llmclient namespace.

LLM_HOST_LOGGING = 'log_llm_host'

Enables logging throughout the smarter.app.llmhost namespace.

MANIFEST_LOGGING = 'log_manifest_brokers'

Enables detailed diagnostic logging for manifest initialization, validation and brokered operations.

MCPCLIENT_LOGGING = 'log_mcpclient'

Enables logging within the smarter.apps.mcpclient namespace.

MCPSERVER_LOGGING = 'log_mcpserver'

Enables logging within the smarter.apps.mcpserver namespace.

MIDDLEWARE_LOGGING = 'log_middleware'

Enables detailed diagnostic logging for all middleware operations.

ORCHESTRATOR = 'log_orchestrator'

Enables logging within the smarter.apps.orchestror namespace.

PLUGIN_LOGGING = 'log_plugin'

Enables logging throughout the smarter.app.plugin namespace.

PROMPT_LOGGING = 'log_prompt'

Enables logging throughout the smarter.app.prompt namespace.

PROVIDER_LOGGING = 'log_provider'

Enables logging throughout the smarter.app.provider namespace.

PROXY_LOGGING = 'log_proxy'

Enables logging throughout the smarter.app.proxy namespace.

RECEIVER_LOGGING = 'log_receivers'

Enables logging in all Django signal receivers throughout the Smarter codebase.

REQUEST_MIXIN_LOGGING = 'log_request_mixin'

Enables detailed diagnostic logging for the SmarterRequestMixin class.

SECRET_LOGGING = 'log_secret'

Enables logging throughout the smarter.app.secret namespace.

TASK_LOGGING = 'log_tasks'

Enables logging in all Celery tasks throughout the Smarter codebase.

VALIDATOR_LOGGING = 'log_validators'

Enables logging in all Django model field validators throughout the Smarter codebase.

VECTORSEARCH_LOGGING = 'log_vectorsearch'

Enables logging throughout the smarter.app.vectorsearch namespace.

VECTORSTORE_LOGGING = 'log_vectorstore'

Enables logging throughout the smarter.app.vectorstore namespace.

VIEW_LOGGING = 'log_views'

Enables logging in all Django views throughout the Smarter codebase.

property all: list[str]

Return every switch’s name.

Returns:

The names of the switches, i.e. the values of the upper-case string attributes, in the sorted order of the attributes.

property all_set: frozenset[str]

Return every switch’s name, as a set.

switch_is_active() tests membership in it on every check of a switch, which a set answers without scanning a list.

Returns:

The names of the switches.

switches = {'allow_api_get': SmarterWaffleSwitch(name='allow_api_get', comment='Allows GET requests to the API endpoints, which are normally restricted to POST requests.', default=False), 'disable_csrf_middleware_for_llmclients': SmarterWaffleSwitch(name='disable_csrf_middleware_for_llmclients', comment='Disables CSRF middleware checks for prompt completion endpoints.', default=False), 'enable_account_registration': SmarterWaffleSwitch(name='enable_account_registration', comment='Enables account registration link.', default=False), 'enable_debug_mode': SmarterWaffleSwitch(name='enable_debug_mode', comment='Enables debug mode for the entire Smarter application, which may include additional logging and diagnostic information.', default=False), 'enable_doodle': SmarterWaffleSwitch(name='enable_doodle', comment="Enables the Doodle, the sign-in page's illustration of the day. Inactive, the page shows the plain base scene.", default=True), 'enable_doodle_ai_credit': SmarterWaffleSwitch(name='enable_doodle_ai_credit', comment="Enables the credit below a doodle that a Smarter AI application chose or drew, in place of the project's description.", default=True), 'enable_doodle_animation': SmarterWaffleSwitch(name='enable_doodle_animation', comment="Enables the Doodle's animations. Inactive, every doodle is a still image.", default=True), 'enable_doodle_auto_approve': SmarterWaffleSwitch(name='enable_doodle_auto_approve', comment="Shows a doodle that the Smarter Doodle Artist drew without a superuser's approval in the admin.", default=False), 'enable_doodle_caption': SmarterWaffleSwitch(name='enable_doodle_caption', comment='Enables the caption below a themed Doodle, e.g. Happy Diwali!, and its link.', default=True), 'enable_doodle_llm_artwork': SmarterWaffleSwitch(name='enable_doodle_llm_artwork', comment='Lets the Smarter Doodle Editor choose a holiday that the catalog has no theme for, which the Smarter Doodle Artist draws.', default=True), 'enable_doodle_llm_editor': SmarterWaffleSwitch(name='enable_doodle_llm_editor', comment="Lets the Smarter Doodle Editor, an LLMClient, choose each region's doodle of each new day.", default=True), 'enable_doodle_regional': SmarterWaffleSwitch(name='enable_doodle_regional', comment="Enables regional doodles, by the browser's time zone. Inactive, every visitor sees the global doodle.", default=True), 'enable_doodle_trends': SmarterWaffleSwitch(name='enable_doodle_trends', comment='Tells the Smarter Doodle Editor what each region is reading about on Wikipedia, for today and tomorrow.', default=True), 'enable_formatted_logging': SmarterWaffleSwitch(name='enable_formatted_logging', comment='Enables formatted logging with ANSI color codes for enhanced readability in logs.', default=True), 'enable_journal': SmarterWaffleSwitch(name='enable_journal', comment='Enables the Smarter Journal feature, the audit trail of every api command and prompt. On by default, so that a new platform keeps one from the start.', default=True), 'enable_llm_price_checker': SmarterWaffleSwitch(name='enable_llm_price_checker', comment="Lets the Smarter LLM Price Checker, an LLMClient, update the LLM prices every week from the providers' pricing pages. A price that a person set is never changed.", default=True), 'enable_login_footer_links': SmarterWaffleSwitch(name='enable_login_footer_links', comment="Enables additional links in the login page footer, such as 'Legal' and 'Contact'.", default=False), 'enable_middleware_block_excessive_404': SmarterWaffleSwitch(name='enable_middleware_block_excessive_404', comment='Enables SmarterBlockExcessive404Middleware', default=True), 'enable_middleware_block_sensitive_files': SmarterWaffleSwitch(name='enable_middleware_block_sensitive_files', comment='Enables SmarterBlockSensitiveFilesMiddleware', default=True), 'enable_middleware_cors': SmarterWaffleSwitch(name='enable_middleware_cors', comment='Enables SmarterCorsMiddleware', default=True), 'enable_middleware_csrf': SmarterWaffleSwitch(name='enable_middleware_csrf', comment="Enables Django's built-in CSRF middleware for enhanced security against cross-site request forgery attacks.", default=True), 'enable_middleware_html_minify': SmarterWaffleSwitch(name='enable_middleware_html_minify', comment="Enables HTML minification for responses with 'text/html' content type using BeautifulSoup, while skipping minification for certain paths and content types to avoid issues with non-HTML responses.", default=True), 'enable_middleware_security': SmarterWaffleSwitch(name='enable_middleware_security', comment='Enables SmarterSecurityMiddleware', default=True), 'enable_middleware_smarter_json_error': SmarterWaffleSwitch(name='enable_middleware_smarter_json_error', comment='Enables SmarterJsonErrorMiddleware, which converts error responses to JSON format when the client expects JSON.', default=True), 'enable_middleware_smarter_token_auth': SmarterWaffleSwitch(name='enable_middleware_smarter_token_auth', comment='Enables SmarterTokenAuthenticationMiddleware, which provides token-based authentication for API endpoints.', default=True), 'enable_multitenant_authentication': SmarterWaffleSwitch(name='enable_multitenant_authentication', comment='Enables multi-tenant authentication support for hosted Smarter platforms.', default=False), 'enable_new_user_password_email': SmarterWaffleSwitch(name='enable_new_user_password_email', comment='Enables sending textemail with password to new users.', default=False), 'enable_oauth2': SmarterWaffleSwitch(name='enable_oauth2', comment='Enables OAuth2 authentication support.', default=False), 'enable_plugin_fuzzy_matching': SmarterWaffleSwitch(name='enable_plugin_fuzzy_matching', comment='Enables typo tolerant (Levenshtein distance) matching of plugin selector search terms.', default=True), 'enable_plugin_thesaurus_matching': SmarterWaffleSwitch(name='enable_plugin_thesaurus_matching', comment='Enables synonym (WordNet thesaurus) matching of plugin selector search terms.', default=True), 'enable_reactapp_debug_mode': SmarterWaffleSwitch(name='enable_reactapp_debug_mode', comment='Enables React app debug mode within the Smarter React Prompt component.', default=False), 'enable_slack_invitation_email': SmarterWaffleSwitch(name='enable_slack_invitation_email', comment='Enables the Celery Beat task that invites account contacts to the Slack workspace, two days after their welcome email.', default=False), 'enable_smarter_page_caching': SmarterWaffleSwitch(name='enable_smarter_page_caching', comment='Enables the Smarter user-based page caching decorator for user-facing pages to improve performance.', default=True), 'enable_web_console_did_you_know': SmarterWaffleSwitch(name='enable_web_console_did_you_know', comment="Enables the Did you know? note, a fact of the day about The Smarter Project, below the web console's title.", default=True), 'enable_web_console_onboarding_hints': SmarterWaffleSwitch(name='enable_web_console_onboarding_hints', comment="Enables the onboarding hints, which point a new user from the sidebar to the Get Weather LLMClient, and the workbench's guided tour.", default=True), 'enable_web_console_server_logs': SmarterWaffleSwitch(name='enable_web_console_server_logs', comment='Enables SmarterRequestLogContextMiddleware, which adds request-specific context to log records for enhanced logging capabilities.', default=True), 'llmclient_enable_endpoints_page': SmarterWaffleSwitch(name='llmclient_enable_endpoints_page', comment="Enables the page that a browser receives from a GET of a deployed LLMClient's endpoints: its curl commands, its manifest and The Smarter Project. Inactive, a GET is the api's, a 405.", default=False), 'log_account': SmarterWaffleSwitch(name='log_account', comment='Enables logging throughout the smarter.app.account namespace.', default=False), 'log_account_mixin': SmarterWaffleSwitch(name='log_account_mixin', comment='Enables logging within the smarter.apps.account.mixins.AccountMixin class.', default=False), 'log_api': SmarterWaffleSwitch(name='log_api', comment='Enables logging throughout the smarter.api namespace.', default=True), 'log_caching': SmarterWaffleSwitch(name='log_caching', comment='Enables detailed logging for caching operations including cache hits, misses, and errors.', default=False), 'log_chatapp': SmarterWaffleSwitch(name='log_chatapp', comment='For the React Prompt UI component. Enables debug-level javascript console logging inside the browser', default=True), 'log_connection': SmarterWaffleSwitch(name='log_connection', comment='Enables logging throughout the smarter.app.connection namespace.', default=True), 'log_doodle': SmarterWaffleSwitch(name='log_doodle', comment='Enables logging throughout the smarter.app.doodle namespace.', default=True), 'log_extension': SmarterWaffleSwitch(name='log_extension', comment='Enables logging throughout the smarter.apps.llmtool.extension namespace.', default=True), 'log_guardrail': SmarterWaffleSwitch(name='log_guardrail', comment='Enables logging throughout the smarter.app.guardrail namespace', default=True), 'log_infrastructure': SmarterWaffleSwitch(name='log_infrastructure', comment='Enables logging throughout the smarter.app.infrastructure namespace.', default=True), 'log_llm_host': SmarterWaffleSwitch(name='log_llm_host', comment='Enables logging throughout the smarter.app.llmhost namespace.', default=True), 'log_llmclient': SmarterWaffleSwitch(name='log_llmclient', comment='Enables logging throughout the smarter.app.llmclient namespace.', default=True), 'log_llmclienthelper': SmarterWaffleSwitch(name='log_llmclienthelper', comment='Enables logging within the smarter.apps.llmclient.model.LLMClientHelper class.', default=False), 'log_manifest_brokers': SmarterWaffleSwitch(name='log_manifest_brokers', comment='Enables detailed diagnostic logging for manifest initialization, validation and brokered operations.', default=True), 'log_mcpclient': SmarterWaffleSwitch(name='log_mcpclient', comment='Enables logging throughout the smarter.app.mcpclient namespace.', default=True), 'log_mcpserver': SmarterWaffleSwitch(name='log_mcpserver', comment='Enables logging throughout the smarter.app.mcpserver namespace.', default=True), 'log_middleware': SmarterWaffleSwitch(name='log_middleware', comment='Enables detailed diagnostic logging for all middleware operations.', default=False), 'log_orchestrator': SmarterWaffleSwitch(name='log_orchestrator', comment='Enables logging throughout the smarter.app.orchestrator namespace.', default=True), 'log_plugin': SmarterWaffleSwitch(name='log_plugin', comment='Enables logging throughout the smarter.app.plugin namespace.', default=True), 'log_prompt': SmarterWaffleSwitch(name='log_prompt', comment='Enables logging throughout the smarter.app.prompt namespace.', default=True), 'log_provider': SmarterWaffleSwitch(name='log_provider', comment='Enables logging throughout the smarter.app.provider namespace.', default=True), 'log_proxy': SmarterWaffleSwitch(name='log_proxy', comment='Enables logging throughout the smarter.app.proxy namespace.', default=True), 'log_receivers': SmarterWaffleSwitch(name='log_receivers', comment='Enables logging in all Django signal receivers throughout the Smarter codebase.', default=True), 'log_request_mixin': SmarterWaffleSwitch(name='log_request_mixin', comment='Enables detailed diagnostic logging for the SmarterRequestMixin class.', default=False), 'log_secret': SmarterWaffleSwitch(name='log_secret', comment='Enables logging throughout the smarter.app.secret namespace.', default=True), 'log_tasks': SmarterWaffleSwitch(name='log_tasks', comment='Enables logging in all Celery tasks throughout the Smarter codebase.', default=True), 'log_validators': SmarterWaffleSwitch(name='log_validators', comment='Enables logging in all Django model field validators throughout the Smarter codebase.', default=False), 'log_vectorsearch': SmarterWaffleSwitch(name='log_vectorsearch', comment='Enables logging throughout the smarter.app.vectorsearch namespace.', default=True), 'log_vectorstore': SmarterWaffleSwitch(name='log_vectorstore', comment='Enables logging throughout the smarter.app.vectorstore namespace.', default=True), 'log_views': SmarterWaffleSwitch(name='log_views', comment='Enables logging in all Django views throughout the Smarter codebase.', default=True)}
async smarter.lib.django.waffle.async_switch_is_active(switch_name)[source]

Async-safe wrapper around switch_is_active().

Django’s ORM-backed Waffle lookup is synchronous. Under ASGI callers should await this helper instead of calling switch_is_active() directly. thread_sensitive=True keeps the work on Django’s thread-sensitive sync executor so connection-local state remains safe.

A state that this process remembers is returned at once, without the hop to that executor, which is a single thread shared by every request.

Parameters:

switch_name (str) – The name of the Waffle switch to check.

Return type:

bool

Returns:

True if the switch is active, False otherwise.

smarter.lib.django.waffle.switch_is_active(switch_name)[source]

Check if a Waffle switch is active, with caching and database readiness checks.

Important

This is the preferred method for checking Waffle switches in the Smarter codebase. It includes caching to optimize performance and handles database readiness to prevent errors. Each process remembers a switch’s state for SWITCH_CACHE_SECONDS.

Example

from smarter.lib.django.waffle import SmarterWaffleSwitches, switch_is_active

if switch_is_active(SmarterWaffleSwitches.API_LOGGING):
    print("API logging is enabled.")
Parameters:

switch_name (str) – The name of the Waffle switch to check.

Return type:

bool

Returns:

True if the switch is active, False otherwise, including when the app registry or the database isn’t ready, or the name isn’t a SmarterWaffleSwitches switch. When the cache can’t be read, the switch is read from the database (see switch_from_database()).