Skip to main content

FeatureGate

Featuregate is a simple feature flag API similar to Flipper.

Configuration

PosthogAdapter

export POSTHOG_API_KEY="someapikey"
export POSTHOG_PROJECT_ID="someprojectid"
export POSTHOG_API_BASE="https://us.posthog.com" # Optional, defaults to US Cloud

POSTHOG_API_KEY must be a personal API key with the feature_flag:read and feature_flag:write scopes. EU Cloud users should set POSTHOG_API_BASE="https://eu.posthog.com"; self-hosted users should use their own domain.

Usage

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.

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

PosthogApiClientError

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

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

RateLimitError

Again, specific to the PosthogAdapter it will raise an error if the account is rate limited by the Posthog API. These get bubbled up as RateLimitError.

from feature_gate.clients.posthog_api_client import RateLimitError

try:
  client.features() # receives response indicating a rate limit and retry time in seconds
except RateLimitError as err:
  # Handle the error -- define default behavior during rate limiting

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.

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

client = Client(MemoryAdapter())

Developing this library

Tool versions (Python and uv) are pinned in .tool-versions and installed with asdf.

bin/bootstrap # first-time setup
bin/ci        # install dependencies and run the tests

Hot-reload the REPL

Hot-reload the client in the repl for development:

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

Metadata

Release files for feature_gate 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for feature_gate 0.0.8
File Size Uploaded Provenance Actions
feature_gate-0.0.8.tar.gz 8.9 kB Without provenance Details for feature_gate-0.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for feature_gate 0.0.8
File Interpreter ABI Platform Actions
feature_gate-0.0.8-py3-none-any.whl Python 3 none any Details for feature_gate-0.0.8-py3-none-any.whl

Total release size: 16.9 kB

Release files / feature_gate-0.0.8.tar.gz

Download URL feature_gate-0.0.8.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ffef015fbecce9cf48ed1eefe3e5616f94deede8b8bc1391837127c6674801ae
BLAKE2b-256 checksum
How to use checksums
3ceef575c865c5c80241b0e17f4b96a9353f85427cb4700f1168df6c3586ebf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / feature_gate-0.0.8-py3-none-any.whl

Download URL feature_gate-0.0.8-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02bd59557a8d06496d207642f8a4b772d84f5d48b16b818b78612fe73f3bc750
BLAKE2b-256 checksum
How to use checksums
498279a8009a3fea80f16635abab89b543957f14d946297a38c286379f97837a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for feature_gate 0.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page