Skip to main content

Feature Flags for FastAPI

Project description

Test Python package codecov PythonVersions Sourcery Black Known Vulnerabilities Twitter Follow

FastAPI Feature Flags

Very simple implementation of feature flags for FastAPI.

  • Minimum configuration required
  • No unnecessary dependencies
  • Does its job

Installing

To install the package from pip, first run:

pip install -U https://github.com/Pytlicek/fastapi-featureflags/archive/refs/tags/0.3.zip

Usage

A simple example of feature flags:

from fastapi_featureflags import FeatureFlags, feature_flag, feature_enabled

FeatureFlags(conf_from_url="https://pastebin.com/raw/4Ai3j2DC")
print("Enabled Features:", FeatureFlags.get_features())


@feature_flag("web_1")
def web_1_enabled():
    print("Feature Should be enabled: web_1")

web_1_enabled()

if feature_enabled("web_2"):
    print("Feature Should be disabled: web_2")

You can get FF (feature flags) from a File, URL, Dictionary or ENV Variables:

FeatureFlags.load_conf_from_url("https://pastebin.com/raw/4Ai3j2DC")
FeatureFlags.load_conf_from_json("tests/features.json")
FeatureFlags.load_conf_from_dict({"web_1": True, "web_2": False})

FeatureFlags.reload_feature_flags()

There is also a handler that recognizes if the "@feature_flag" wrapper is used and the flag is not registered in the config. This way you can also use FF at runtime. Defaults to False, so it's safer if you forget the feature flag in the code.

Function get_features returns a list of all registered FF
You can enable or disable functions on the fly with enable_feature or enable_feature

When needed you can reload all feature flags with reload_feature_flags, this is useful when you want to read and change features from URL. All unregistered or on-the-fly created FF, that are not in the configuration will be omitted.

For non-production testing, a router is available, so you can see the paths in swagger-ui docs. Use include_in_schema=False when defining the router for public deployments

from fastapi_featureflags import router as ff_router
app.include_router(ff_router, tags=["FeatureFlags"])

FastAPI-FF

Contributing and Code of Conduct

Contributing to fastapi-featureflags

As an open source project, fastapi-featureflags welcomes contributions of many forms.
Please read and follow our Contributing to fastapi-featureflags

Code of Conduct

As a contributor, you can help us keep the fastapi-featureflags project open and inclusive.
Please read and follow our Code of Conduct


TODO

  • Better main class
  • Packaging

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_featureflags-0.3.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

fastapi_featureflags-0.3-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_featureflags-0.3.tar.gz.

File metadata

  • Download URL: fastapi_featureflags-0.3.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for fastapi_featureflags-0.3.tar.gz
Algorithm Hash digest
SHA256 8df47bd61120b39fc8653cc529c93b35bb31f6cf423125432dfe74bc186dcb9a
MD5 1e7ad95cbb3ee3f8ddf5bc0a69a4cb1e
BLAKE2b-256 7d33e865ae7649476ad042f88b2493f6b4b1833c8ac8eb49cd7db8029833cbf3

See more details on using hashes here.

File details

Details for the file fastapi_featureflags-0.3-py3-none-any.whl.

File metadata

  • Download URL: fastapi_featureflags-0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for fastapi_featureflags-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 68e9e4727752cafdb71274842394cabd6f2631ef33487011a743384bc541ad93
MD5 8ec5626d27fdc96c7b64861f5c6a2531
BLAKE2b-256 b5dff9f3bfbacf86c3c725a9b47bb3d9f5b72f7df19a7da227a56eb6d6685096

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page