{"id":22822475,"url":"https://github.com/switcherapi/switcher-client-py","last_synced_at":"2026-04-25T19:02:22.346Z","repository":{"id":260829987,"uuid":"882462511","full_name":"switcherapi/switcher-client-py","owner":"switcherapi","description":"[Py] Switcher Client - Python SDK to work with Switcher API - Cloud-based Feature Flag ","archived":false,"fork":false,"pushed_at":"2026-04-18T23:42:08.000Z","size":275,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-19T00:23:50.528Z","etag":null,"topics":["feature-flags","python-sdk","switcherapi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/switcherapi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"patreon":"switcherapi","ko_fi":"petruki","github":["petruki"]}},"created_at":"2024-11-02T20:52:40.000Z","updated_at":"2026-04-18T23:42:08.000Z","dependencies_parsed_at":"2024-12-26T00:24:16.682Z","dependency_job_id":"6c9eec0f-b155-4d3c-b35b-5dec700de27e","html_url":"https://github.com/switcherapi/switcher-client-py","commit_stats":null,"previous_names":["switcherapi/switcher-client-py"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/switcherapi/switcher-client-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/switcherapi%2Fswitcher-client-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/switcherapi%2Fswitcher-client-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/switcherapi%2Fswitcher-client-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/switcherapi%2Fswitcher-client-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/switcherapi","download_url":"https://codeload.github.com/switcherapi/switcher-client-py/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/switcherapi%2Fswitcher-client-py/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32273223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T18:29:39.964Z","status":"ssl_error","status_checked_at":"2026-04-25T18:29:32.149Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["feature-flags","python-sdk","switcherapi"],"created_at":"2024-12-12T16:12:04.843Z","updated_at":"2026-04-25T19:02:22.341Z","avatar_url":"https://github.com/switcherapi.png","language":"Python","funding_links":["https://patreon.com/switcherapi","https://ko-fi.com/petruki","https://github.com/sponsors/petruki"],"categories":[],"sub_categories":[],"readme":"***\n\n\u003cdiv align=\"center\"\u003e\n\u003cb\u003eSwitcher Client SDK\u003c/b\u003e\u003cbr\u003e\nA Python SDK for Switcher API\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![Master CI](https://github.com/switcherapi/switcher-client-py/actions/workflows/master.yml/badge.svg)](https://github.com/switcherapi/switcher-client-py/actions/workflows/master.yml)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=switcherapi_switcher-client-py\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=switcherapi_switcher-client-py)\n[![Pypi: switcher-client](https://img.shields.io/pypi/v/switcher-client.svg)](https://pypi.org/project/switcher-client/)\n[![Conda: switcher-client](https://anaconda.org/switcherapi/switcher-client/badges/version.svg)](https://anaconda.org/switcherapi/switcher-client)\n[![Python: 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Slack: Switcher-HQ](https://img.shields.io/badge/slack-@switcher/hq-blue.svg?logo=slack)](https://switcher-hq.slack.com/)\n\n\u003c/div\u003e\n\n***\n\n![Switcher API: Python Client: Cloud-based Feature Flag API](https://github.com/switcherapi/switcherapi-assets/blob/master/logo/switcherapi_python_client.png)\n\n\u003c/div\u003e\n\n---\n\n## Table of Contents\n\n- [Quick Start](#quick-start)\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Usage Examples](#usage-examples)\n- [Advanced Features](#advanced-features)\n- [Snapshot Management](#snapshot-management)\n- [Testing \u0026 Development](#testing--development)\n- [Contributing](#contributing)\n\n---\n\n## About\n\nThe **Switcher Client SDK for Python** provides seamless integration with [Switcher-API](https://github.com/switcherapi/switcher-api), enabling powerful feature flag management in your Python applications.\n\n### Key Features\n\n- **Clean \u0026 Maintainable**: Flexible and robust functions that keep your code organized\n- **Local Mode**: Work offline using snapshot files from your Switcher-API Domain\n- **Silent Mode**: Hybrid configuration with automatic fallback for connectivity issues\n- **Built-in Mocking**: Easy implementation of automated testing with mock support\n- **Zero Latency**: Local snapshot execution for high-performance scenarios\n- **Secure**: Built-in protection against ReDoS attacks with regex safety features\n- **Monitoring**: Comprehensive logging and error handling capabilities\n\n## Quick Start\n\nGet up and running in just a few lines of code:\n\n```python\nfrom switcher_client import Client\n\n# Initialize the client\nClient.build_context(\n    domain='My Domain',\n    url='https://api.switcherapi.com',\n    api_key='[YOUR_API_KEY]',\n    component='MyApp',\n    environment='default'\n)\n\n# Use feature flags\nswitcher = Client.get_switcher()\nif switcher.is_on('FEATURE_TOGGLE'):\n    print(\"Feature is enabled!\")\n```\n\n## Installation\n\nInstall the Switcher Client SDK:\n\n```bash\n# Pip\npip install switcher-client\n```\n\n```bash\n# Conda\nconda install switcherapi::switcher-client\n```\n\n\n### System Requirements\n- **Python**: 3.9+ (supports 3.9, 3.10, 3.11, 3.12, 3.13, 3.14)\n- **Operating System**: Cross-platform (Windows, macOS, Linux)\n\n## Configuration\n\n### Basic Setup\n\nInitialize the Switcher Client with your domain configuration:\n\n```python\nfrom switcher_client import Client\n\nClient.build_context(\n    domain='My Domain',                 # Your Switcher domain name\n    url='https://api.switcherapi.com',  # Switcher-API endpoint (optional)\n    api_key='[YOUR_API_KEY]',           # Your component's API key (optional)\n    component='MyApp',                  # Your application name (optional)\n    environment='default'               # Environment ('default' for production)\n)\n\nswitcher = Client.get_switcher()\n```\n\n#### Configuration Parameters\n\n| Parameter | Required | Description | Default |\n|-----------|----------|-------------|---------|\n| `domain` | ✅ | Your Switcher domain name | - |\n| `url` |  | Switcher-API endpoint | `https://api.switcherapi.com` |\n| `api_key` |  | API key for your component | - |\n| `component` |  | Your application identifier | - |\n| `environment` |  | Target environment | `default` |\n\n### Advanced Configuration\n\nEnable additional features like local mode, silent mode, and security options:\n\n```python\nfrom switcher_client import Client, ContextOptions\n\nClient.build_context(\n    domain='My Domain',\n    url='https://api.switcherapi.com',\n    api_key='[YOUR_API_KEY]',\n    component='MyApp',\n    environment='default',\n    options=ContextOptions(\n        local=True,\n        logger=True,\n        freeze=True,\n        snapshot_location='./snapshot/',\n        snapshot_auto_update_interval=3,\n        silent_mode='5m',\n        restrict_relay=True,\n        throttle_max_workers=2,\n        regex_max_black_list=10,\n        regex_max_time_limit=100,\n        cert_path='./certs/ca.pem'\n    )\n)\n\nswitcher = Client.get_switcher()\n```\n\n#### Advanced Options Reference\n\n| Option | Type | Description | Default |\n|--------|------|-------------|---------|\n| `local` | `bool` | Use local snapshot files only (zero latency) | `False` |\n| `logger` | `bool` | Enable logging/caching of feature flag evaluations | `False` |\n| `freeze` | `bool` | Enable cache-immutability responses for consistent results | `False` |\n| `snapshot_location` | `str` | Directory for snapshot files | `'./snapshot/'` |\n| `snapshot_auto_update_interval` | `int` | Auto-update interval in seconds (0 = disabled) | `0` |\n| `silent_mode` | `str` | Silent mode retry time (e.g., '5m' for 5 minutes) | `None` |\n| `restrict_relay` | `bool` | Enable relay restrictions in local mode | `True` |\n| `throttle_max_workers` | `int` | Max workers for throttling feature checks | `None` |\n| `regex_max_black_list` | `int` | Max cached entries for failed regex | `100` |\n| `regex_max_time_limit` | `int` | Regex execution time limit (ms) | `3000` |\n| `cert_path` | `str` | Path to custom certificate for secure API connections | `None` |\n\n#### Security Features\n\n- **ReDoS Protection**: Built-in ReDoS attack prevention with regex safety features\n- **Time Limits**: Configurable timeouts prevent long-running regex operations\n- **Certificate Support**: Use custom certificates for secure API connections\n\n## Usage Examples\n\n### Basic Feature Flag Checking\n\nThe simplest way to check if a feature is enabled:\n\n```python\nswitcher = Client.get_switcher()\n\n# Simple boolean check\nif switcher.is_on('FEATURE_LOGIN_V2'):\n    # Use new login system\n    new_login()\nelse:\n    # Use legacy login\n    legacy_login()\n```\n\n### Detailed Response Information\n\nGet comprehensive information about the feature flag evaluation:\n\n```python\nresponse = switcher.is_on_with_details('FEATURE_LOGIN_V2')\n\nprint(f\"Feature enabled: {response.result}\")     # True or False\nprint(f\"Reason: {response.reason}\")              # Evaluation reason\nprint(f\"Metadata: {response.metadata}\")          # Additional context\n```\n\n### Strategy-Based Feature Flags\n\n#### Method 1: Prepare and Execute\n\nLoad validation data separately, useful for complex applications:\n\n```python\n# Prepare the validation context\nswitcher.check_value('USER_123').prepare('USER_FEATURE')\n\n# Execute when ready\nif switcher.is_on():\n    enable_user_feature()\n```\n\n#### Method 2: All-in-One Execution\n\nChain multiple validation strategies for comprehensive feature control:\n\n```python\nis_enabled = switcher \\\n                    # VALUE strategy\n                    .check_value('premium_user') \\\n                    # NETWORK strategy\n                    .check_network('192.168.1.0/24') \\\n                    # Fallback value if API fails\n                    .default_result(True) \\\n                    # Cache result for 1 second\n                    .throttle(1000) \\\n                    .is_on('PREMIUM_FEATURES')\n\nif is_enabled:\n    show_premium_dashboard()\n```\n\n### Error Handling\n\nSubscribe to error notifications for robust error management:\n\n```python\n# Set up error handling\nClient.subscribe_notify_error(lambda error: print(f\"Switcher Error: {error}\"))\n```\n\n## Advanced Features\n\n#### Throttling\n```python\n# Zero-latency async execution\nswitcher.throttle(1000).is_on('FEATURE01')\n```\n\n#### Hybrid Mode\n```python\n# Force remote resolution for specific features\nswitcher.remote().is_on('FEATURE01')\n```\n\n## Snapshot Management\n\n### Loading Snapshots\n\nLoad configuration snapshots from the API for local/offline usage:\n\n```python\n# Download and save snapshot from API\nClient.load_snapshot()\n```\n\n### Version Management\n\nCheck your current snapshot version:\n\n```python\n# Verify snapshot version\nversion_info = Client.check_snapshot()\nprint(f\"Current snapshot version: {Client.snapshot_version()}\")\n```\n\n### Automated Updates\n\nSchedule automatic snapshot updates for zero-latency local mode:\n\n```python\nClient.schedule_snapshot_auto_update(\n    interval=60,\n    callback=lambda error, updated: (\n        print(f\"Snapshot updated to version: {Client.snapshot_version()}\") if updated else None\n    )\n)\n```\n\n### Snapshot Monitoring\n\n```python\n# Watch for snapshot file changes\nClient.watch_snapshot(WatchSnapshotCallback(\n    success=lambda: print(\"✅ Snapshot loaded successfully\"),\n    reject=lambda e: print(f\"❌ Error loading snapshot: {e}\")\n))\n```\n\n## Testing \u0026 Development\n\n### Built-in Mocking (Coming Soon)\n\n\u003e 🚧 **Note**: The mocking features are currently under development\n\nThe SDK will include powerful mocking capabilities for testing:\n\n```python\n# 🚧 TODO: Mock feature states for testing\nClient.assume('FEATURE01').true()\nassert switcher.is_on('FEATURE01') == True\n\nClient.forget('FEATURE01')  # Reset to normal behavior\n\n# 🚧 TODO: Mock with metadata\nClient.assume('FEATURE01').false().with_metadata({\n    'message': 'Feature is disabled'\n})\nresponse = switcher.is_on_with_details('FEATURE01')\nassert response.result == False\nassert response.metadata['message'] == 'Feature is disabled'\n```\n\n### Test Mode Configuration\n\n```python\n# 🚧 TODO: Enable test mode to prevent file locking\nClient.enable_test_mode()\n```\n\n### Configuration Validation\n\nValidate your feature flag configuration before deployment:\n\n```python\n# Verify that all required switchers are configured\ntry:\n    Client.check_switchers(['FEATURE_LOGIN', 'FEATURE_DASHBOARD', 'FEATURE_PAYMENTS'])\n    print(\"✅ All switchers are properly configured\")\nexcept Exception as e:\n    print(f\"❌ Configuration error: {e}\")\n```\n\nThis validation helps prevent deployment issues by ensuring all required feature flags are properly set up in your Switcher domain.\n\n## Contributing\nWe welcome contributions to the Switcher Client SDK for Python! If you have suggestions, improvements, or bug fixes, please follow these steps:\n\n1. Fork the repository.\n2. Create a new branch for your feature or bug fix.\n3. Make your changes and commit them with clear messages.\n4. Submit a pull request detailing your changes and the problem they solve.\n\nThank you for helping us improve the Switcher Client SDK!\n\n### Requirements\n- Python 3.9 or higher\n- Virtualenv - `pip install virtualenv`\n- Create a virtual environment - `python3 -m venv .venv`\n- Install Pipenv - `pip install pipenv`\n- Check Makefile for all available commands","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswitcherapi%2Fswitcher-client-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswitcherapi%2Fswitcher-client-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswitcherapi%2Fswitcher-client-py/lists"}