All Projects → whatyouhide → Saul

whatyouhide / Saul

Licence: isc
Data validation and conformation library for Elixir.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Saul

objectiv-analytics
Powerful product analytics for data teams, with full control over data & models.
Stars: ✭ 399 (+543.55%)
Mutual labels:  data-validation
changeset
(unreleased) Data validation with first-class and first-order labels in OCaml
Stars: ✭ 28 (-54.84%)
Mutual labels:  data-validation
Xtypejs
Elegant, highly efficient data validation for JavaScript.
Stars: ✭ 357 (+475.81%)
Mutual labels:  data-validation
IATI.cloud
The open-source IATI datastore for IATI data with RESTful web API providing XML, JSON, CSV output. It extracts and parses IATI XML files referenced in the IATI Registry and powered by Apache Solr.
Stars: ✭ 35 (-43.55%)
Mutual labels:  data-validation
form-binder-java
Java port of form-binder, a micro data binding and validating framework
Stars: ✭ 29 (-53.23%)
Mutual labels:  data-validation
validada
Another library for defensive data analysis.
Stars: ✭ 29 (-53.23%)
Mutual labels:  data-validation
Dry Schema
Coercion and validation for data structures
Stars: ✭ 249 (+301.61%)
Mutual labels:  data-validation
Pywhip
💂‍♂️ Python package to validate data against whip specifications
Stars: ✭ 5 (-91.94%)
Mutual labels:  data-validation
validation-components
A collection of common validation predicates for ValidationToolkit framework
Stars: ✭ 26 (-58.06%)
Mutual labels:  data-validation
Openapi Cop
A proxy that validates responses and requests against an OpenAPI document.
Stars: ✭ 338 (+445.16%)
Mutual labels:  data-validation
check-engine
Data validation library for PySpark 3.0.0
Stars: ✭ 29 (-53.23%)
Mutual labels:  data-validation
pyvaru
Rule based data validation library for python 3.
Stars: ✭ 17 (-72.58%)
Mutual labels:  data-validation
Validus
A dead simple Python string validation library.
Stars: ✭ 257 (+314.52%)
Mutual labels:  data-validation
form-binder
A micro data binding and validating framework, very easy to use and hack
Stars: ✭ 18 (-70.97%)
Mutual labels:  data-validation
Pointblank
Data validation and organization of metadata for data frames and database tables
Stars: ✭ 480 (+674.19%)
Mutual labels:  data-validation
minimallist
A minimalist data driven data model library, inspired by Clojure Spec and Malli.
Stars: ✭ 63 (+1.61%)
Mutual labels:  data-validation
data-validator
A tool to validate data built around Apache Spark.
Stars: ✭ 66 (+6.45%)
Mutual labels:  data-validation
Dry Validation
Validation library with type-safe schemas and rules
Stars: ✭ 1,087 (+1653.23%)
Mutual labels:  data-validation
Pandera
A light-weight, flexible, and expressive pandas data validation library
Stars: ✭ 506 (+716.13%)
Mutual labels:  data-validation
Laravel Recaptcha
Google ReCaptcha package for Laravel
Stars: ✭ 273 (+340.32%)
Mutual labels:  data-validation

Saul

Build Status

Data validation and conformation library for Elixir.

Cover image

Saul is a data validation and conformation library. It tries to solve the problem of validating the shape and content of some data (most useful when such data come from an external source) and of conforming those data to arbitrary formats.

The goal of Saul is to provide a declarative and composable way to define data validation/conformation. The basic unit of validation is a validator which is either a function or a term that implements the Saul.Validator protocol. The return value of validator functions or implementations of Saul.Validator.validate/2 has to be either {:ok, transformed} to signify a successful validation and conformation, {:error, term} to signify a failed validation with a given reason, or a boolean to signify just successful/failed validation with no conformation step. These return values have been chosen because of their widespread presence in Elixir and Erlang code: for example, allowing to return booleans means any predicate function (such as String.valid?/1) can be used as validator.

Validators can be a powerful abstraction because they're easy to combine: for example, the Saul.one_of/1 combinator takes a list of validators and returns a validator that passes if one of the given validators pass. Saul provides both "basic" validators as well as validator combinators, as well as a single entry point to validate data (Saul.validate/2). See the documentation for detailed information on all the provided features.

Installation

Add the :saul dependency to your mix.exs file:

defp deps() do
  [{:saul, "~> 0.1"}]
end

If you're not using :extra_applications from Elixir 1.4 and above, also add :saul to your list of applications:

defp application() do
  [applications: [:logger, :saul]]
end

Then, run mix deps.get in your shell to fetch the new dependency.

Usage

Validators are just data structures that can be moved around. You can create arbitrarely complex ones:

string_to_integer =
  fn string ->
    case Integer.parse(string) do
      {int, ""} -> {:ok, int}
      _other -> {:error, "not parsable as integer"}
    end
  end
  |> Saul.named_validator("string_to_integer")

stringy_integer = Saul.all_of([
  &is_binary/1,
  string_to_integer,
])

Now you can use them to validate data:

iex> Saul.validate!("123", stringy_integer)
123
iex> Saul.validate!("nope", stringy_integer)
** (Saul.Error) (string_to_integer) not parsable as integer - failing term: "nope"

Contributing

Clone the repository and run $ mix test. To generate docs, run $ mix docs.

License

Saul is released under the ISC license, see the LICENSE file.

Attribution

Many ideas in this library are inspired by clojure.spec.

A special thanks for the feedback and encouragement goes to the awesome @lexmag, as well as to @josevalim, @ericmj, and @michalmuskala.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].