{"id":23465,"library":"craft-cli","title":"craft-cli","description":"A Python framework from Canonical for building CLI tools with structured output, logging, and progress indicators. Current version 3.4.0, requires Python >=3.10. Released on a monthly cadence.","status":"active","version":"3.4.0","language":"python","source_language":"en","source_url":"https://github.com/canonical/craft-cli","tags":["cli","canonical","logging","progress","framework"],"install":[{"cmd":"pip install craft-cli","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"","wrong":"","symbol":"craft_cli","correct":"import craft_cli"},{"note":"EmitterMode is exported from the top-level package, not a submodule.","wrong":"from craft_cli.emitter import EmitterMode","symbol":"EmitterMode","correct":"from craft_cli import EmitterMode"},{"note":"emit is a top-level singleton, not from internal modules.","wrong":"from craft_cli.emitter import emit","symbol":"emit","correct":"from craft_cli import emit"}],"quickstart":{"code":"from craft_cli import emit, EmitterMode\n\n# Initialize the CLI emitter\nemit.init(EmitterMode.BRIEF, appname=\"myapp\")\n\n# Simple message\nemit.message(\"Hello, world!\")\n\n# Progress bar\nwith emit.open_stream(\"Processing\") as stream:\n    for i in range(10):\n        stream.progress(f\"Step {i+1}\")\n\n# Error handling\nemit.error(\"Something went wrong\")\n","lang":"python","description":"Initialize the emitter and use basic output functions."},"warnings":[{"fix":"Use lowercase 'craft_cli' throughout.","message":"In version 2.x, craft_cli was internally called CraftCLI but later renamed to craft_cli. Ensure imports use lowercase.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use EmitterMode.VERBOSE for detailed output, EmitterMode.QUIET for minimal output.","message":"EmitterMode.BRIEF is considered legacy; prefer EmitterMode.VERBOSE or EmitterMode.QUIET for production.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Always pair emit.init() with emit.cleanup() in a try/finally block or context manager.","message":"Calling emit.init() more than once without emit.cleanup() will raise a RuntimeError.","severity":"gotcha","affected_versions":"all"},{"fix":"Use a single word or hyphenated name for appname.","message":"The appname argument in emit.init() must not contain spaces; otherwise, output formatting may break.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install with 'pip install craft-cli' and import as 'craft_cli' (underscore).","cause":"Package not installed or wrong import path (e.g., 'craft-cli' with hyphen).","error":"ModuleNotFoundError: No module named 'craft_cli'"},{"fix":"Wrap code in try/finally: emit.init(...); try: ... finally: emit.cleanup().","cause":"emit.init() called twice without emit.cleanup() in between.","error":"RuntimeError: Emitter already initialized"},{"fix":"Use 'from craft_cli import emit'.","cause":"Old import pattern or using incorrect casing.","error":"AttributeError: module 'craft_cli' has no attribute 'emit'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}