Skip to main content

Python library for Juju

Project description

Source code:

Bug reports:



  • Python 3.5+
  • Juju 2.0+

Design Notes

  • Asynchronous - uses asyncio and async/await features of python 3.5
  • Websocket-level bindings are programmatically generated (indirectly) from the Juju golang code, ensuring full api coverage
  • 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.)


pip3 install juju


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.


import logging
import sys

from juju import loop
from juju.model import Model

async def deploy():
    # 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 model
    await model.connect_current()

        # Deploy a single unit of the ubuntu charm, using the latest revision
        # from the stable channel of the Charm Store.
        ubuntu_app = await model.deploy(

        if '--wait' in sys.argv:
            # optionally block until the application is ready
            await model.block_until(lambda: ubuntu_app.status == 'active')
        # Disconnect from the api server and cleanup.
        await model.disconnect()

def main():

    # If you want to see everything sent over the wire, set this to DEBUG.
    ws_logger = logging.getLogger('websockets.protocol')

    # Run the deploy coroutine in an asyncio event loop, using a helper
    # that abstracts loop creation and teardown.

if __name__ == '__main__':

Change Log


Monday Dec 18 2017

  • Fix missed renames of model_uuids (#197)


Fri Dec 15 2017

  • Fix race condition in adding relations (#192)
  • Fix race condition in connection monitor test (#183)
  • Fix example in README (#178)
  • Fix rare hang during (#177)
  • Fix licensing quirks (#176)
  • Refactor model handling (#171)
  • Refactor users handling, add get_users (#170)
  • Upload credential to controller when adding model (#168)
  • Support ‘applications’ key in bundles (#165)
  • Improve handling of thread error handling for (#169)
  • Fix encoding when using to_json() (#166)
  • Fix intermittent test failures (#167)


Fri Sept 29 2017

  • Fix failure when controller supports newer facade version (#145)
  • Fix test failures (#163)
  • Fix SSH key handling when adding a new model (#161)
  • Make Application.upgrade_charm upgrade resources (#158)
  • Expand integration tests to use stable/edge versions of juju (#155)
  • Move docs to ReadTheDocs (


Thu June 29 2017

  • Implement scp functionality (#149)
  • Add Unit.public_address property (#153)
  • Adds support for getting/setting config on a model (#152)


Thu June 22 2017

  • Improve handling of closed connections (#148)
  • Configurable and larger max message size (#146)


Wed June 14 2017

  • Fix deploying non-stable channels and explicit revs (#144)


Tue June 13 2017

  • Update schema for Juju 2.3 alpha1 (#142)
  • Improve API doc navigation and coverage (#141)
  • Add type info to Model.add_machine docs (#138)


Thu June 8 2017

  • Add machine status properties (#133)
  • Add model context manager (#128)
  • Implement Application.upgrade_charm method (#132)


Thu June 1 2017

  • Accept new / unknown API fields gracefully (#131)
  • Add support for new agent-version field in ModelInfo (#131)
  • Replace pip with pip3 in install instructions (#129)
  • Strip local:-prefix from local charm urls (#121)


Wed May 10 2017

  • Support (and prefer) per-controller macaroon files (#125)


Wed Apr 27 2017

  • Remove VERSION_MAP and rely on facade list from controller (#118)
  • Refactor connection task management to avoid cancels (#117)
  • Refactored login code to better handle redirects (#116)


Wed Apr 19 2017

  • Feature/api version support (#109)
  • Expanding with basic user functions, get_models and destroy (#89)
  • Added Monitor class to Connection. (#105)
  • Support placement lists (#103)
  • Include resources from store when deploying (#102)
  • Allow underscore to dash translation when accessing model attributes (#101)
  • Added controller to ssh fix. (#100)
  • Regen schema to pick up missing APIs
  • Improve error handling
  • Fix issue where we do not check to make sure that we are receiving the correct response.
  • Retry calls to charmstore and increase timeout to 5s
  • Make connect_model and deploy a bit more friendly
  • Fix model name not including user
  • Implement Model.get_status
  • Add integration tests.


Mon Feb 27 2017

  • Fix docstrings for placement directives.
  • Implement Model.add_machine()
  • Bug fix - “to” parameter to Model.deploy() was broken
  • Add docs and examples for adding machines and containers and deploying charms to them.
  • Make Machine.destroy() block the current coroutine, returning only after the machine is actually removed from the remote model. This is more consistent with the way the other apis work (e.g. Model.deploy(), Application.add_unit(), etc).
  • Raise NotImplementedError in all unimplemented method stubs instead of silently passing.


Thu Feb 16 2017

  • Add default ssh key to newly created model.
  • Add loop helpers and simplify examples/
  • Add support for deploying local charms, and bundles containing local charm paths.
  • Add ability to get cloud name for controller.
  • Bug fix - fix wrong api used in Model.destroy_unit()
  • Add error detection in bundle deploy.


Thu Dec 22 2016

  • Bug fix - Include docs in package


Thu Dec 22 2016

  • Bug fix - Include VERSION file in package


Wed Dec 21 2016

  • Initial Release

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
juju-0.7.1.tar.gz (187.8 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page