feature_gate


Namefeature_gate JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/deftinc/feature_gate
SummaryAn extensible feature flagging library for Python
upload_time2024-04-11 13:20:49
maintainerPatrick Wiseman
docs_urlNone
authorPatrick Wiseman
requires_python>=3.10
licenseMIT
keywords feature flags feature gate
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FeatureGate

Featuregate is a simple feature flag API similar to [Flipper](https://github.com/flippercloud/flipper).

## Configuration

### PosthogAdapter

```bash
export POSTHOG_API_KEY="someapikey"
export POSTHOG_PROJECT_ID="someprojectid"
```

## Usage

```python
from feature_gate.client import Client
from feature_gate.adapters import PosthogAdapter
from feature_gate.feature import Feature

adapter = PosthogAdapter() # Or MemoryAdapter for testing
client = Client(adapter)
feature = Feature("Test flag", "test_flag", "This is a test flag")

client.features()
# => []

client.add(feature)
# => True

client.features()
# => ["test_flag"]

client.is_enabled("test_flag")
# => False

client.enable("test_flag")
# => True

client.is_enabled("test_flag")
# => True

client.disable("test_flag")
# => True

client.is_enabled("test_flag")
# => False

client.remove("test_flag")
# => True

client.features()
# => []
```

## Errors

### FeatureNotFound
If you try to run something that presumes the existence of a feature and it can't find it it'll throw a `FeatureNotFound`.

```python
from feature_gate.client import FeatureNotFound

try:
  client.remove("some_feature_that_definitely_does_not_exist")
except FeatureNotFound as err:
  # Do what we want to do when the feature doesn't exist
```

### PostApiClientError
For the `PosthogAdapter` in particular it will raise error if it was unable to reach the Posthog API. These get bubbled up as `PosthogAPIClientError`.

```python
from feature_gate.clients.posthog_api_client import PosthogAPIClientError

try:
  client.features() #disable network connection
except PosthogAPIClientError as err:
  # Handle the error -- define default behavior in outage
```

## Testing

The Memory Adapter can be used for writing tests. This creates an ephemeral memory only implementation of the feature_gate client API. This is non-suitable for production only for tests.

```python
from feature_gate.client import Client
from feature_gate.adapters.memory import MemoryAdapter

client = Client(MemoryAdapter())
```

## Developing this library

### Hot-reload the REPL

Hot-reload the client in the repl for development:

```
$ repl
>>> exec(open('reload.py').read())
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/deftinc/feature_gate",
    "name": "feature_gate",
    "maintainer": "Patrick Wiseman",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "patrick@deft.services",
    "keywords": "feature flags, feature gate",
    "author": "Patrick Wiseman",
    "author_email": "patrick@deft.services",
    "download_url": "https://files.pythonhosted.org/packages/76/33/974408036ff122faf591876d0338668bfd9e6d619786f4e094973a921cf7/feature_gate-0.0.5.tar.gz",
    "platform": null,
    "description": "# FeatureGate\n\nFeaturegate is a simple feature flag API similar to [Flipper](https://github.com/flippercloud/flipper).\n\n## Configuration\n\n### PosthogAdapter\n\n```bash\nexport POSTHOG_API_KEY=\"someapikey\"\nexport POSTHOG_PROJECT_ID=\"someprojectid\"\n```\n\n## Usage\n\n```python\nfrom feature_gate.client import Client\nfrom feature_gate.adapters import PosthogAdapter\nfrom feature_gate.feature import Feature\n\nadapter = PosthogAdapter() # Or MemoryAdapter for testing\nclient = Client(adapter)\nfeature = Feature(\"Test flag\", \"test_flag\", \"This is a test flag\")\n\nclient.features()\n# => []\n\nclient.add(feature)\n# => True\n\nclient.features()\n# => [\"test_flag\"]\n\nclient.is_enabled(\"test_flag\")\n# => False\n\nclient.enable(\"test_flag\")\n# => True\n\nclient.is_enabled(\"test_flag\")\n# => True\n\nclient.disable(\"test_flag\")\n# => True\n\nclient.is_enabled(\"test_flag\")\n# => False\n\nclient.remove(\"test_flag\")\n# => True\n\nclient.features()\n# => []\n```\n\n## Errors\n\n### FeatureNotFound\nIf you try to run something that presumes the existence of a feature and it can't find it it'll throw a `FeatureNotFound`.\n\n```python\nfrom feature_gate.client import FeatureNotFound\n\ntry:\n  client.remove(\"some_feature_that_definitely_does_not_exist\")\nexcept FeatureNotFound as err:\n  # Do what we want to do when the feature doesn't exist\n```\n\n### PostApiClientError\nFor the `PosthogAdapter` in particular it will raise error if it was unable to reach the Posthog API. These get bubbled up as `PosthogAPIClientError`.\n\n```python\nfrom feature_gate.clients.posthog_api_client import PosthogAPIClientError\n\ntry:\n  client.features() #disable network connection\nexcept PosthogAPIClientError as err:\n  # Handle the error -- define default behavior in outage\n```\n\n## Testing\n\nThe Memory Adapter can be used for writing tests. This creates an ephemeral memory only implementation of the feature_gate client API. This is non-suitable for production only for tests.\n\n```python\nfrom feature_gate.client import Client\nfrom feature_gate.adapters.memory import MemoryAdapter\n\nclient = Client(MemoryAdapter())\n```\n\n## Developing this library\n\n### Hot-reload the REPL\n\nHot-reload the client in the repl for development:\n\n```\n$ repl\n>>> exec(open('reload.py').read())\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An extensible feature flagging library for Python",
    "version": "0.0.5",
    "project_urls": {
        "Homepage": "https://github.com/deftinc/feature_gate",
        "Repository": "https://github.com/deftinc/feature_gate"
    },
    "split_keywords": [
        "feature flags",
        " feature gate"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1065b3eaac25ebe6bf802d0eecac85e8e6d136903f41e8974d557095e068c252",
                "md5": "f936e486f82adf843433163f39c5cb5f",
                "sha256": "9908e9240ff3ba586603b59433252b72c2c48639db29060c2a6b72b2fbbadbda"
            },
            "downloads": -1,
            "filename": "feature_gate-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f936e486f82adf843433163f39c5cb5f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 7245,
            "upload_time": "2024-04-11T13:20:46",
            "upload_time_iso_8601": "2024-04-11T13:20:46.537862Z",
            "url": "https://files.pythonhosted.org/packages/10/65/b3eaac25ebe6bf802d0eecac85e8e6d136903f41e8974d557095e068c252/feature_gate-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7633974408036ff122faf591876d0338668bfd9e6d619786f4e094973a921cf7",
                "md5": "063cd994dc121f27c1c33f002a7536b8",
                "sha256": "eec59a5610ebcbfee820e6cd44c9001dfe4c9bbb14be72ec9223b486990284f4"
            },
            "downloads": -1,
            "filename": "feature_gate-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "063cd994dc121f27c1c33f002a7536b8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 5851,
            "upload_time": "2024-04-11T13:20:49",
            "upload_time_iso_8601": "2024-04-11T13:20:49.127148Z",
            "url": "https://files.pythonhosted.org/packages/76/33/974408036ff122faf591876d0338668bfd9e6d619786f4e094973a921cf7/feature_gate-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-11 13:20:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "deftinc",
    "github_project": "feature_gate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "feature_gate"
}
        
Elapsed time: 0.28810s