Official Elixir client for Chalk Online Queries. This library provides an easy way to integrate with Chalk's API for feature computation and serving.
Add chalk_elixir
to your list of dependencies in mix.exs
:
def deps do
[
{:chalk_elixir, "~> 0.0.12"}
]
end
Online queries are executed by calling Chalk.Query.online/2
and passing inputs and expected outputs as described in the Chalk API documentation.
{:ok, response} = Chalk.Query.online(%{
inputs: %{
"user.id": 1
},
outputs: [
"user.id",
"user.email",
"user.credit_score"
]
})
The query can include additional options:
{:ok, response} = Chalk.Query.online(%{
inputs: %{
"user.id": 1
},
outputs: [
"user.id",
"user.email",
"user.credit_score"
],
staleness: %{
"user.credit_score": "1d" # Allow data up to 1 day old
},
context: %{
environment: "production",
tags: ["high-priority"]
},
query_name: "user_profile_query" # For telemetry and observability
})
The response contains data, errors, and metadata:
%Chalk.Query.OnlineQueryResponse{
data: [
%Chalk.Query.FeatureResult{
field: "user.id",
value: 1,
meta: %Chalk.Query.FeatureMeta{...}
},
%Chalk.Query.FeatureResult{
field: "user.email",
value: "[email protected]",
meta: %Chalk.Query.FeatureMeta{...}
},
...
],
errors: [...],
meta: %Chalk.Query.QueryMeta{...}
}
The Chalk client supports two authentication methods:
Set the following environment variables:
CHALK_CLIENT_ID=your_client_id
CHALK_CLIENT_SECRET=your_client_secret
Optionally, you can set a default deployment:
DEPLOYMENT_ID=your_deployment_id
Pass credentials directly to the client:
Chalk.Query.online(
%{
inputs: %{
"user.id": 1
},
outputs: [
"user.id"
]
},
%{
client_id: "your_client_id",
secret: "your_client_secret",
deployment_id: "your_deployment_id" # Optional
}
)
Credentials can be generated on the Chalk dashboard or via API.
For detailed documentation, visit:
mix test
mix dialyzer
mix credo
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.