Skip to main content

Announcing Official Support for OpenFeature

· 5 min read
Zayyad Muhammad Sani
You live, you learn.

At ConfigCat, we've seen firsthand how feature flags help teams ship faster with less risk and build more resilient, user-friendly applications. We want more people to experience these benefits, so we've decided to officially support OpenFeature.

Our OpenFeature providers were previously developed and maintained by open-source contributors. Moving forward, we've opted to develop and maintain some providers in-house, while continuing to collaborate with open-source contributors for others.

In the upcoming sections, we'll explore how to integrate OpenFeature into a Python application that currently uses the ConfigCat Python SDK.

Announcing official OpenFeature support cover

What is OpenFeature

OpenFeature is a project under the Cloud Native Computing Foundation (CNCF) that offers a standard, vendor-agnostic API for feature flagging. With OpenFeature, developers can utilize a single SDK to interact with multiple feature management platforms. To make this possible, feature management platforms or the open-source community develop providers that connect their SDKs to OpenFeature. These SDKs and providers are available for many programming languages and feature management platforms.

An OpenFeature SDK connected to ConfigCat and a fictional vendor via providers

Why use OpenFeature with ConfigCat?

Here are a few reasons why combining OpenFeature with ConfigCat is a game-changer for your development process:

Avoid vendor lock-in: OpenFeature's APIs and SDKs let you work with any feature management platform, so you're not tied to just one.

Benefit from the OpenFeature ecosystem: OpenFeature offers a growing set of tools to help you integrate feature flags across your software development stack.

Migrate to ConfigCat more easily: If you're switching to ConfigCat from another platform, OpenFeature makes the migration process easier at the code level.

Check out our OpenFeature guide for more detailed explanations of these benefits.

Getting Started: Integrating ConfigCat with OpenFeature

Let’s see how you can integrate OpenFeature with ConfigCat in a Python app. We'll use a project with ConfigCat already set up to demonstrate how easy this integration can be.

tip

If you’re interested in using OpenFeature with other languages, check out our docs for the list of OpenFeature providers we have.

Sample App

The app is an online courses API with a GET endpoint that returns a predefined list of courses. The endpoint is linked to a feature flag I created in ConfigCat:

Feature flag turned on in ConfigCat

The endpoint will return the course list if the feature flag is turned on:

JSON response showing a list of courses

It will return an error if the flag is turned off:

JSON response showing a 404 not found error

After adding OpenFeature to the app, it should function just as before.

Installing OpenFeature

To run the sample app, you'll need the following:

  • A ConfigCat account
  • Python v3.9+
  • Git v2.33+
  • A tool to make HTTP requests (I'll be using Postman)
  • Intermediate knowledge of Python and FastAPI and basic knowledge of Git

You can find the sample app's source code on GitHub. The main.py file contains the initial code before OpenFeature was added, while cc-openfeature.py has the completed version with OpenFeature integrated.

Follow these steps to add OpenFeature to the project:

  1. Install the OpenFeature Python provider.
pip install configcat-openfeature-provider
  1. Import the newly installed packages in main.py:
main.py
# ... other imports
from openfeature import api
from configcat_openfeature_provider import ConfigCatProvider
# ... remaining code

Using ConfigCat with OpenFeature

As we integrate OpenFeature into the app, we'll use its API in place of ConfigCat code.

  1. In the lifespan function, use the OpenFeature provider to initialize the ConfigCat client.
main.py
# BEFORE
client = configcatclient.get(os.getenv("CONFIGCAT_SDK_KEY"))
app.state.client = client

# AFTER
cc_provider = ConfigCatProvider(os.getenv("CONFIGCAT_SDK_KEY"))
  1. Enable the provider with OpenFeature's API and instantiate a new OpenFeature client.
main.py
api.set_provider(cc_provider)
client = openfeature.get_client()
app.state.client = client

The OpenFeature client accesses the provider we set up and uses it to evaluate feature flags.

  1. After the yield statement, use OpenFeature's API to clean up the providers when the application shuts down.
main.py
yield
api.shutdown()

The lifespan function should now look like this:

main.py
@asynccontextmanager
async def lifespan(app: FastAPI):
cc_provider = ConfigCatProvider(os.getenv("CONFIGCAT_SDK_KEY"))
api.set_provider(cc_provider)
client = api.get_client()
app.state.client = client
yield
# clean up all provders
api.shutdown()

We have one more code change to make.

  1. Evaluate the feature flag using the OpenFeature client in the get_courses function.
main.py
# BEFORE
is_get_courses_enabled = app.state.client.get_value('get_courses_enabled', False)

# AFTER
is_get_courses_enabled = app.state.client.get_boolean_value('get_courses_enabled', False)

And here's the full function:

main.py
@app.get("/courses/")
def get_courses():
is_get_courses_enabled = client.get_boolean_value('get_courses_enabled', False)
if is_get_courses_enabled:
return {"courses": courses}
else:
raise HTTPException(status_code = 404)

We're using a boolean flag that returns True when the flag is on and False when the flag is off. For cases like A/B tests, user segmentation, or targeting, an OpenFeature context object is required to evaluate the feature flag. Check out our OpenFeature Python docs to see how the context object works.

  1. Run the program in your terminal:
fastapi dev main.py
  1. Toggle the flag in your ConfigCat dashboard and visit http://localhost:8000/courses. The app should work like before:
Feature flag turned off in ConfigCat JSON response showing a 404 not found error

And there you have it! The app is now OpenFeature compliant. As always, you can find the complete code on GitHub.

Conclusion

Open-source software has increased collaboration among developers and accelerated advancements in the software industry like never before. Whether a company offers proprietary software, open-source software, or a mix of both, everyone benefits when projects like OpenFeature make feature flags more accessible and better integrated across the entire software development stack.

Resources

For more on feature flags, check out ConfigCat on Facebook, X, LinkedIn, and GitHub.