{"id":13412748,"url":"https://github.com/d5/tengo","last_synced_at":"2025-04-23T20:54:20.196Z","repository":{"id":37580086,"uuid":"164809872","full_name":"d5/tengo","owner":"d5","description":"A fast script language for Go","archived":false,"fork":false,"pushed_at":"2024-04-23T11:42:39.000Z","size":927,"stargazers_count":3631,"open_issues_count":84,"forks_count":311,"subscribers_count":59,"default_branch":"master","last_synced_at":"2025-04-23T20:54:03.720Z","etag":null,"topics":["compiler","embedded-language","go","golang","programming-language","script","tengo","vm"],"latest_commit_sha":null,"homepage":"https://tengolang.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-09T07:17:17.000Z","updated_at":"2025-04-23T19:11:32.000Z","dependencies_parsed_at":"2024-06-18T11:18:02.496Z","dependency_job_id":null,"html_url":"https://github.com/d5/tengo","commit_stats":{"total_commits":308,"total_committers":41,"mean_commits":7.512195121951219,"dds":"0.36363636363636365","last_synced_commit":"c461a7fe6043d451d222406fdda3d39438653fea"},"previous_names":[],"tags_count":102,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d5%2Ftengo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d5%2Ftengo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d5%2Ftengo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d5%2Ftengo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d5","download_url":"https://codeload.github.com/d5/tengo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514767,"owners_count":21443208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","embedded-language","go","golang","programming-language","script","tengo","vm"],"created_at":"2024-07-30T20:01:28.693Z","updated_at":"2025-04-23T20:54:20.172Z","avatar_url":"https://github.com/d5.png","language":"Go","readme":"# The Tengo Language\n\n[![GoDoc](https://godoc.org/github.com/d5/tengo/v2?status.svg)](https://godoc.org/github.com/d5/tengo/v2)\n![test](https://github.com/d5/tengo/workflows/test/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/d5/tengo)](https://goreportcard.com/report/github.com/d5/tengo)\n\n**Tengo is a small, dynamic, fast, secure script language for Go.** \n\nTengo is **[fast](#benchmark)** and secure because it's compiled/executed as\nbytecode on stack-based VM that's written in native Go.\n\n```golang\n/* The Tengo Language */\nfmt := import(\"fmt\")\n\neach := func(seq, fn) {\n    for x in seq { fn(x) }\n}\n\nsum := func(init, seq) {\n    each(seq, func(x) { init += x })\n    return init\n}\n\nfmt.println(sum(0, [1, 2, 3]))   // \"6\"\nfmt.println(sum(\"\", [1, 2, 3]))  // \"123\"\n```\n\n\u003e Test this Tengo code in the\n\u003e [Tengo Playground](https://tengolang.com/?s=0c8d5d0d88f2795a7093d7f35ae12c3afa17bea3)\n\n## Features\n\n- Simple and highly readable\n  [Syntax](https://github.com/d5/tengo/blob/master/docs/tutorial.md)\n  - Dynamic typing with type coercion\n  - Higher-order functions and closures\n  - Immutable values\n- [Securely Embeddable](https://github.com/d5/tengo/blob/master/docs/interoperability.md)\n  and [Extensible](https://github.com/d5/tengo/blob/master/docs/objects.md)\n- Compiler/runtime written in native Go _(no external deps or cgo)_\n- Executable as a\n  [standalone](https://github.com/d5/tengo/blob/master/docs/tengo-cli.md)\n  language / REPL\n- Use cases: rules engine, [state machine](https://github.com/d5/go-fsm),\n  data pipeline, [transpiler](https://github.com/d5/tengo2lua)\n\n## Benchmark\n\n| | fib(35) | fibt(35) |  Language (Type)  |\n| :--- |    ---: |     ---: |  :---: |\n| [**Tengo**](https://github.com/d5/tengo) | `2,315ms` | `3ms` | Tengo (VM) |\n| [go-lua](https://github.com/Shopify/go-lua) | `4,028ms` | `3ms` | Lua (VM) |\n| [GopherLua](https://github.com/yuin/gopher-lua) | `4,409ms` | `3ms` | Lua (VM) |\n| [goja](https://github.com/dop251/goja) | `5,194ms` | `4ms` | JavaScript (VM) |\n| [starlark-go](https://github.com/google/starlark-go) | `6,954ms` | `3ms` | Starlark (Interpreter) |\n| [gpython](https://github.com/go-python/gpython) | `11,324ms` | `4ms` | Python (Interpreter) |\n| [Yaegi](https://github.com/containous/yaegi) | `11,715ms` | `10ms` | Yaegi (Interpreter) |\n| [otto](https://github.com/robertkrimen/otto) | `48,539ms` | `6ms` | JavaScript (Interpreter) |\n| [Anko](https://github.com/mattn/anko) | `52,821ms` | `6ms` | Anko (Interpreter) |\n| - | - | - | - |\n| Go | `47ms` | `2ms` | Go (Native) |\n| Lua | `756ms` | `2ms` | Lua (Native) |\n| Python | `1,907ms` | `14ms` | Python2 (Native) |\n\n_* [fib(35)](https://github.com/d5/tengobench/blob/master/code/fib.tengo):\nFibonacci(35)_  \n_* [fibt(35)](https://github.com/d5/tengobench/blob/master/code/fibtc.tengo):\n[tail-call](https://en.wikipedia.org/wiki/Tail_call) version of Fibonacci(35)_  \n_* **Go** does not read the source code from file, while all other cases do_  \n_* See [here](https://github.com/d5/tengobench) for commands/codes used_\n\n## Quick Start\n\n```\ngo get github.com/d5/tengo/v2\n```\n\nA simple Go example code that compiles/runs Tengo script code with some input/output values:\n\n```golang\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/d5/tengo/v2\"\n)\n\nfunc main() {\n\t// create a new Script instance\n\tscript := tengo.NewScript([]byte(\n`each := func(seq, fn) {\n    for x in seq { fn(x) }\n}\n\nsum := 0\nmul := 1\neach([a, b, c, d], func(x) {\n    sum += x\n    mul *= x\n})`))\n\n\t// set values\n\t_ = script.Add(\"a\", 1)\n\t_ = script.Add(\"b\", 9)\n\t_ = script.Add(\"c\", 8)\n\t_ = script.Add(\"d\", 4)\n\n\t// run the script\n\tcompiled, err := script.RunContext(context.Background())\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// retrieve values\n\tsum := compiled.Get(\"sum\")\n\tmul := compiled.Get(\"mul\")\n\tfmt.Println(sum, mul) // \"22 288\"\n}\n```\n\nOr, if you need to evaluate a simple expression, you can use [Eval](https://pkg.go.dev/github.com/d5/tengo/v2#Eval) function instead:\n\n\n```golang\nres, err := tengo.Eval(ctx,\n\t`input ? \"success\" : \"fail\"`,\n\tmap[string]interface{}{\"input\": 1})\nif err != nil {\n\tpanic(err)\n}\nfmt.Println(res) // \"success\"\n```\n\n## References\n\n- [Language Syntax](https://github.com/d5/tengo/blob/master/docs/tutorial.md)\n- [Object Types](https://github.com/d5/tengo/blob/master/docs/objects.md)\n- [Runtime Types](https://github.com/d5/tengo/blob/master/docs/runtime-types.md)\n  and [Operators](https://github.com/d5/tengo/blob/master/docs/operators.md)\n- [Builtin Functions](https://github.com/d5/tengo/blob/master/docs/builtins.md)\n- [Interoperability](https://github.com/d5/tengo/blob/master/docs/interoperability.md)\n- [Tengo CLI](https://github.com/d5/tengo/blob/master/docs/tengo-cli.md)\n- [Standard Library](https://github.com/d5/tengo/blob/master/docs/stdlib.md)\n- Syntax Highlighters: [VSCode](https://github.com/lissein/vscode-tengo), [Atom](https://github.com/d5/tengo-atom), [Vim](https://github.com/geseq/tengo-vim)\n- **Why the name Tengo?** It's from [1Q84](https://en.wikipedia.org/wiki/1Q84).\n\n\n","funding_links":[],"categories":["开源类库","Embeddable Scripting Languages","Go","Open source library","脚本语言与嵌入式编程","可嵌入的脚本语言","脚本语言与嵌入式编程`在你的go代码中嵌入其他脚本语言`","Other","Relational Databases","Repositories"],"sub_categories":["解释器","Search and Analytic Databases","Interpreter","SQL 查询语句构建库","Advanced Console UIs","检索及分析资料库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd5%2Ftengo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd5%2Ftengo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd5%2Ftengo/lists"}