{"id":5755,"library":"cement","title":"Cement Application Framework for Python","description":"Cement is an advanced application framework for Python, primarily focused on Command Line Interfaces (CLI). It provides a versatile, stable, and feature-rich foundation for building simple to complex command-line and backend applications, offering the simplicity of a micro-framework with the capabilities of a mega-framework. The current version is 3.0.14, and it is actively maintained with regular updates.","status":"active","version":"3.0.14","language":"en","source_language":"en","source_url":"https://github.com/datafolklabs/cement","tags":["cli","framework","application-framework","command-line-interface","python"],"install":[{"cmd":"pip install cement","lang":"bash","label":"Core library"},{"cmd":"pip install cement[cli]","lang":"bash","label":"With CLI development tools"}],"dependencies":[{"reason":"Required for `cement` command-line tool, installed via `cement[cli]`","package":"PyYAML","optional":true},{"reason":"Required for `cement` command-line tool, installed via `cement[cli]`","package":"Jinja2","optional":true},{"reason":"Optional dependency for enhanced logging, installed via `cement[colorlog]`","package":"colorlog","optional":true}],"imports":[{"note":"This is the modern import for the main application class.","symbol":"App","correct":"from cement import App"},{"note":"Used for defining application commands and sub-commands.","symbol":"Controller","correct":"from cement import Controller"},{"note":"Decorator for exposing controller methods as commands.","symbol":"ex","correct":"from cement import ex"},{"note":"This import path was common in Cement 2.x and earlier; `from cement import App` is preferred for Cement 3.x.","wrong":"from cement.core.foundation import CementApp","symbol":"CementApp"}],"quickstart":{"code":"import sys\nfrom cement import App, Controller, ex\n\nclass Base(Controller):\n    class Meta:\n        label = 'base'\n\n    @ex(hide=True)\n    def _default(self):\n        \"\"\"Default action if no sub-command is passed.\"\"\"\n        print(\"Hello from Cement! Try 'myapp hello <name>'\\n\")\n        print(\"Run with --help for options.\")\n\nclass HelloWorld(Controller):\n    class Meta:\n        label = 'hello'\n        stacked_on = 'base'\n        stacked_type = 'nested'\n\n    @ex(help=\"Say hello to a given name.\")\n    def name(self):\n        \"\"\"A sample sub-command.\"\"\"\n        name = self.app.pargs.name or \"World\"\n        print(f\"Hello, {name}!\")\n\nclass MyApp(App):\n    class Meta:\n        label = 'myapp'\n        base_controller = 'base'\n        handlers = [\n            Base,\n            HelloWorld,\n        ]\n\nif __name__ == '__main__':\n    try:\n        with MyApp() as app:\n            app.run()\n    except Exception as e:\n        print(f\"An error occurred: {e}\", file=sys.stderr)\n        sys.exit(1)\n","lang":"python","description":"This quickstart demonstrates a basic Cement application with a default command and a nested 'hello' sub-command. It showcases the `App` and `Controller` classes, along with the `ex` decorator for defining commands. Running `python myapp.py` will execute the default action, while `python myapp.py hello --help` or `python myapp.py hello name --name YourName` will demonstrate the sub-command."},"warnings":[{"fix":"Upgrade your Python environment to 3.8 or newer and update your application code to be Python 3 compatible. Refer to Python's official migration guides.","message":"Cement 3.x officially dropped support for Python 2.x. It requires Python >=3.8. Applications developed with older Cement versions targeting Python 2.x will require significant migration efforts.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"Ensure that `pip install cement[cli]` is executed if you use the `cement` command-line tool or its features.","message":"As of Cement 3.0.12, dependencies for the `cement` command-line development tool (specifically `PyYAML` and `Jinja2`) were moved to an optional `cement[cli]` extra. Existing automation or scripts that rely on the `cement` command without this extra installed will break.","severity":"breaking","affected_versions":">=3.0.12"},{"fix":"For Windows development, consider using Docker. If developing natively, be aware of potential platform-specific issues and consult the documentation or issue tracker.","message":"Native Windows development support for Cement is not 100% complete and is not a primary development target. Users developing on Windows are recommended to use Docker for a more streamlined experience, as native setups may encounter known issues.","severity":"gotcha","affected_versions":"All 3.x versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}