kata

kata — A bidirectional schema library for Gleam. Define your data shape once, decode and encode with the same definition.

The name comes from the Japanese word “型” (kata), meaning “form” or “mold” — defining the correct shape for your data.

Installation

gleam add kata

Quick Start

import kata
import kata/refine

pub type User {
  User(name: String, email: String, age: Int)
}

pub fn user_schema() -> kata.Schema(User) {
  use name <- kata.field(
    "name",
    kata.string() |> refine.min_length(1),
    fn(u: User) { u.name },
  )
  use email <- kata.field("email", kata.string(), fn(u: User) { u.email })
  use age <- kata.field(
    "age",
    kata.int() |> refine.min(0) |> refine.max(150),
    fn(u: User) { u.age },
  )
  kata.done(User(name:, email:, age:))
}

// Decode
let value = kata.decode(user_schema(), some_value)

// Encode
let encoded = kata.encode(user_schema(), User("Alice", "a@b.com", 30))

Features

JSON Support

For JSON encoding/decoding, use the companion package kata_json:

gleam add kata_json

v0.1 Scope

This is the initial release. It includes:

Roadmap

Relation to Other Libraries

kata fills a different niche than existing Gleam schema libraries:

Development

gleam test  # Run the tests
Search Document