{"id":17720231,"url":"https://github.com/starlight-go/starlight","last_synced_at":"2026-01-12T02:35:56.320Z","repository":{"id":46588804,"uuid":"105833862","full_name":"starlight-go/starlight","owner":"starlight-go","description":"a go wrapper for google's starlark embedded python language","archived":false,"fork":false,"pushed_at":"2024-05-17T04:45:26.000Z","size":214,"stargazers_count":299,"open_issues_count":18,"forks_count":29,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-06-18T14:09:09.083Z","etag":null,"topics":["go","golang","python","scripting","starlark"],"latest_commit_sha":null,"homepage":"","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/starlight-go.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":"2017-10-05T00:33:01.000Z","updated_at":"2024-06-12T14:28:07.000Z","dependencies_parsed_at":"2024-06-18T13:53:59.281Z","dependency_job_id":"dba77e21-1015-47ec-9cf6-a7af387b3a6b","html_url":"https://github.com/starlight-go/starlight","commit_stats":null,"previous_names":["hippogryph/skyhook","natefinch/skyhook","go-skyhook/skyhook"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starlight-go%2Fstarlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starlight-go%2Fstarlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starlight-go%2Fstarlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starlight-go%2Fstarlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/starlight-go","download_url":"https://codeload.github.com/starlight-go/starlight/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243526270,"owners_count":20305107,"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":["go","golang","python","scripting","starlark"],"created_at":"2024-10-25T15:26:33.588Z","updated_at":"2026-01-12T02:35:56.297Z","avatar_url":"https://github.com/starlight-go.png","language":"Go","readme":"# \u003cimg src=\"https://user-images.githubusercontent.com/3185864/49534746-5b90de80-f890-11e8-9fd6-5417cf915c67.png\"/\u003e Starlight [![GoDoc](https://godoc.org/github.com/starlight-go/starlight?status.svg)](https://godoc.org/github.com/starlight-go/starlight) [![Build Status](https://travis-ci.org/starlight-go/starlight.svg?branch=master)](https://travis-ci.org/starlight-go/starlight)\n\n\n\u003cp align=\"center\" style=\"font-weight:bold\"\u003e!! Starlight is still a WIP !!\u003cp/\u003e\n\n\nStarlight is a wrapper library for google's [starlark](https://github.com/google/starlark-go)\nembedded python-like language. Starlight is intended to give you an easier-to-use\ninterface for running starlark scripts directly from your Go programs.  Starlark\nis a dialect of python, and has a Go native interpreter, so you can let your\nusers extend your application without any external requirements.\n\n\n## Sample\n\nYou can call a script from go thusly:\n\n```go\n\nimport (\n    \"fmt\"\n    \"github.com/starlight-go/starlight\"\n)\n\ntype contact struct {\n    Name string\n}\n\nfunc main() {\n    c := \u0026contact{Name: \"Bob\"}\n    globals := map[string]interface{}{\n        \"contact\":c, \n        \"Println\":fmt.Println,\n    }\n\n    script := []byte(`\ncontact.Name = \"Phil\"\nPrintln(\"hello \" + contact.Name)\n`)\n    // errors will tell you about syntax/runtime errors.\n    _, err := starlight.Eval(script, globals, nil)\n}\n\n// prints \"hello Phil\"\n// also the value of c's Name field will now be Phil when referenced from Go code as well.\n```\n\nEval expects either a filename, slice of bytes, or io.Reader as its argument\ncontaining the code, and then a map of global variables to populate the script\nwith.\n\n## Usage\n\nStarlight.New creates a script cache that will read and compile scripts on the fly, caching those it has already run.\n\nStarlight.Eval does all the compilation at call time.\n\n## Inputs and Outputs\n\nStarlark scripts (and starlight scripts by extension) use global variables in the\nscript as the input.\n\nThus if args are `map[string]interface{}{\"input\":\"hello\"}`, the script may act\non the variable called input thusly:\n\n```python\noutput = input + \"world!\"\n```\n\nWhen run, this script will create a value in the map returned with the\nkey \"output\" and with the value \"hello world!\".\n\n## Types\n\nStarlight automatically translates go types to starlark types. Starlight\nsupports almost every go type except channels.   You may also pass in types that\nimplement starlark.Value themselves, in which case they will be passed to the\nscript as-is (this is useful if you need custom behavior).\n\n## Functions\n\nYou can pass go functions that the script can call by passing your function in\nwith the rest of the globals. Positional args are passed to your function and\nconverted to their appropriate go type if possible. Kwargs passed from starlark\nscripts are currently ignored.\n\n## Caching\n\nSince parsing scripts is non-zero work, starlight caches the scripts it finds\nafter the first time they get run, so that further runs of the script will not\nincur the disk read and parsing overhead. To make starlight reparse a file\n(perhaps because it has changed) use the Forget method for the specific file, or\nReset to remove all cached files.\n\n## Example\n\nThe [example](https://github.com/starlight-go/starlight/tree/master/example)\ndirectory shows an example of using starlight to run scripts that modify the\noutput of a running web server.\n\n## Why?\n\n**Why not just use starlark-go directly?**\n\nWell, it's actually quite difficult to get go data *into* a starlark-go script. Starlark as written is made more for configuration, so you mostly get data *out* of scripts, and mostly just basic values.\n\nFor example, structs just aren't supported, unless you write a complicated wrapper (starlight does that for you). Adapting a function to starlark-go requires a bunch of boilerplate adapter and conversion code, and then if you're using anything other than basic types (int, string, bool, float, etc), you need adapters for those, too (starlight does that for you, too).\n\n**Why embed python in your Go application?**\n\nBecause it lets you add flexibility without having to recompile.  It lets users customize your application with just a few lines of python.\n\nAlso, Starlark is *safe*.  You can run arbitrary code from third parties without worrying about it blowing up your machine or downloading nasty things from the internet (unless you give scripts the ability to do that).  Starlark code can only call the functions you allow.\n\n## How?\n\nLots of reflection.  It's not as slow as you think.  Running a small pre-compiled script including the time to process the inputs using reflection, takes less than 2400ns on my 2017 macbook pro (that's 0.0024 milliseconds). \n","funding_links":[],"categories":["Go","Libraries and extensions"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarlight-go%2Fstarlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarlight-go%2Fstarlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarlight-go%2Fstarlight/lists"}