Skip to main content

cliyard

CLI + YAML + Yard — a framework that generates CLI commands from YAML specs. Define your REST API in a few YAML files, and cliyard produces a fully-structured Click CLI with parameters, types, response formatting, and auto-generated help.

Installation

pip install cliyard

# Or for development
pip install -e .

Quick Start

# Generate a CLI from spec files
cliyard gen --name mycli --defs-path ./specs/
cd mycli && pip install -e .

# Use it
mycli --help
mycli repos list --page-size 10

How It Works

cliyard turns a directory of YAML files into CLI commands. One directory equals one API service. Each YAML file becomes a resource group with subcommands for every defined method.

specs/
├── _auth.yaml              # Service config: name, servers, auth chain
├── _groups.yaml            # (optional) Group definitions for nesting
├── _flows.yaml             # (optional) Flow orchestration index
├── resources/              # Resource YAML files
│   ├── repos.yaml
│   └── ...
├── flows/                  # (optional) Flow step definitions
│   ├── _flow_create_repo.yaml
│   └── ...
└── plugins/                # Python plugins
    └── *.py

Data flow for a single invocation:

CLI input → bind & validate → auth chain → assemble request → HTTP call → format response

Features

  • YAML-driven: Add a new API resource by creating a .yaml file, no code changes
  • Plugin system: 7 extension points for auth, types, hooks, methods, commands, field resolvers, flow steps
  • Flow orchestration: Define multi-step workflows with conditional branching, loops, and lifecycle hooks
  • Multi-server: Support multiple API endpoints in a single CLI
  • Rich output: Tables, JSON, CSV formatting with datetime conversion
  • Resource grouping: Nest related commands under parent groups

Web UI (cliyard serve)

cliyard serve 以 Web 方式启动 spec 目录:命令自动渲染为表单,执行过程以步骤流实时展示,并保留可重放的执行历史。

用法

cliyard serve ./specs
cliyard serve examples/demo --port 8080 --host 0.0.0.0
cliyard serve examples/demo --open --reload

选项

选项 默认值 说明
--host 127.0.0.1 绑定地址
--port 8080 监听端口
--open 关闭 启动后自动打开浏览器
--reload 关闭 uvicorn 自动重载(配合前端开发)

前端构建

静态资源由 FastAPI 托管,首次使用前需构建前端:

cd webui && npm install && npm run build

未构建时访问 / 返回提示 JSON(而非 500)。开发模式可在 webui/ 下运行 npm run dev(Vite 默认 5173 端口,已配置 CORS)。

API 一览

方法 路径 说明
GET /api/spec 命令树 + flow 元数据(含 JSON Schema)
POST /api/execute 提交命令/流程执行,返回 execution_id
GET /api/executions/{id}/stream SSE 步骤流(validate→auth→…→done)
GET /api/executions/{id} 执行状态 + 全量步骤(轮询兜底)
GET /api/executions 历史列表(时间倒序、分页、kind 过滤)
POST /api/executions/{id}/replay 用历史参数重放执行
DELETE /api/executions 清空历史
GET /api/auth/profiles 凭据 profile 列表(token 掩码)
POST /api/auth/switch 切换当前 profile

示例

# 启动 demo 服务
cliyard serve examples/demo --port 8080

# 提交一个命令执行
curl -X POST http://127.0.0.1:8080/api/execute \
  -H 'Content-Type: application/json' \
  -d '{"kind":"command","target":"user.list","params":{}}'
# => {"execution_id":"..."}

# 订阅步骤流(SSE)
curl -N http://127.0.0.1:8080/api/executions/<id>/stream

# 查看历史
curl http://127.0.0.1:8080/api/executions

Examples

See the examples/ directory for ready-to-use spec sets:

  • examples/demo/ — Pet Store API demo with resource commands, plugins, and flow orchestration
# Library mode (read YAML at runtime)
python3 -c "from cliyard.runtime import create_cli; create_cli('examples/demo')()"

# Flow orchestration
petstore flow list
petstore flow run add-user --name 张三
petstore flow run retry-demo
petstore flow run plugin-demo
petstore flow run hook-demo

Documentation

Generated CLI projects include a README.md with full usage docs covering:

  • Usage & environment management
  • Adding new resources
  • Plugin authoring (all 7 plugin types)
  • Flow orchestration with conditional branching, loops, and hooks
  • Multi-server configuration
  • Custom method plugins

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cliyard-0.12.1.tar.gz (365.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cliyard-0.12.1-py3-none-any.whl (324.0 kB view details)

Uploaded Python 3

File details

Details for the file cliyard-0.12.1.tar.gz.

File metadata

  • Download URL: cliyard-0.12.1.tar.gz
  • Upload date:
  • Size: 365.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for cliyard-0.12.1.tar.gz
Algorithm Hash digest
SHA256 2da62fdd1bd12430ece8945f09fd6b3d1cfb241e61bbcab20152a8f3af38f4c1
MD5 400cd3b164e04f6886b722df01ba8ba3
BLAKE2b-256 2a17567404df3479b454000f91a55e1fac3d7fffd099477fb2750be713051eaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for cliyard-0.12.1.tar.gz:

Publisher: publish.yml on guolong123/cliyard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cliyard-0.12.1-py3-none-any.whl.

File metadata

  • Download URL: cliyard-0.12.1-py3-none-any.whl
  • Upload date:
  • Size: 324.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for cliyard-0.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8ffd8c1b575dabe6ad239a0f71e6be55654f1084a9d39ef4873d323edf9b5a3
MD5 2c58c0b94e499c3ce0f4995fa3bdc329
BLAKE2b-256 b3a71cc6c47c9e4a0b395d78b89ff97b603a9d3640c0e501cdb373d33ae0755c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cliyard-0.12.1-py3-none-any.whl:

Publisher: publish.yml on guolong123/cliyard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.15.0

2 files

0.14.2

2 files

0.14.1

2 files

0.14.0

2 files

0.13.1

2 files

0.13.0

2 files

0.12.2

2 files

This release

0.12.1 This release

2 files

0.12.0

2 files

0.11.1

2 files

0.11.0

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page