Design Notes

Provides an OO layer which encapsulates much of the websocket api and
provides familiar nouns and verbs (e.g. Model.deploy(), Application.add_unit(),
etc.)

Installation

pip install juju

Quickstart

Here’s a simple example that shows basic usage of the library. The example
connects to the currently active Juju model, deploys a single unit of the
ubuntu charm, then exits.

More examples can be found in the examples/ directory of the source tree,
and in the documentation.

#!/usr/bin/python3.5importasyncioimportloggingfromjuju.modelimportModelasyncdefrun():# Create a Model instance. We need to connect our Model to a Juju api# server before we can use it.model=Model()# Connect to the currently active Juju modelawaitmodel.connect_current()# Deploy a single unit of the ubuntu charm, using revision 0 from the# stable channel of the Charm Store.ubuntu_app=awaitmodel.deploy('ubuntu-0',application_name='ubuntu',series='xenial',channel='stable',)# Disconnect from the api server and cleanup.model.disconnect()# Stop the asyncio event loop.model.loop.stop()defmain():# Set logging level to debug so we can see verbose output from the# juju library.logging.basicConfig(level=logging.DEBUG)# Quiet logging from the websocket library. If you want to see# everything sent over the wire, set this to DEBUG.ws_logger=logging.getLogger('websockets.protocol')ws_logger.setLevel(logging.INFO)# Create the asyncio event looploop=asyncio.get_event_loop()# Queue up our `run()` coroutine for executionloop.create_task(run())# Start the event looploop.run_forever()if__name__=='__main__':main()