{"id":20607707,"url":"https://github.com/open-feature/kotlin-sdk","last_synced_at":"2025-04-15T04:02:17.176Z","repository":{"id":190003148,"uuid":"663664042","full_name":"open-feature/kotlin-sdk","owner":"open-feature","description":"Kotlin implementation of the OpenFeature SDK for Android clients","archived":false,"fork":false,"pushed_at":"2025-04-08T10:44:23.000Z","size":494,"stargazers_count":14,"open_issues_count":16,"forks_count":5,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-08T11:34:11.416Z","etag":null,"topics":["sdk"],"latest_commit_sha":null,"homepage":"https://openfeature.dev","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/open-feature.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-07T20:30:53.000Z","updated_at":"2025-03-17T07:35:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"91a2dc40-f706-48c9-ac6f-465a77a0f682","html_url":"https://github.com/open-feature/kotlin-sdk","commit_stats":null,"previous_names":["open-feature/kotlin-sdk"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fkotlin-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fkotlin-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fkotlin-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fkotlin-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-feature","download_url":"https://codeload.github.com/open-feature/kotlin-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003952,"owners_count":21196793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sdk"],"created_at":"2024-11-16T10:08:22.723Z","updated_at":"2025-04-15T04:02:17.169Z","avatar_url":"https://github.com/open-feature.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable MD033 --\u003e\n\u003c!-- x-hide-in-docs-start --\u003e\n\u003cp align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/open-feature/community/0e23508c163a6a1ac8c0ced3e4bd78faafe627c7/assets/logo/horizontal/white/openfeature-horizontal-white.svg\" /\u003e\n    \u003cimg align=\"center\" alt=\"OpenFeature Logo\" src=\"https://raw.githubusercontent.com/open-feature/community/0e23508c163a6a1ac8c0ced3e4bd78faafe627c7/assets/logo/horizontal/black/openfeature-horizontal-black.svg\" /\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\n\u003ch2 align=\"center\"\u003eOpenFeature Kotlin SDK\u003c/h2\u003e\n\n\u003c!-- x-hide-in-docs-end --\u003e\n\u003c!-- The 'github-badges' class is used in the docs --\u003e\n\u003cp align=\"center\" class=\"github-badges\"\u003e\n  \u003ca href=\"https://github.com/open-feature/spec/releases/tag/v0.8.0\"\u003e\n    \u003cimg alt=\"Specification\" src=\"https://img.shields.io/static/v1?label=specification\u0026message=v0.8.0\u0026color=yellow\u0026style=for-the-badge\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- x-release-please-start-version --\u003e\n  \u003ca href=\"https://github.com/open-feature/kotlin-sdk/releases/tag/v0.4.1\"\u003e\n    \u003cimg alt=\"Release\" src=\"https://img.shields.io/static/v1?label=release\u0026message=v0.4.1\u0026color=blue\u0026style=for-the-badge\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- x-release-please-end --\u003e\n  \u003cbr/\u003e\n  \u003cimg alt=\"Status\" src=\"https://img.shields.io/badge/lifecycle-alpha-a0c3d2.svg\" /\u003e\n  \u003ca href=\"https://mvnrepository.com/artifact/dev.openfeature/android-sdk\"\u003e\n    \u003cimg alt=\"MavenCentral\" src=\"https://img.shields.io/maven-central/v/dev.openfeature/android-sdk\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\u003c!-- x-hide-in-docs-start --\u003e\n\n[OpenFeature](https://openfeature.dev) is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool.\n\n\u003c!-- x-hide-in-docs-end --\u003e\n## 🚀 Quick start\n\n### Requirements\n\n- The Android minSdk version supported is: `21`.\n\nNote that this library is intended to be used in a mobile context, and has not been evaluated for use in other types of applications (e.g. server applications).\n\n### Install\n\n#### Maven Central\n\nInstallation via Maven Central is preferred, using the following dependency:\n\n\u003c!-- x-release-please-start-version --\u003e\n```kotlin\ndependencies {\n    api(\"dev.openfeature:android-sdk:0.4.1\")\n}\n```\n\n### Usage\n\n```kotlin\ncoroutineScope.launch(Dispatchers.IO) {\n  // configure a provider, wait for it to complete its initialization tasks\n  OpenFeatureAPI.setProviderAndWait(customProvider)\n  val client = OpenFeatureAPI.getClient()\n\n  // get a bool flag value\n  client.getBooleanValue(\"boolFlag\", default = false)\n}\n```\n\n## 🌟 Features\n\n| Status | Features                        | Description                                                                                                                        |\n|--------|---------------------------------|------------------------------------------------------------------------------------------------------------------------------------|\n| ✅      | [Providers](#providers)         | Integrate with a commercial, open source, or in-house feature management tool.                                                     |\n| ✅      | [Targeting](#targeting)         | Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context). |\n| ✅      | [Hooks](#hooks)                 | Add functionality to various stages of the flag evaluation life-cycle.                                                             |\n| ✅      | [Tracking](#tracking)           | Associate user actions with feature flag evaluations.                                                                              |\n| ❌      | [Logging](#logging)             | Integrate with popular logging packages.                                                                                           |\n| ❌      | [Named clients](#named-clients) | Utilize multiple providers in a single application.                                                                                |\n| ✅      | [Eventing](#eventing)           | React to state changes in the provider or flag management system.                                                                  |\n| ✅      | [Shutdown](#shutdown)           | Gracefully clean up a provider during application shutdown.                                                                        |\n| ⚠️     | [Extending](#extending)         | Extend OpenFeature with custom providers and hooks.                                                                                |\n\n\u003csub\u003eImplemented: ✅ | In-progress: ⚠️ | Not implemented yet: ❌\u003c/sub\u003e\n\n### Providers\n\n[Providers](https://openfeature.dev/docs/reference/concepts/provider) are an abstraction between a flag management system and the OpenFeature SDK.\nLook [here](https://openfeature.dev/ecosystem?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Provider\u0026instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=kotlin) for a complete list of available providers.\nIf the provider you're looking for hasn't been created yet, see the [develop a provider](#develop-a-provider) section to learn how to build it yourself.\n\nOnce you've added a provider as a dependency, it can be registered with OpenFeature like this:\n\n```kotlin\ncoroutineScope.launch(Dispatchers.IO) {\n    OpenFeatureAPI.setProviderAndWait(MyProvider())\n}\n```\n\nAsynchronous API that doesn't wait is also available. It's useful when you want to set a provider and continue with other tasks.\n\nHowever, flag evaluations are only possible after the provider is Ready.\n\n```kotlin\nOpenFeatureAPI.setProvider(MyProvider()) // can pass a dispatcher here\n// The provider initialization happens on a coroutine launched on the IO dispatcher. \nval status = OpenFeatureAPI.getStatus()\n// When status is Ready, flag evaluations can be made\n```\n\n\n### Targeting\n\nSometimes, the value of a flag must consider some dynamic criteria about the application or user, such as the user's location, IP, email address, or the server's location.\nIn OpenFeature, we refer to this as [targeting](https://openfeature.dev/specification/glossary#targeting).\nIf the flag management system you're using supports targeting, you can provide the input data using the [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context).\n\n```kotlin\n// set a value to the global context\nval evaluationContext = ImmutableContext(\n    targetingKey = session.getId,\n    attributes = mutableMapOf(\"region\" to Value.String(\"us-east-1\")))\nOpenFeatureAPI.setEvaluationContext(evaluationContext)\n```\n\n### Hooks\n\n[Hooks](https://openfeature.dev/docs/reference/concepts/hooks) allow for custom logic to be added at well-defined points of the flag evaluation life-cycle.\nLook [here](https://openfeature.dev/ecosystem/?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Hook\u0026instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=kotlin) for a complete list of available hooks.\nIf the hook you're looking for hasn't been created yet, see the [develop a hook](#develop-a-hook) section to learn how to build it yourself.\n\nOnce you've added a hook as a dependency, it can be registered at the global, client, or flag invocation level.\n\n```kotlin\n// add a hook globally, to run on all evaluations\nOpenFeatureAPI.addHooks(listOf(ExampleHook()))\n\n// add a hook on this client, to run on all evaluations made by this client\nval client = OpenFeatureAPI.getClient()\nclient.addHooks(listOf(ExampleHook()))\n\n// add a hook for this evaluation only\nval retval = client.getBooleanValue(flagKey, false,\n    FlagEvaluationOptions(listOf(ExampleHook())))\n```\n\n### Tracking\n\nThe [tracking API](https://openfeature.dev/specification/sections/tracking/) allows you to use \nOpenFeature abstractions to associate user actions with feature flag evaluations.\nThis is essential for robust experimentation powered by feature flags. Note that, unlike methods \nthat handle feature flag evaluations, calling `track(...)` may throw an `IllegalArgumentException` \nif an empty string is passed as the `trackingEventName`.\n\nBelow is an example of how we can track a \"Checkout\" event with some `TrackingDetails`.\n\n```kotlin\nOpenFeatureAPI.getClient().track(\n  \"Checkout\",\n  TrackingEventDetails(\n    499.99,\n    ImmutableStructure(\n      \"numberOfItems\" to Value.Integer(4),\n      \"timeInCheckout\" to Value.String(\"PT3M20S\")\n    )\n  )\n)\n```\n\nTracking is optionally implemented by Providers.\n\n### Logging\n\nLogging customization is not yet available in the Kotlin SDK.\n\nIt is possible to write and inject logging `Hook`s to log events at different stages of the flag evaluation life-cycle.\n\n### Named clients\n\nSupport for named clients is not yet available in the Kotlin SDK.\n\n### Eventing\n\nEvents from the Provider allow the SDK to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions.\nEvents are optional which mean that not all Providers will emit them and it is not a must have. Some providers support additional events, such as `PROVIDER_CONFIGURATION_CHANGED`.\n\nPlease refer to the documentation of the provider you're using to see what events are supported.\n\nExample usage:\n```kotlin\nviewModelScope.launch {\n  OpenFeatureAPI.observe().collect {\n    println(\"\u003e\u003e Provider event received\")\n  }\n}\n\nviewModelScope.launch {\n  OpenFeatureAPI.setProviderAndWait(\n    MyFeatureProvider(),\n    Dispatchers.IO,\n    myEvaluationContext\n  )\n}\n```\n\n\u003c!-- (It's only possible to observe events from the global `OpenFeatureAPI`, until multiple providers are supported) --\u003e\n\n### Shutdown\n\nThe OpenFeature API provides a close function to perform a cleanup of the registered provider.\nThis should only be called when your application is in the process of shutting down.\n\n```kotlin\nOpenFeatureAPI.shutdown()\n```\n## Sample app\n\nIn the repo there is also a sample app currently under development. \nThe sample app can be used to try out development of a [Provider](#develop-a-provider), a [Hook](#develop-a-hook) \nor to validate changes to the SDK itself. \n\nThe sample app should not be used as a reference implementation of how to use the OpenFeature SDK \nin an Android app.\n\n## Extending\n\n### Develop a provider\n\nTo develop a provider, you need to create a new project and include the OpenFeature SDK as a dependency.\nYou’ll then need to write the provider by implementing the `FeatureProvider` interface exported by the OpenFeature SDK.\n\n```kotlin\nclass NewProvider(override val hooks: List\u003cHook\u003c*\u003e\u003e, override val metadata: Metadata) : FeatureProvider {\n    override fun getBooleanEvaluation(\n        key: String,\n        defaultValue: Boolean,\n        context: EvaluationContext?\n    ): ProviderEvaluation\u003cBoolean\u003e {\n        // resolve a boolean flag value\n    }\n\n    override fun getDoubleEvaluation(\n        key: String,\n        defaultValue: Double,\n        context: EvaluationContext?\n    ): ProviderEvaluation\u003cDouble\u003e {\n        // resolve a double flag value\n    }\n\n    override fun getIntegerEvaluation(\n        key: String,\n        defaultValue: Int,\n        context: EvaluationContext?\n    ): ProviderEvaluation\u003cInt\u003e {\n        // resolve an integer flag value\n    }\n\n    override fun getObjectEvaluation(\n        key: String,\n        defaultValue: Value,\n        context: EvaluationContext?\n    ): ProviderEvaluation\u003cValue\u003e {\n        // resolve an object flag value\n    }\n\n    override fun getStringEvaluation(\n        key: String,\n        defaultValue: String,\n        context: EvaluationContext?\n    ): ProviderEvaluation\u003cString\u003e {\n        // resolve a string flag value\n    }\n\n    override suspend fun initialize(initialContext: EvaluationContext?) {\n        // add context-aware provider initialization\n    }\n\n    override suspend fun onContextSet(oldContext: EvaluationContext?, newContext: EvaluationContext) {\n        // add necessary changes on context change\n    }\n  \n    override fun track(\n      trackingEventName: String,\n      context: EvaluationContext?,\n      details: TrackingEventDetails?\n    ) {\n      // Optionally track an event\n    }\n  \n    override fun observe(): Flow\u003cOpenFeatureProviderEvents\u003e {\n        // Optionally return a `Flow` of OpenFeatureProviderEvents\n    }\n}\n```\n\n\u003e Built a new provider? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=\u0026labels=provider\u0026projects=\u0026template=document-provider.yaml\u0026title=%5BProvider%5D%3A+) so we can add it to the docs!\n\n### Develop a hook\n\nTo develop a hook, you need to create a new project and include the OpenFeature SDK as a dependency.\nImplement your own hook by conforming to the `Hook` interface exported by the OpenFeature SDK.\n\n\u003c!-- TODO: code example of hook implementation --\u003e\n\n\u003e Built a new hook? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=\u0026labels=hook\u0026projects=\u0026template=document-hook.yaml\u0026title=%5BHook%5D%3A+) so we can add it to the docs!\n\n\u003c!-- x-hide-in-docs-start --\u003e\n## ⭐️ Support the project\n\n- Give this repo a ⭐️!\n- Follow us on social media:\n  - Twitter: [@openfeature](https://twitter.com/openfeature)\n  - LinkedIn: [OpenFeature](https://www.linkedin.com/company/openfeature/)\n- Join us on [Slack](https://cloud-native.slack.com/archives/C0344AANLA1)\n- For more, check out our [community page](https://openfeature.dev/community/)\n\n## 🤝 Contributing\n\nInterested in contributing? Great, we'd love your help! To get started, take a look at the [CONTRIBUTING](CONTRIBUTING.md) guide.\n\n### Thanks to everyone who has already contributed\n\n\u003ca href=\"https://github.com/open-feature/kotlin-sdk/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=open-feature/kotlin-sdk\" alt=\"Pictures of the folks who have contributed to the project\" /\u003e\n\u003c/a\u003e\n\nMade with [contrib.rocks](https://contrib.rocks).\n\u003c!-- x-hide-in-docs-end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-feature%2Fkotlin-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-feature%2Fkotlin-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-feature%2Fkotlin-sdk/lists"}