{"id":18463981,"url":"https://github.com/unleash/unleash-client-python","last_synced_at":"2025-04-04T17:10:39.289Z","repository":{"id":37735093,"uuid":"154826150","full_name":"Unleash/unleash-client-python","owner":"Unleash","description":"Unleash client SDK for Python 💡💡💡","archived":false,"fork":false,"pushed_at":"2024-04-08T20:39:30.000Z","size":6841,"stargazers_count":78,"open_issues_count":6,"forks_count":56,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-04-14T06:00:04.600Z","etag":null,"topics":["client-library","feature-flags","feature-management","feature-toggles","hacktoberfest","unleash","unleash-server"],"latest_commit_sha":null,"homepage":"http://unleash.github.io/unleash-client-python","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/Unleash.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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}},"created_at":"2018-10-26T11:47:02.000Z","updated_at":"2024-04-15T21:41:05.948Z","dependencies_parsed_at":"2023-02-09T12:01:37.037Z","dependency_job_id":"99831173-d42f-4a92-8ab5-ef2769e2ec91","html_url":"https://github.com/Unleash/unleash-client-python","commit_stats":{"total_commits":211,"total_committers":27,"mean_commits":7.814814814814815,"dds":"0.37914691943127965","last_synced_commit":"8172750c034610cd97056a73c4b107897e373bc3"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unleash%2Funleash-client-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unleash%2Funleash-client-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unleash%2Funleash-client-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unleash%2Funleash-client-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Unleash","download_url":"https://codeload.github.com/Unleash/unleash-client-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247217222,"owners_count":20903009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["client-library","feature-flags","feature-management","feature-toggles","hacktoberfest","unleash","unleash-server"],"created_at":"2024-11-06T09:08:32.036Z","updated_at":"2025-04-04T17:10:39.270Z","avatar_url":"https://github.com/Unleash.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unleash-client-python\n\n![](https://github.com/unleash/unleash-client-python/workflows/CI/badge.svg?branch=main) [![Coverage Status](https://coveralls.io/repos/github/Unleash/unleash-client-python/badge.svg?branch=main)](https://coveralls.io/github/Unleash/unleash-client-python?branch=main) [![PyPI version](https://badge.fury.io/py/UnleashClient.svg)](https://badge.fury.io/py/UnleashClient) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/UnleashClient.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\nThis is the Python client for [Unleash](https://github.com/unleash/unleash).  It implements [Client Specifications 1.0](https://docs.getunleash.io/client-specification) and checks compliance based on spec in [unleash/client-specifications](https://github.com/Unleash/client-specification)\n\n\u003e  **Migrating to v6**\n\u003e\n\u003e If you use custom strategies or access the `features` property on the Unleash Client, read the complete [migration guide](./v6_MIGRATION_GUIDE.md) before upgrading to v6.\n\n\nWhat it supports:\n* Default activation strategies using 32-bit [Murmurhash3](https://en.wikipedia.org/wiki/MurmurHash)\n* Custom strategies\n* Full client lifecycle:\n    * Client registers with Unleash server\n    * Client periodically fetches feature toggles and stores to on-disk cache\n    * Client periodically sends metrics to Unleash Server\n* Tested on Linux (Ubuntu), OSX, and Windows\n\nCheck out the [project documentation](https://unleash.github.io/unleash-client-python/) and the [changelog](https://docs.getunleash.io/unleash-client-python/changelog.html).\n\n## Installation\n\nCheck out the package on [Pypi](https://pypi.org/project/UnleashClient/)!\n\n```bash\npip install UnleashClient\n```\n\n## Usage\n\n### Initialization\n\n```python\nfrom UnleashClient import UnleashClient\n\nclient = UnleashClient(\n    url=\"https://unleash.herokuapp.com\",\n    app_name=\"my-python-app\",\n    custom_headers={'Authorization': '\u003cAPI token\u003e'})\n\nclient.initialize_client()\n```\n\nFor more information about configuring `UnleashClient`, check out the [project reference docs](https://docs.getunleash.io/unleash-client-python/unleashclient.html)!\n\n### Checking if a feature is enabled\n\nA check of a simple toggle:\n```python\nclient.is_enabled(\"my_toggle\")\n```\n\nTo supply application context, use the second positional argument:\n\n```python\napp_context = {\"userId\": \"test@email.com\"}\nclient.is_enabled(\"user_id_toggle\", app_context)\n```\n\n#### Fallback function and default values\n\nYou can specify a fallback function for cases where the client doesn't recognize the toggle by using the `fallback_function` keyword argument:\n\n```python\ndef custom_fallback(feature_name: str, context: dict) -\u003e bool:\n    return True\n\nclient.is_enabled(\"my_toggle\", fallback_function=custom_fallback)\n```\n\nYou can also use the `fallback_function` argument to replace the obsolete `default_value` keyword argument by using a lambda that ignores its inputs. Whatever the lambda returns will be used as the default value.\n\n```python\nclient.is_enabled(\"my_toggle\", fallback_function=lambda feature_name, context: True)\n```\n\nThe fallback function **must** accept the feature name and context as positional arguments in that order.\n\nThe client will evaluate the fallback function only if an exception occurs when calling the `is_enabled()` method. This happens when the client can't find the feature flag. The client _may_ also throw other, general exceptions.\n\nFor more information about usage, see the [Usage documentation](https://docs.getunleash.io/unleash-client-python/usage.html).\n\n### Getting a variant\n\nChecking for a variant:\n```python\ncontext = {'userId': '2'}  # Context must have userId, sessionId, or remoteAddr.  If none are present, distribution will be random.\n\nvariant = client.get_variant(\"variant_toggle\", context)\n\nprint(variant)\n\u003e {\n\u003e    \"name\": \"variant1\",\n\u003e    \"payload\": {\n\u003e        \"type\": \"string\",\n\u003e        \"value\": \"val1\"\n\u003e        },\n\u003e    \"enabled\": True\n\u003e }\n```\n\nFor more information about variants, see the [Variant documentation](https://docs.getunleash.io/advanced/toggle_variants).\n\n## Developing\n\nFor development, you'll need to setup the environment to run the tests. This repository is using\ntox to run the test suite to test against multiple versions of Python. Running the tests is as simple as running this command in the makefile:\n\n```\ntox -e py311\n```\n\nThis command will take care of downloading the client specifications and putting them in the correct place in the repository, and install all the dependencies you need.\n\nHowever, there are some caveats to this method. There is no easy way to run a single test, and running the entire test suite can be slow.\n\n### Manual setup\n\nFirst, make sure you have pip or pip3 installed.\n\nThen setup your viritual environment:\n\nLinux \u0026 Mac:\n\n```\npython3 -m venv venv\nsource venv/bin/activate\n```\n\nWindows + cmd:\n\n```\npython -m venv venv\nvenv\\Scripts\\activate.bat\n```\n\nPowershell:\n\n```\npython -m venv venv\nvenv\\Scripts\\activate.bat\n```\n\nOnce you've done your setup, run:\n```\npip install -r requirements.txt\n```\n\nRun the get-spec script to download the client specifications tests:\n```\n./scripts/get-spec.sh\n```\n\nNow you can run the tests by running `pytest` in the root directory.\n\nIn order to run a single test, run the following command:\n\n```\npytest testfile.py::function_name\n\n# example: pytest tests/unit_tests/test_client.py::test_consistent_results\n```\n\n### Linting\n\nIn order to lint all the files you can run the following command:\n\n```\nmake fmt\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funleash%2Funleash-client-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funleash%2Funleash-client-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funleash%2Funleash-client-python/lists"}