Peri

Peri is a data description library for Elixir, in the spirit of Clojure's Plumatic Schema and Metosin's Malli. A schema is plain Elixir data: atoms like :string, literals like {:literal, 42}, tuples, maps, keyword lists, composed however the data demands. There is no separate DSL to learn; the schema language is Elixir itself. Peri is data, Peri is Elixir.

Because schemas are data, they are programmable: the same definition can validate structs, coerce string params at the boundary, generate test data, export JSON Schema, build Ecto changesets, or render Phoenix forms.

Installation

defp deps do
[
{:peri, "~> 0.11.2"} # x-release-please-version
]
end

Quick Start

defmodule MyApp.Schemas do
import Peri
defschema :user, %{
name: {:required, :string},
age: {:integer, gte: 18},
role: {:enum, [:admin, :user, :guest]}
}
defschema :search, %{
page: {:coerce, :integer},
tags: {:coerce, {:list, :string}, split: ","}
}
end
MyApp.Schemas.user(%{name: "John", age: 25, role: :user})
# => {:ok, %{name: "John", age: 25, role: :user}}
# Boundary data arrives as strings; {:coerce, ...} types it.
MyApp.Schemas.search(%{"page" => "2", "tags" => "elixir,otp"})
# => {:ok, %{page: 2, tags: ["elixir", "otp"]}}

Features

Documentation

Why the Name "Peri"?

From the Greek "περί", meaning "around" or "about": the library wraps data structures with descriptions of what they must conform to.