OpenFeature Gleam SDK

Package Version Hex Docs

An SDK for the OpenFeature specification.

gleam add openfeature
import gleam/bool
import gleam/dict
import gleam/dynamic
import gleam/io
import gleam/option.{None}
import openfeature/api as openfeature
import openfeature/client
import openfeature/evaluation.{type ResolutionDetails}
import openfeature/evaluation_context
import openfeature/providers/in_memory
pub fn main() {
let test_flag =
in_memory.Flag(
"off",
dict.from_list([
#("off", dynamic.from(False)),
#("on", dynamic.from(True)),
]),
None,
)
let flags = dict.from_list([#("test_flag", test_flag)])
let provider = in_memory.provider(flags)
let _ = openfeature.set_provider(provider)
// set global provider
io.println(
"`test_flag` evaluated to " <> bool.to_string(evaluate_flag("test_flag")),
)
}
fn evaluate_flag(flag: String) -> Bool {
openfeature.get_client()
|> client.resolve_bool_evaluation(flag, False, evaluation_context.empty())
|> fn(details: ResolutionDetails(Bool)) { details.value }
}

Further documentation can be found at https://hexdocs.pm/openfeature.

🌟 Features

Status Features Description
Providers Integrate with a commercial, open source, or in-house feature management tool.
Targeting Contextually-aware flag evaluation using evaluation context.
Hooks Add functionality to various stages of the flag evaluation life-cycle.
Logging Integrate with popular logging packages.
Domains Logically bind clients with providers.
Eventing React to state changes in the provider or flag management system.
Shutdown Gracefully clean up a provider during application shutdown.
⚠️ Extending Extend OpenFeature with custom providers and hooks.

Implemented: ✅ | In-progress: ⚠️ | Not implemented yet: ❌

Providers

TODO

Targeting

TODO

Hooks

TODO

Logging

TODO

Domains

TODO

Eventing

TODO

Shutdown

The OpenFeature API provides a close function to perform a cleanup of all registered providers. This should only be called when your application is in the process of shutting down.

import openfeature/api as openfeature
openfeature.shutdown()

Extending

Develop a provider

TODO

Develop a hook

TODO