• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Djblets 5.x
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.x
    6. Version 2.0
    7. Version 1.0
    8. Version 0.9
    9. Djblets Documentation
    10. Guides
    11. Feature Checks Guides
    12. Introduction to Feature Checks
  • Home
  • Guides
  • Avatar Services Guides
  • Writing Avatar Services
  • Extension Guides
  • Writing Extensions
  • Testing Extensions
  • Feature Checks Guides
  • Introduction to Feature Checks
  • Writing Features
  • Writing Feature Checkers
  • Testing with Feature Checks
  • Integration Guides
  • Supporting Integrations
  • Writing Integrations
  • Privacy Compliance Guides
  • Getting and Checking Consent
  • Working with Personally Identifiable Information
  • Service Integrations
  • reCAPTCHA Guides
  • Using reCAPTCHA
  • Registries Guides
  • Writing Registries
  • Web API Guides
  • Writing Web API Resources
  • Adding OAuth2 Support
  • Module and Class References
  • djblets
  • djblets.deprecation
  • djblets.auth.forms
  • djblets.auth.ratelimit
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.avatars.errors
  • djblets.avatars.forms
  • djblets.avatars.registry
  • djblets.avatars.services
  • djblets.avatars.services.base
  • djblets.avatars.services.fallback
  • djblets.avatars.services.file_upload
  • djblets.avatars.services.gravatar
  • djblets.avatars.services.url
  • djblets.avatars.settings
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.cache.synchronizer
  • djblets.conditions
  • djblets.conditions.choices
  • djblets.conditions.conditions
  • djblets.conditions.errors
  • djblets.conditions.operators
  • djblets.conditions.values
  • djblets.configforms.forms
  • djblets.configforms.mixins
  • djblets.configforms.pages
  • djblets.configforms.registry
  • djblets.configforms.views
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.fields.base64_field
  • djblets.db.fields.comma_separated_values_field
  • djblets.db.fields.counter_field
  • djblets.db.fields.json_field
  • djblets.db.fields.modification_timestamp_field
  • djblets.db.fields.relation_counter_field
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.query_catcher
  • djblets.db.query_comparator
  • djblets.db.validators
  • djblets.extensions.admin
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.features
  • djblets.features.checkers
  • djblets.features.decorators
  • djblets.features.errors
  • djblets.features.feature
  • djblets.features.level
  • djblets.features.registry
  • djblets.features.testing
  • djblets.features.templatetags.features
  • djblets.forms.fields
  • djblets.forms.fieldsets
  • djblets.forms.forms
  • djblets.forms.forms.key_value_form
  • djblets.forms.widgets
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.http.middleware
  • djblets.http.responses
  • djblets.integrations.errors
  • djblets.integrations.forms
  • djblets.integrations.hooks
  • djblets.integrations.integration
  • djblets.integrations.manager
  • djblets.integrations.mixins
  • djblets.integrations.models
  • djblets.integrations.urls
  • djblets.integrations.views
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.escape_html
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.pipeline.compilers.es6
  • djblets.pipeline.compilers.less
  • djblets.pipeline.compilers.mixins
  • djblets.pipeline.compilers.rollup
  • djblets.pipeline.compilers.typescript
  • djblets.pipeline.settings
  • djblets.privacy.consent
  • djblets.privacy.consent.base
  • djblets.privacy.consent.common
  • djblets.privacy.consent.errors
  • djblets.privacy.consent.forms
  • djblets.privacy.consent.hooks
  • djblets.privacy.consent.registry
  • djblets.privacy.consent.tracker
  • djblets.privacy.models
  • djblets.privacy.pii
  • djblets.privacy.templatetags.djblets_privacy
  • djblets.recaptcha.mixins
  • djblets.recaptcha.siteconfig
  • djblets.recaptcha.templatetags.djblets_recaptcha
  • djblets.recaptcha.widgets
  • djblets.registries
  • djblets.registries.errors
  • djblets.registries.importer
  • djblets.registries.mixins
  • djblets.registries.registry
  • djblets.registries.signals
  • djblets.secrets
  • djblets.secrets.crypto
  • djblets.secrets.token_generators
  • djblets.secrets.token_generators.base
  • djblets.secrets.token_generators.legacy_sha1
  • djblets.secrets.token_generators.registry
  • djblets.secrets.token_generators.vendor_checksum
  • djblets.siteconfig
  • djblets.siteconfig.admin
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.signals
  • djblets.siteconfig.views
  • djblets.template.caches
  • djblets.template.context
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.compat.django.core.cache
  • djblets.util.compat.python.past
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.functional
  • djblets.util.html
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.json_utils
  • djblets.util.properties
  • djblets.util.serializers
  • djblets.util.symbols
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.util.typing
  • djblets.util.views
  • djblets.views.generic.base
  • djblets.views.generic.etag
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.backends.oauth2_tokens
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.fields
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.oauth2_scopes
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.oauth2_tokens
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.signals
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • General Index
  • Python Module Index
  • Release Notes
  • Introduction to Feature Checks¶

    Feature checks are a way of allowing feature development to happen in a codebase without exposing those features to all your users. You can define a feature with an ID, name, summary, and a stability level (unavailable, experimental, beta, or stable) and limit who’s able to actually see and use that feature, dynamically.

    The ability to control access to a feature can be done in a variety of ways. Features can be enabled based on their stability level, or based on a per-feature setting, or based on custom logic defined in the application.

    There are many modules out there that provide this functionality, with specific ways to write and check those features. Djblets provides its own variation in a way that’s very small and very pluggable, with support for existing Djblets features like SiteConfiguration.

    There are two main components in the feature check system: The features, and the checkers.

    Features¶

    Applications should define a Feature subclass for every feature they want to control access to. These specify a unique ID, a name and summary, and the current stability level of the feature. They can also supply initialization or shutdown logic for that feature.

    A typical feature might look like:

    from djblets.features import Feature
    
    
    class MyFeature(Feature):
        feature_id = 'myproject.myfeature'
        name = 'My Feature'
        summary = 'This feature does some neat things.'
    
    
    my_feature = MyFeature()
    

    Checking Features¶

    Features can be checked in Python code:

    if my_feature.is_enabled():
        ...
    

    Or in templates:

    {% if_feature_enabled "myproject.myfeature" %}
    ...
    {% else %}
    ...
    {% endif_feature_enabled %}
    

    You can also do the inverse of this in templates:

    {% if_feature_disabled "myproject.myfeature" %}
    ...
    {% else %}
    ...
    {% endif_feature_disabled %}
    

    More specialized feature checkers, as we’ll see below, may take other state into consideration when determining if a feature is enabled. For instance, it may want to consider a request or user. These can be provided as well:

    if my_feature.is_enabled(request=request, user=user):
        ...
    
    {% if_feature_enabled "myproject.myfeature" request=request user=user %}
    ...
    {% endif_feature_enabled %}
    

    There’s more you can do with a feature. See Writing Features.

    You may also want to look into testing with feature checks, to help you write comprehensive unit tests.

    Feature Checkers¶

    Feature checkers are small classes that determine whether a feature should be enabled or disabled. They do this by making a determination based on a feature stability level and based on any arguments passed to the checker.

    Unless otherwise customized by a subclass, feature checkers will determine that beta-level features are enabled by default only if settings.DEBUG = True, and that stable-level features are always enabled by default. This logic is contained within min_enabled_level().

    If a feature isn’t determined to be enabled based on its level, then is_feature_enabled() will make a final determination. How it does this depends very much on the feature checker. It can make a determination based on some global setting somewhere, or it may consider keyword arguments passed to the function and make a determination based on those.

    An application can choose the feature checker to use by configuring settings.FEATURE_CHECKER to point to the absolute class path.

    Built-in Checkers¶

    There are two built-in feature checkers:

    SettingsFeatureChecker:

    Determines whether a feature is enabled by checking for the feature’s ID in a settings.ENABLED_FEATURES dictionary. For instance:

    ENABLED_FEATURES = {
        'my-feature': True,
    }
    

    If present and True, the feature will be enabled. Otherwise, it will be disabled.

    This is the default feature checker.

    SiteConfigFeatureChecker:

    Determines whether a feature is enabled first by checking for the feature’s ID in a enabled_features dictionary in SiteConfiguration.settings, and then falling back on a settings.ENABLED_FEATURES dictionary (just like with SettingsFeatureChecker.

    To use this, set the following in settings.py:

    FEATURE_CHECKER = 'djblets.features.checkers.SiteConfigFeatureChecker'
    

    You can also write your own feature checker if you want custom behavior, such as determining features per-user.

    Feature Registry¶

    Every feature you instantiate gets added to the main feature registry. This registry allows you to dynamically look up, unregister, and re-register features.

    Looking Up Features¶

    You can fetch any previously-registered feature by calling get_feature():

    from djblets.features import get_feature_registry
    
    
    get_feature_registry().get_feature('my-feature-id')
    

    If the feature exists (doesn’t return None), then you can go ahead and make some determinations based on that feature.

    Iterating Features¶

    You can also iterate through all the features by iterating through the registry:

    from djblets.features import get_feature_registry
    
    
    for feature in get_feature_registry():
        ...
    

    Unregistering Features¶

    If you ever need to unregister a feature, you can do so with the unregister() method:

    from djblets.features import get_feature_registry
    
    from myapp.features import my_feature
    
    
    get_feature_registry().unregister(my_feature)
    

    Registering Features¶

    If you need to re-register a feature that was previously unregistered, you can do so with the register() method:

    from djblets.features import get_feature_registry
    
    from myapp.features import my_feature
    
    
    get_feature_registry().register(my_feature)
    

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • Features
      • Checking Features
    • Feature Checkers
      • Built-in Checkers
    • Feature Registry
      • Looking Up Features
      • Iterating Features
      • Unregistering Features
      • Registering Features