This guide will help you create and run your first Pocket workflow in under 5 minutes.
- Pocket CLI installed (Installation Guide)
- A text editor
- Basic understanding of YAML
Create a file named hello.yaml:
name: hello-world
description: My first Pocket workflow
version: "1.0.0"
start: greet
nodes:
- name: greet
type: echo
config:
message: "Hello from Pocket!"pocket run hello.yamlYou should see:
Hello from Pocket!
Congratulations! You've run your first Pocket workflow.
Let's break down what happened:
- name: Identifies your workflow
- start: The first node to execute
- nodes: List of operations to perform
- type: echo: Built-in node that outputs a message
Let's create a workflow that processes data through multiple steps:
Create process-data.yaml:
name: data-processor
description: Process data through multiple steps
start: fetch
nodes:
- name: fetch
type: echo
config:
message: '{"name": "pocket user", "score": 85}'
- name: parse
type: transform
config:
jq: ". | fromjson"
- name: check-score
type: conditional
config:
conditions:
- if: "{{gt .score 90}}"
then: excellent
- if: "{{gt .score 70}}"
then: good
else: needs-improvement
- name: excellent
type: template
config:
template: "🌟 Excellent work, {{.name}}! Score: {{.score}}"
- name: good
type: template
config:
template: "👍 Good job, {{.name}}! Score: {{.score}}"
- name: needs-improvement
type: template
config:
template: "📚 Keep studying, {{.name}}. Score: {{.score}}"
connections:
- from: fetch
to: parse
- from: parse
to: check-scorepocket run process-data.yaml --verboseThis workflow:
- Starts with JSON data
- Parses it into a structure
- Checks the score with conditions
- Routes to different responses
- Formats output with templates
Create fetch-weather.yaml:
name: weather-checker
start: fetch-weather
nodes:
- name: fetch-weather
type: http
config:
url: "https://api.open-meteo.com/v1/forecast"
method: GET
params:
latitude: "40.7128"
longitude: "-74.0060"
current_weather: "true"
- name: extract-temp
type: jsonpath
config:
path: "$.current_weather.temperature"
- name: format-output
type: template
config:
template: "Current temperature in NYC: {{.}}°C"
connections:
- from: fetch-weather
to: extract-temp
- from: extract-temp
to: format-outputRun it:
pocket run fetch-weather.yamlCreate process-file.yaml:
name: file-processor
start: read
nodes:
- name: read
type: file
config:
path: "./data.txt"
operation: read
- name: transform
type: transform
config:
jq: ". | ascii_upcase"
- name: write
type: file
config:
path: "./output.txt"
operation: write
connections:
- from: read
to: transform
- from: transform
to: writeCreate a Lua script at ~/.pocket/scripts/custom.lua:
-- @name: custom-processor
-- @description: Custom data processing
function exec(input)
local data = input.data or "none"
return {
processed = true,
original = data,
timestamp = os.time()
}
endUse it in a workflow:
name: lua-example
start: process
nodes:
- name: process
type: custom-processor
config:
data: "test input"See detailed execution information:
pocket run workflow.yaml --verboseValidate without executing:
pocket run workflow.yaml --dry-run# List all available nodes
pocket nodes list
# Get details about a specific node
pocket nodes info httpnodes:
- name: risky-operation
type: http
config:
url: "https://api.example.com/data"
timeout: "5s"
retry:
max_attempts: 3
delay: "1s"nodes:
- name: parallel-tasks
type: parallel
config:
tasks:
- name: task1
node: http
config:
url: "https://api1.example.com"
- name: task2
node: http
config:
url: "https://api2.example.com"Now that you understand the basics:
- Explore all built-in nodes
- Learn the YAML schema
- Install plugins
- View more examples
- Read the command reference
- Start Simple: Begin with echo nodes to understand flow
- Use Verbose Mode:
--verbosehelps debug issues - Check Examples: The
examples/cli/directory has many patterns - Validate First: Use
--dry-runbefore running complex workflows - Modular Design: Break complex workflows into smaller pieces