expr alternatives and similar packages
Based on the "Embeddable Scripting Languages" category.
Alternatively, view expr alternatives based on common mentions on social networks and blogs.
-
starlark-go
Starlark in Go: the Starlark configuration language, implemented in Go -
cel-go
Fast, portable, non-Turing complete expression evaluation with gradual typing (Go) -
Gentee script programming language
Gentee - script programming language for automation. It uses VM and compiler written in Go (Golang). -
ecal
A simple embeddable scripting language which supports concurrent event processing. -
ngaro
An embeddable implementation of the Ngaro Virtual Machine for Go programs
Static code analysis for 29 languages.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of expr or a related project?
Popular Comparisons
README
Expr
Expr package provides an engine that can compile and evaluate expressions. An expression is a one-liner that returns a value (mostly, but not limited to, booleans). It is designed for simplicity, speed and safety.
The purpose of the package is to allow users to use expressions inside configuration for more complex logic. It is a perfect candidate for the foundation of a business rule engine. The idea is to let configure things in a dynamic way without recompile of a program:
# Get the special price if
user.Group in ["good_customers", "collaborator"]
# Promote article to the homepage when
len(article.Comments) > 100 and article.Category not in ["misc"]
# Send an alert when
product.Stock < 15
Features
- Seamless integration with Go (no need to redefine types)
- Static typing (example).
go out, err := expr.Compile(`name + age`) // err: invalid operation + (mismatched types string and int) // | name + age // | .....^
- User-friendly error messages.
- Reasonable set of basic operators.
- Builtins
all
,none
,any
,one
,filter
,map
.coffeescript all(Tweets, {.Size <= 280})
- Fast (benchmarks): uses bytecode virtual machine and optimizing compiler.
Install
go get github.com/antonmedv/expr
Documentation
- See [Getting Started](docs/Getting-Started.md) page for developer documentation.
- See [Language Definition](docs/Language-Definition.md) page to learn the syntax.
Expr Code Editor
Also, I have an embeddable code editor written in JavaScript which allows editing expressions with syntax highlighting and autocomplete based on your types declaration.
Examples
package main
import (
"fmt"
"github.com/antonmedv/expr"
)
func main() {
env := map[string]interface{}{
"greet": "Hello, %v!",
"names": []string{"world", "you"},
"sprintf": fmt.Sprintf,
}
code := `sprintf(greet, names[0])`
program, err := expr.Compile(code, expr.Env(env))
if err != nil {
panic(err)
}
output, err := expr.Run(program, env)
if err != nil {
panic(err)
}
fmt.Println(output)
}
package main
import (
"fmt"
"github.com/antonmedv/expr"
)
type Tweet struct {
Len int
}
type Env struct {
Tweets []Tweet
}
func main() {
code := `all(Tweets, {.Len <= 240})`
program, err := expr.Compile(code, expr.Env(Env{}))
if err != nil {
panic(err)
}
env := Env{
Tweets: []Tweet{{42}, {98}, {69}},
}
output, err := expr.Run(program, env)
if err != nil {
panic(err)
}
fmt.Println(output)
}
Who uses Expr?
- Aviasales uses Expr as a business rule engine for our flight search engine.
- Wish.com uses Expr for decision-making rule engine in the Wish Assistant.
- Argo uses Expr in Argo Rollouts and Argo Workflows for Kubernetes.
- Crowdsec uses Expr in a security automation tool.
- FACEIT uses Expr to allow customization of its eSports matchmaking algorithm.
- qiniu uses Expr in trade systems.
- OpenTelemetry uses Expr in the OpenTelemetry Collector.
- Philips Labs uses Expr in Tabia, a tool for collecting insights on the characteristics of our code bases.
- CodeDNS uses Expr in CoreDNS, a DNS server.
- Chaos Mesh uses Expr in Chaos Mesh, a cloud-native Chaos Engineering platform.
- Milvus uses Expr in Milvus, an open-source vector database.
- Visually.io uses Expr as a business rule engine for our personalization targeting algorithm.
License
[MIT](LICENSE)
*Note that all licence references and agreements mentioned in the expr README section above
are relevant to that project's source code only.