Examples

May 3, 2026 ยท View on GitHub

Drop-in snippets for every common runtime. All of them produce the same output: a stable JSON envelope (schema v1) with the password, entropy, and crack-time estimate against a nation-state attacker.

LanguagePathStrategy
Gogo/Native โ€” calls pkg/secretgen directly
Pythonpython/Subprocess to the secretgenerator CLI
Node.jsnode/Subprocess via child_process.execFileSync
Rubyruby/Subprocess via Open3.capture2
Rustrust/Subprocess via std::process::Command
Bashbash/Pipe the JSON through jq

The non-Go snippets all --require-schema-version=1 so any future incompatible change at the CLI side fails loudly instead of silently mutating field shapes.

Prerequisites

Install the CLI once with whichever method you prefer:

brew install rafaelperoco/tap/secretgenerator
# or
npm install -g @secretgenerator/cli
# or
go install github.com/rafaelperoco/secretgenerator/cmd/secretgenerator@latest

Run

go run ./examples/go
python3 examples/python/generate.py
node examples/node/generate.mjs
ruby examples/ruby/generate.rb
( cd examples/rust && cargo run )
examples/bash/generate.sh

Each prints something like:

password: M)Eh8a!?gDWKK9xS:c6;3Wuz
entropy:  156.9 bits
crack:    2e+14 times the age of the universe (nation-state)