Code Monkey home page Code Monkey logo

fastapi-featureflags's Introduction

Test Python package codecov Upload Python Package to PyPI PythonVersions Sourcery Black Snyk Downloads 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 fastapi-featureflags

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, prefix="/ff", 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

fastapi-featureflags's People

Contributors

maltsev avatar manfre avatar pytlicek avatar wzharith avatar xmatoha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fastapi-featureflags's Issues

CodeCov warning

Fix issue with CodeCov:

->  Issue detecting commit SHA. Please run actions/checkout with fetch-depth > 1 or set to 0
    current dir:  /home/runner/work/fastapi-featureflags/fastapi-featureflags
    project root: .
    Yaml not found, that's ok! Learn more at http://docs.codecov.io/docs/codecov-yaml
==> Running gcov in . (disable via -X gcov)
==> Python coveragepy not found
==> Searching for coverage reports in:
    + .
--> No coverage report found.
    Please visit http://docs.codecov.io/docs/supported-languages

Screenshot 2023-05-04 at 09 56 25

Tests review

I think we can review tests and add some new ones.

Use PyPI API token instead of basic auth

What?
During your recent upload or upload attempt of fastapi-featureflags to PyPI, we noticed you used  
basic authentication  (username & password).  
However, your account has two-factor authentication (2FA) enabled.  

In the near future, PyPI will begin prohibiting uploads using basic authentication for accounts with two-factor  
authentication enabled. Instead, we will require API tokens to be used.  

What should I do?  
First, generate an API token for your account or project at https://pypi.org/manage/account/token/.  
Then, use this token when publishing instead of your username and password.  
See https://pypi.org/help/#apitoken for help using API tokens to publish.

I think also related to: #8

Load FF from dict or env variables

Load FF from env variables. This is useful when you want to load feature flags from env variables into docker, so the FF can be reloaded every time the container starts in docker daemon or kubernetes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.