{"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,"search_vec":"'3.10':25 '3.4.0':22 'build':10 'cadenc':30 'canon':8,32 'cli':3,11,31 'craft':2 'craft-c':1 'current':20 'framework':6,35 'indic':19 'log':16,33 'month':29 'output':15 'progress':18,34 'python':5,24 'releas':26 'requir':23 'structur':14 'tool':12 'version':21","created_at":"2026-05-01T08:07:55.332739+00:00","updated_at":"2026-05-01T08:07:55.332739+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"3.4.1","cli_name":"craft","cli_version":"sh: 1: craft: not found","type":"library","homepage":null,"github":"https://github.com/canonical/craft-cli","docs":"https://craft-cli.readthedocs.io/en/latest/","changelog":null,"pypi":"https://pypi.org/project/craft-cli/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}