Feature Flags

Feature flag system for controlling feature rollout.

Module Contents

Feature flags system for conditional functionality.

class FeatureFlags[source]

Bases: object

Feature flags management for conditional functionality.

enable_oauth

OAuth authentication support

enable_jobs

Job listings functionality

enable_sponsors

Sponsorship management

Site-wide search functionality

maintenance_mode

Application-wide maintenance mode

__init__(*, enable_oauth=True, enable_jobs=True, enable_sponsors=True, enable_search=True, maintenance_mode=False)[source]
is_enabled(feature_name)[source]

Check if a feature is enabled.

Parameters:

feature_name (str) – Name of the feature to check

Return type:

bool

Returns:

True if feature is enabled, False otherwise

Raises:

AttributeError – If feature name does not exist

to_dict()[source]

Export feature flags as dictionary for template context.

Return type:

dict[str, bool]

Returns:

Dictionary of feature flag names and their values

require_feature(feature_name)[source]

Guard decorator factory to require a feature to be enabled.

Parameters:

feature_name (str) – Name of the feature flag to check

Returns:

Guard function that validates feature is enabled

Example:

@get("/oauth/login", guards=[require_feature("enable_oauth")])
async def oauth_login() -> dict:
    return {"message": "OAuth login"}

Usage

Feature flags allow you to control feature availability at runtime:

from pydotorg.core.features import FeatureFlags

if FeatureFlags.is_enabled("new_download_page"):
    # New feature code
    pass
else:
    # Legacy code
    pass