or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/posthog@6.7.x
tile.json

tessl/pypi-posthog

tessl install tessl/pypi-posthog@6.7.0

Integrate PostHog into any python application.

Agent Success

Agent success rate when using this tile

89%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.03x

Baseline

Agent success rate without this tile

86%

task.mdevals/scenario-4/

Feature Flag-Based Configuration Service

Build a configuration service that uses feature flags to control application behavior and provide dynamic configuration values.

Requirements

Your service should:

  1. Check Feature Availability: Implement a function that determines whether a specific feature is enabled for a given user
  2. Get Configuration Variant: Implement a function that retrieves the active configuration variant for a user (e.g., for A/B testing)
  3. Retrieve All Active Features: Implement a function that returns all enabled features for a user in a single call
  4. Get Configuration Payload: Implement a function that retrieves additional configuration data associated with a feature flag

Implementation Details

Create a FeatureFlagService class with the following methods:

  • __init__(api_key: str, host: str): Initialize the service with API credentials and host URL
  • is_feature_enabled(feature_name: str, user_id: str) -> bool: Returns whether the feature is enabled for the user
  • get_feature_variant(feature_name: str, user_id: str) -> str | bool | None: Returns the variant/value of the feature flag
  • get_all_features(user_id: str) -> dict: Returns a dictionary of all feature flags for the user
  • get_feature_config(feature_name: str, user_id: str) -> dict | None: Returns the configuration payload for the feature

Dependencies { .dependencies }

posthog { .dependency }

Provides analytics and feature flag evaluation capabilities.

Test Cases { .test-cases }

Test 1: Check if feature is enabled { .test-case }

@test

Input:

  • Feature name: "new_dashboard"
  • User ID: "user_123"

Expected Behavior: The is_feature_enabled method should return a boolean indicating whether the feature is enabled.

File: test_feature_service.py { .test-file }

def test_feature_enabled():
    service = FeatureFlagService(api_key="test_key", host="http://localhost")
    result = service.is_feature_enabled("new_dashboard", "user_123")
    assert isinstance(result, bool)

Test 2: Get feature variant { .test-case }

@test

Input:

  • Feature name: "button_color"
  • User ID: "user_456"

Expected Behavior: The get_feature_variant method should return the variant value (could be a string, boolean, or None).

File: test_feature_service.py { .test-file }

def test_feature_variant():
    service = FeatureFlagService(api_key="test_key", host="http://localhost")
    result = service.get_feature_variant("button_color", "user_456")
    assert result is not None or result is None  # Can be any value

Test 3: Get all features for a user { .test-case }

@test

Input:

  • User ID: "user_789"

Expected Behavior: The get_all_features method should return a dictionary containing all feature flags.

File: test_feature_service.py { .test-file }

def test_all_features():
    service = FeatureFlagService(api_key="test_key", host="http://localhost")
    result = service.get_all_features("user_789")
    assert isinstance(result, dict)

Test 4: Get feature configuration payload { .test-case }

@test

Input:

  • Feature name: "pricing_config"
  • User ID: "user_101"

Expected Behavior: The get_feature_config method should return a dictionary with the feature's payload data.

File: test_feature_service.py { .test-file }

def test_feature_config():
    service = FeatureFlagService(api_key="test_key", host="http://localhost")
    result = service.get_feature_config("pricing_config", "user_101")
    assert result is None or isinstance(result, dict)