Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Server-side SDKs
Here are the configuration options for contexts in server-side SDKs:- .NET (server-side)
- Apex
- C++ (server-side)
- Erlang
- Go
- Haskell
- Java
- Lua
- Node.js (server-side)
- PHP
- Python
- Ruby
- Rust
.NET (server-side)
Expand .NET (server-side) code sample
Expand .NET (server-side) code sample
In the server-side .NET SDK, you can construct a Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If an attribute is a JSON object, then in your flag or segment targeting, you can use
Context that only has a key by calling Context.New. The context kind defaults to “user,” or you can supply a different context kind. Alternatively, you can use the Context.Builder method for building a context with other properties.The argument to Builder is the context’s key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The optional name and kind attributes, which you can set with
.Name() and .Kind(), expect string values. If the kind attribute is not specified, it is assumed to be “user.” Other attribute values can be booleans, numbers, strings, arrays, or JSON objects. The SDK uses the LdValue type to represent arrays and objects. The .NET SDK is strongly-typed, so be aware of this distinction./ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the .NET (server-side) SDK, read Private attributes.To learn how to configure anonymous contexts in the .NET (server-side) SDK, read Anonymous contexts and users.Apex
Expand Apex code sample
Expand Apex code sample
Here’s an example of a user:The argument to
Builder is the user’s key. The key should uniquely identify each user. You can use a primary key or a hash, as long as the same user always has the same key. We recommend using a hash if possible. In this example, the hash is "example-user-key".To learn how to configure private attributes in the Apex SDK, read Private attributes.To learn how to configure anonymous users in the Apex SDK, read Anonymous contexts and users.C++ (server-side)
Expand C++ (server-side) code sample
Expand C++ (server-side) code sample
In the C++ (server-side) SDK, you can construct a context using the Here’s how to construct a context with context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If you are working in C, when you are done with the context ensure that you free the structure:To learn how to configure private attributes in the C++ (server-side) SDK, read Private attributes.To learn how to configure anonymous contexts in the C++ (server-side) SDK, read Anonymous contexts and users.
ContextBuilder. The arguments to .Kind() are the context kind and key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash for the key, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:Erlang
Expand Erlang code sample
Expand Erlang code sample
In the Erlang SDK, use Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:To learn how to configure private attributes in the Erlang SDK, read Private attributes.To learn how to configure anonymous contexts in the Erlang SDK, read Anonymous contexts and users.
ldclient_context:set and ldclient_context:new to define and construct a context.The key property is the context’s key. The key is the only mandatory context attribute. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.You can set the kind, or, if you do not set it, LaunchDarkly assumes that the context kind is “user.”Here’s an example of a context:Go
Expand Go code sample
Expand Go code sample
In the Go SDK, you have two options for how you want to manage contexts:Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:You can also use the context builder to create each of the individual contexts:Each individual context within a multi-context can have the same attributes. The only restriction is that each context has to have a different context After you create a scoped client, we recommend adding it your Go context. Another advantage of using If an attribute is a JSON object, then in your flag or segment targeting, you can use
-
Create a context and pass it in when you initialize an
LDScopedClient. This is a wrapper aroundLDClientthat lets you specify the evaluation context to use for all operations. The scoped client’s context is a multi-context, and you can update the multi-context with additional associated contexts at any time. -
Create a context and pass it in to each method call, such as when you evaluate a flag. To use this option, create a single, shared instance of
LDClient.
Context struct and a Builder. The context key is the only mandatory context attribute. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:kind from the others within the multi-context.If you’re working with LDScopedClient, you don’t need to manually create the multi-context. Instead, you can add new contexts to the scoped client’s multi-context as they become available, or update existing contexts:LDScopedClient is that you can pass the scoped client to any logic that already takes a Go context (context.Context), using utility methods provided in the SDK. This means the scoped client is implicitly passed around through all of your code that uses context.Context, and you can access the scoped client anywhere in your application logic. To learn more, read Use Go contexts with LDScopedClient.To learn more about the available LaunchDarkly context attributes, read Context and Builder.The kind and name attributes expect string values. You can set the kind, or, if you do not set it, LaunchDarkly assumes that the context kind is “user.” Other attribute values can be booleans, numbers, strings, arrays, or JSON objects. These types are all represented by the
ldvalue.Value type. The Go SDK is strongly-typed, so be aware of this distinction./ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the Go SDK, read Private attributes.To learn how to configure anonymous contexts in the Go SDK, read Anonymous contexts and users.Haskell
Expand Haskell code sample
Expand Haskell code sample
In the Haskell SDK, use Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:To learn how to configure private attributes in the Haskell SDK, read Private attributes.To learn how to configure anonymous contexts in the Haskell SDK, read Anonymous contexts and users.
makeContext to create a new context. The argument to makeContext is the context’s key. The key is the only mandatory attribute. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example of a context:Java
Expand Java code sample
Expand Java code sample
In the Java SDK, use a builder pattern to construct contexts. The argument to Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:The documentation for If an attribute is a JSON object, then in your flag or segment targeting, you can use
Builder is the context’s key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:ContextBuilder shows you all the attributes that LaunchDarkly supports by default.The optional name and kind attributes expect string values. If the “kind” attribute is not specified, it is assumed to be “user.” Other attribute values can be booleans, numbers, strings, arrays, or objects. If you pass a value that looks like a number or a boolean, the SDK interprets it that way. The Java SDK is strongly-typed, so be aware of this distinction.
/ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the Java SDK, read Private attributes.To learn how to configure anonymous contexts in the Java SDK, read Anonymous contexts and users.Lua
Expand Lua code sample
Expand Lua code sample
In the Lua SDK, use Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:To learn more, read
makeContext to construct a context of any kind. This requires a context key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible. The context attributes are defined as part of the context kind.To construct a user context specifically, you can use makeUser. Both makeUser and makeContext require a context key. You can omit the kind option if you construct your context with makeUser. This method is a convenience to make upgrading from the Lua SDK version 1.x to version 2.0 easier. It is deprecated and may be removed in future versions.Here’s an example of a context:makeUser and makeContext.To learn how to configure private attributes in the Lua SDK, read Private attributes.To learn how to configure anonymous contexts in the Lua SDK, read Anonymous contexts and users.Node.js (server-side)
Expand Node.js (server-side) code sample
Expand Node.js (server-side) code sample
In the Node.js (server-side) SDK, contexts are JSON objects. The Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If an attribute is a JSON object, then in your flag or segment targeting, you can use
key property is the context key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The optional
name and kind attributes expect string values. If the kind attribute is not specified, it is assumed to be “user.” Other attribute values can be booleans, numbers, strings, arrays, or JSON objects./ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the Node.js (server-side) SDK, read Private attributes.To learn how to configure anonymous contexts in the Node.js (server-side) SDK, read Anonymous contexts and users.PHP
Expand PHP code sample
Expand PHP code sample
In the PHP SDK, use a builder pattern to construct contexts. The first argument to Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:To learn how to configure private attributes in the PHP SDK, read Private attributes.To learn how to configure anonymous contexts in the PHP SDK, read Anonymous contexts and users.
LDContextBuilder is the context’s key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The kind and name attributes expect string values. Other attribute values can be booleans, numbers, strings, or arrays. If you enter a custom value on the Contexts list that looks like a number or a boolean, the SDK interprets it that way. The PHP SDK is strongly-typed, so be aware of this distinction.
Python
Expand Python code sample
Expand Python code sample
In version 8.0 and higher of the Python SDK, the Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If you have many attributes to set, you can also create a context from a dictionary:If an attribute is a JSON object, then in your flag or segment targeting, you can use
Context class has a create method for creating a context with a context kind of “user” and with only a key. It has a builder method for building a context with other properties.The argument to Context.builder is the context’s key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The optional name and kind attributes expect string values. If the “kind” attribute is not specified, it is assumed to be “user.” Other attribute values can be booleans, numbers, strings, arrays, or objects.
/ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn more, read from_dict.To learn how to configure private attributes in the Python SDK, read Private attributes.To learn how to configure anonymous contexts in the Python SDK, read Anonymous contexts and users.Ruby
Expand Ruby code sample
Expand Ruby code sample
In the Ruby SDK, contexts are instances of Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If an attribute is a JSON object, then in your flag or segment targeting, you can use
LaunchDarkly::LDContext. Legacy users can continue to be provided as simple hashes.The key property is the context’s key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key, an email address, or a hash string, as long as the same context always has the same key. We recommend using a hash string if possible.Here’s an example:The optional name and kind attributes expect string values. If the “kind” attribute is not specified, it is assumed to be “user” and the hash is assumed to be in the legacy user format. Other attribute values can be booleans, numbers, strings, arrays, or objects. If you enter a custom value on the Contexts list that looks like a number or a boolean, the SDK interprets it that way.
/ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the Ruby SDK, read Private attributes.To learn how to configure anonymous contexts in the Ruby SDK, read Anonymous contexts and users.Rust
Expand Rust code sample
Expand Rust code sample
The Rust SDK defines a Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:To learn more about the available attributes, read If an attribute is a JSON object, then in your flag or segment targeting, you can use
Context struct and a ContextBuilder.The context key is the only mandatory context attribute. You can set the kind, or, if you do not set it, LaunchDarkly assumes that the context kind is “user.” The combination of key and kind must uniquely identify each context. For the key, you can use a primary key, a hash string, or some other value, as long as the same context always has the same key. We recommend using a hash string if possible.Here’s an example:Context and ContextBuilder.The optional name and kind attributes, which you can set with
.name() and .kind(), expect string values. Other attribute values can be any JSON type, including booleans, numbers, strings, arrays, or objects. These types are all represented by the AttributeValue type. The Rust SDK is strongly-typed, so be aware of this distinction./ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.To learn how to configure private attributes in the Rust SDK, read Private attributes.To learn how to configure anonymous contexts in the Rust SDK, read Anonymous contexts and users.