Skip to main content

Lean CLI framework for AI-friendly micro-apps

Project description

microcli-toolkit

Lean CLI framework for AI-friendly micro-apps

Microcli is a decorator-based CLI framework designed for building tools that agents can use. Unlike traditional CLIs that return data, microcli tools return instructions that guide the next step.

Installation

pip install microcli-toolkit
# or
uv add microcli-toolkit

Quick Start

#!/usr/bin/env python3
from typing import Annotated
import microcli as m

@m.command
def hello(name: Annotated[str, "Your name"]):
    """Greet a user."""
    m.ok(f"Hello, {name}!")

if __name__ == "__main__":
    m.main()
python hello.py hello Alice
# ✓ Hello, Alice!

The Three Principles

  1. Validate before acting — Check inputs before executing
  2. Return descriptive messages — Tell the agent what to do next
  3. Use two-phase patterns — Draft → Save for safety

Parameters

Style Becomes
No default Positional argument (required)
Has default --flag optional argument
bool type Boolean flag (--flag or nothing)
def cmd(name):                    # python cmd.py cmd John
def cmd(name="World"):            # python cmd.py cmd --name John  
def cmd(verbose: bool = False):  # python cmd.py cmd --verbose

Use Annotated[type, "help text"] to add help documentation.

Utilities

Status Helpers

  • m.ok(msg) — ✓ Success message
  • m.fail(msg) — ✗ Error message + exit(1)
  • m.info(msg) — → Informational message
  • m.warn(msg) — ⚠ Warning message
  • m.step(msg) — → Step indicator

File Operations

  • m.read(path) — Read file contents
  • m.write(path, content) — Write to file
  • m.ls() / m.glob(pattern) — List files
  • m.touch(path) — Create empty file
  • m.rm(path, recursive) — Remove file/directory
  • m.cp(src, dst) — Copy file/directory
  • m.mv(src, dst) — Move/rename

Shell

  • m.sh(cmd, timeout) — Run shell command, returns Result
  • m.which(cmd) — Find command in PATH

Navigation

  • with m.cd(path): — Context manager for directory changes
  • m.env(name) — Get environment variable

Design Patterns

Two-Phase (Safety)

if not save:
    m.info("Draft mode. Rerun with --save to persist")
    return
# ... save operation

Validation First

content = sys.stdin.read().strip()
if not content:
    m.fail("No content provided via stdin")

Descriptive Outputs

# Bad:  return  # silent
# Good: m.ok("Saved to: " + str(filepath))

Follow-up Commands (.explain)

if not save:
    m.info("Draft mode. Rerun with --save:")
    m.info("  " + create.explain(title=title, save=True))
    return

--learn Mode

Auto-discovers command tours by analyzing source code:

python tool.py --learn              # Show all commands
python tool.py --learn create       # Show focused view for 'create'

Output includes:

  • Next steps — Commands discovered via .explain() calls
  • Failure modes — Errors discovered via m.fail() calls
  • Happy paths — Success messages via m.ok() calls

License

MIT

Project details


Download files

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

Source Distribution

microcli_toolkit-0.2.0.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

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

microcli_toolkit-0.2.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file microcli_toolkit-0.2.0.tar.gz.

File metadata

  • Download URL: microcli_toolkit-0.2.0.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for microcli_toolkit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0a627e7f77665492f93086ef904f683006c3900168bd62dfe0bd6ec4ce2733c3
MD5 112d7885de4a0ebebfd4a5e3448eb626
BLAKE2b-256 dafd28bade45672c509849c7e64a062461b81cc5b35c22c06178b116a52665fd

See more details on using hashes here.

File details

Details for the file microcli_toolkit-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: microcli_toolkit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for microcli_toolkit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c598791e2284f1f92806ea166c3e28452cea65696704f1e8fe8eddc07fa8a9ec
MD5 21fc3ff47f2fa06172535e637e3c5e4e
BLAKE2b-256 8a5a389bcdb47359d2e431788cca4e0b8ee41a96df928a1d3894f30fdeafdaf7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page