Programming in YAML
> /plugin marketplace add yaml/yamlscript> /plugin install ys-skill@yamlscript
Repo: yaml/yamlscript
What's inside
Program in YAML β Code is Data
YS (aka YAMLScript) is a YAML loader (with Functional Programming Capabilities) for 32 (and counting) programming languages:
Ada, C#, Clojure, Crystal, D, Dart, Delphi (Free Pascal), Dyalog APL, Elixir, Erlang, F#, Fortran, Go, Haskell, Java, Julia, Kotlin, Lua, MoonBit, Nim, NodeJS, Perl, PHP, PowerShell, Python, R, Raku, Ruby, Rust, Scala, Swift and Zig.
Try using YS in place of your current YAML loader!
How can YS offer all this?
YS is also a functional programming language!
Like PyYAML and many other YAML loaders, YS is implemented to the YAML 1.2 specification. But instead of loading YAML into directly into its intended data structure, a YS loader loads YAML into a Lisp AST (abstract syntax tree) data structure. The AST is then rendered into Lisp code and evaluated by a full-featured runtime, resulting in the intended data structure.
The specific Lisp is Clojure, which is very capable, mature and well-documented programming language with a large ecosystem of libraries and tools.
Note: You may be aware that Clojure is a JVM hosted language (and also a JavaScript hosted one via ClojureScript), but YS doesn't need either of those. YS is compiled to a native binary executable and also a native shared library. The shared library can be used by nearly any programming language, including the ones listed above.
Not only can you use YS as a loader library from a programming language, but you
can also use it from the command line with the ys command.
YS is awesome for:
YS is an official language on the
Exercism (free) language learning site!
It's a great way to learn how to program in YS.
First you'll need to install ys and/or libys.
You can install them both persistently with this single command:
source <(curl -sL https://in-1.cc) --local ys libys
See Installing YS for full details.
Now say you have a file called file.yaml that looks like this:
name: Fido
age: 6
dog years: 42
likes: [running, fetching, playing, treats]
You can load it with:
ys --json file.yaml
And get this output:
{"name":"Fido",
"age":6,
"dog years":42,
"likes":["fetching", "playing", "running", "treats"]}
Nothing special here. YS is 100% compatible with existing YAML files, so this is just what you'd expect.
But here's where it gets interesting... Let's say you want to add some dynamic logic:
!ys-0:
age =: 6
name: Fido
age:: age
dog years:: age * 7
likes::
sort:: [running, fetching, playing, treats]
The first line is a special tag that tells YS that this file may contain code.
The age =: 6 sets a variable, and the :: tells YS that the value is a code
expression, not a data value.
We've also used the standard sort function to sort the likes list.
Let's load it via a Python using the yamlscript.py module this time:
python3 -c '
import json, yamlscript;
print(json.dumps(yamlscript.YAMLScript()
.load(open("file.yaml").read())))'
{"name": "Fido", "age": 6, "dog years": 42,
"likes": ["fetching", "playing", "running", "treats"]}
The good stuff is all sorted and the dog years are calculated automatically!
Want to merge multiple YAML files with environment variable overrides?
!ys-0:
config =:
merge:
load: 'base-config.yaml'
load: 'prod-config.yaml'
database:
host:: config.database.host
port:: config.database.port || 5432
ssl:: ENV.environment == 'production'
Need to transform data from an API?
!ys-0:
users =: http/get('https://api.example.com/users'):json/load
active-users::
map user-data:
filter users:
fn(u):
(u.status == 'active') &&
(u.lastLogin > date('-30d'))
defn user-data(u)::
name:: "$(u.firstName) $(u.lastName)"
email:: u.email
role:: u.role:uc
There are two primary ways to use YS:
ys command line runner / loader / compiler / installerThe ys command line tool is the easiest way to get started with YS.
You can use it to load / evaluate / transform YAML files and print the result as
YAML, JSON, CSV, TSV, or EDN.
Or you can use it to run programs written in YS.
You can also use YS as a library in your own programming language.
For example, in Python you can use the yamlscript module like this:
from yamlscript import YAMLScript
ys = YAMLScript()
text = open("foo.yaml").read()
data = ys.load(text)
YS is supported on these operating systems:
Release executables are available for these platform and architecture pairs:
x86_64 and aarch64x86_64The native ys executable and libys shared library use Gloat and Glojure and
do not require Java or a JVM.
The WASI release contains the ys executable only.
Here's some examples of how to use YS in a few different programming languages. Usage in other languages is similar.
Python:
import yamlscript
ys = yamlscript.YAMLScript()
config = ys.load(open('config.yaml').read())
JavaScript/Node:
YS = require('@yaml/yamlscript');
ys = new YS();
config = ys.load(fs.readFileSync('config.yaml', 'utf8'));
Go:
import "github.com/yaml/yamlscript-go"
data, err := ys.Load(yamlContent)
Ruby:
require 'yamlscript'
ys = YAMLScript.new
config = ys.load(File.read('config.yaml'))
YS has an official Claude Code plugin that teaches Claude to write idiomatic YAMLScript. Install it in Claude Code with:
/plugin marketplace add yaml/yamlscript
/plugin install ys-skill@yamlscript
See ai/claude/ReadMe.md for more details.
The YS source code repository is a mono-repo containing:
make It SoThe YS repository uses a Makefile system to build, test and install its
various offerings.
It installs (locally within this directory) all the dependencies you need to
build and test YS, including every programming language needed by the bindings.
There is a top level Makefile and each repo subdirectory has its own
Makefile.
When run at the top level, many make targets like test, build, install,
clean, distclean, etc will invoke that target in each relevant subdirectory.
Given that this repository has so few dependencies, you should be able to clone
it and run make targets (try make test) without any problems.
This project aims to have a binding implementation for each every programming language where YAML is used.
If you would like to contribute a new YS binding for a programming language, you are encouraged to submit a pull request to this repository.
See the YS Contributing Guide for more details.
FAQ
yamlscript is a Claude Code plugin with 1 hand-picked skill for development work, indexed on Flowy. Install it with the command on its page. It includes yamlscript. Its skills do not fire on their own yet. Request auto-invocation to have Flowy route them as you prompt. Free and open source.
Is this plugin yours?
Claim it with GitHubSubmit a pluginPromote it