Guide for creating or updating sample applications in this project. Use when adding a new sample, modifying an existing sample, or when asked to demonstrate a feature management capability with example code.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Guide for creating or updating sample applications in this project. Use when adding a new sample, modifying an existing sample, or when asked to demonstrate a feature management capability with example code.
Sample Applications
Samples live in samples/ and demonstrate feature management capabilities to users.
File conventions
Every sample must have the Microsoft copyright header:
# ------------------------------------------------------------------------# Copyright (c) Microsoft Corporation. All rights reserved.# Licensed under the MIT License. See License.txt in the project root for# license information.# -------------------------------------------------------------------------
Every sample must have a module-level docstring (one-liner describing what it demonstrates).
Filename should end with _sample.py and describe what is being demonstrated (e.g., feature_flag_sample.py, feature_variant_sample_with_telemetry.py).
Structure of a sample
Samples follow this general pattern:
# (copyright header)"""Sample demonstrating <what this shows>."""import json
import os
import sys
from featuremanagement import FeatureManager, TargetingContext
# Load feature flags from the local JSON file
file_path = os.path.dirname(os.path.abspath(sys.argv[0]))
withopen(os.path.join(file_path, "formatted_feature_flags.json"), encoding="utf-8") as f:
feature_flags = json.load(f)
# Create FeatureManager
feature_manager = FeatureManager(feature_flags)
# Demonstrate the feature
result = feature_manager.is_enabled("FlagName")
print(f"FlagName is {'enabled'if result else'disabled'}")
Feature flag definitions
Sample feature flags go in formatted_feature_flags.json under feature_management.feature_flags. Each flag needs at minimum id and enabled. Add filters, variants, allocation, or telemetry as needed for the sample.
Custom filters
Custom filters used by samples are defined in their own file (e.g., random_filter.py) and imported by the samples that need them.
Async samples
Async samples import from featuremanagement.aio instead of featuremanagement. See quarty_sample.py for the async pattern.
Azure-connected samples
Samples that connect to Azure App Configuration:
Use azure.appconfiguration.provider.load() to get configuration
Authenticate using DefaultAzureCredential from azure-identity, never connection strings
List Azure dependencies in samples/requirements.txt
Telemetry samples
Two patterns exist:
Callback-based: Pass on_feature_evaluated=publish_telemetry to FeatureManager and use track_event() from featuremanagement.azuremonitor.
Web app span processor: Use TargetingSpanProcessor from featuremanagement.azuremonitor with configure_azure_monitor(span_processors=[...]).
Dependencies
Any new package a sample needs must be added to samples/requirements.txt. CI installs these before linting samples.