View Source Chalk Elixir

Official Elixir client for Chalk Online Queries. This library provides an easy way to integrate with Chalk's API for feature computation and serving.
installation
Installation
Add chalk_elixir to your list of dependencies in mix.exs:
def deps do
[
{:chalk_elixir, "~> 0.0.12"}
]
end
usage
Usage
basic-query
Basic Query
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"
]
})
advanced-options
Advanced Options
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
})
response-structure
Response Structure
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: "user@example.com",
meta: %Chalk.Query.FeatureMeta{...}
},
...
],
errors: [...],
meta: %Chalk.Query.QueryMeta{...}
}
authentication
Authentication
The Chalk client supports two authentication methods:
environment-variables
Environment Variables
Set the following environment variables:
CHALK_CLIENT_ID=your_client_id
CHALK_CLIENT_SECRET=your_client_secretOptionally, you can set a default deployment:
DEPLOYMENT_ID=your_deployment_id
explicit-credentials
Explicit Credentials
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.
documentation
Documentation
For detailed documentation, visit:
development
Development
running-tests
Running Tests
mix test
linting
Linting
mix dialyzer
mix credo
license
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.