Skip to content
NanoFlags
Start free

All posts

Blog & guides

Feature flags in any language with OpenFeature and OFREP

NanoFlags speaks the OpenFeature Remote Evaluation Protocol (OFREP 0.4.0), so any OpenFeature OFREP provider can read your flags. When to use it, when a native SDK is the better choice, and how the results map to reasons and variants.

NanoFlags engineeringPublished 3 min read

We maintain native NanoFlags SDKs for JavaScript and TypeScript, Python and Go. They download the signed configuration once, verify it, and evaluate flags in-process with live updates. Writing and maintaining an SDK of that quality for every language your teams use is not realistic, for us or for anyone. So instead of a long tail of thin wrappers, NanoFlags implements an open standard that already has providers in many languages.

OpenFeature in one paragraph

OpenFeature is an open specification for feature-flag evaluation APIs. Your code calls a vendor-neutral client (getBooleanValue("checkout-v2", false, context)), and a provider connects that client to a flag system. The Remote Evaluation Protocol (OFREP) is the part of the standard that defines a plain HTTP API for evaluating flags remotely, so one generic OFREP provider per language works with any system that speaks the protocol.

What NanoFlags implements

  • OFREP 0.4.0 on the edge: single-flag evaluation (POST /ofrep/v1/evaluate/flags/{key}) and bulk evaluation of every flag a key can see (POST /ofrep/v1/evaluate/flags), with ETag / 304 Not Modified for the bulk call.
  • Base URL https://edge.nanoflags.io; authentication with your SDK key as Authorization: Bearer … or X-API-Key: ….
  • Evaluation against the environment's current published, signed revision, with the same evaluation engine the native SDKs use, so a given context gets the same value either way.
  • Server keys (nf_srv_…) evaluate every flag of their environment. Browser keys (nf_pub_…) only see flags marked client-exposed; any other flag answers FLAG_NOT_FOUND.

Two quickstarts

Go, with the OpenFeature Go SDK and its OFREP provider:

main.go
provider := ofrep.NewProvider("https://edge.nanoflags.io", ofrep.WithBearerToken(os.Getenv("NANOFLAGS_SERVER_KEY")))
if err := openfeature.SetProviderAndWait(provider); err != nil {
	panic(err)
}
client := openfeature.NewClient("checkout")

evalCtx := openfeature.NewEvaluationContext("user-123", map[string]any{"region": "US", "plan": "pro"})
enabled, _ := client.BooleanValue(context.Background(), "checkout-v2", false, evalCtx)

Python, with openfeature-sdk and openfeature-provider-ofrep:

app.py
import os
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from openfeature.contrib.provider.ofrep import OFREPProvider

key = os.environ["NANOFLAGS_SERVER_KEY"]
api.set_provider(OFREPProvider("https://edge.nanoflags.io", headers_factory=lambda: {"Authorization": f"Bearer {key}"}))
client = api.get_client()

ctx = EvaluationContext(targeting_key="user-123", attributes={"region": "US", "plan": "pro"})
enabled = client.get_boolean_value("checkout-v2", False, ctx)

Java, .NET, Node.js and browser examples are in the OFREP guide; providers for PHP, Ruby, Swift, Kotlin and more are configured with the same base URL and key header. Under the hood, every provider sends a request like this one:

raw HTTP
curl -X POST https://edge.nanoflags.io/ofrep/v1/evaluate/flags/checkout-v2 \
  -H "Authorization: Bearer $NANOFLAGS_SERVER_KEY" -H "Content-Type: application/json" \
  -d '{"context":{"targetingKey":"user-123","region":"US"}}'
# {"key":"checkout-v2","value":true,"reason":"TARGETING_MATCH","variant":"us","metadata":{"revision":42,"ruleIndex":0,"ruleId":"us"}}

Reasons, variants and metadata

OpenFeature reports why a value was returned, not only the value. NanoFlags maps its evaluation outcomes like this:

Reasons and variants
Situationreasonvariant
Flag turned off in this environmentDISABLEDoff
Flag has no rulesSTATICdefault
No rule matchedDEFAULTdefault
A rule with a fixed value matchedTARGETING_MATCHthe rule id
A percentage rollout matchedSPLIT<rule id>:rollout or <rule id>:otherwise

The flag metadata always carries revision, the published revision that was evaluated, and, when a rule matched, ruleIndex and ruleId. That makes an OFREP answer traceable to an exact, immutable configuration in the NanoFlags history.

OFREP or a native SDK?

Be deliberate about the trade-off. An OFREP server provider makes an HTTP request per evaluation; a web or mobile provider fetches all client-exposed flags in one request and re-checks on a poll interval (cheap, thanks to 304). A native SDK downloads the configuration once, evaluates in microseconds with no network on the hot path, and receives changes over a live connection.

  • JavaScript / TypeScript: use @nanoflags/sdk, with our OpenFeature provider if you want the OpenFeature API.
  • Python and Go: use the native Python and Go SDKs; each has its own OpenFeature provider too.
  • Every other language: use the OpenFeature OFREP provider for that language.
native SDK behind the OpenFeature API
import { OpenFeature } from "@openfeature/server-sdk";
import { createClient } from "@nanoflags/sdk";
import { NanoFlagsProvider } from "@nanoflags/openfeature-provider";

const nanoflags = createClient({ sdkKey: process.env.NANOFLAGS_SDK_KEY!, baseUrl: "https://edge.nanoflags.io", service: "checkout-api" });
await OpenFeature.setProviderAndWait(new NanoFlagsProvider({ client: nanoflags }));

const enabled = await OpenFeature.getClient().getBooleanValue("checkout-v2", false, { targetingKey: user.id, region: "US" });

Current limits

  • No push channel over OFREP: browser providers poll, and server providers ask per evaluation.
  • Shared test sessions are not applied to OFREP evaluations.
  • OFREP evaluations are not reported as evaluation events, so they do not appear in flag usage insights.
  • Each key may make 1,000 evaluations per 10 seconds per edge location (browser keys are counted per visitor network); beyond that the edge answers 429 with Retry-After, and providers pause.

Try it without an account, with the public key of the live demo on the home page (flags demo-new-checkout and demo-accent):

sh
curl -X POST https://edge.nanoflags.io/ofrep/v1/evaluate/flags \
  -H "X-API-Key: nf_pub_4ced72c484c4f388a900aeeaf81e130c110c11730d555dd8" -H "Content-Type: application/json" \
  -d '{"context":{"targetingKey":"user-123"}}'
  • openfeature
  • ofrep
  • sdk
  • go
  • python
  • java
  • .net