Skip to main content

Python library for Juju

Project description

Source code: https://github.com/juju/python-libjuju

Bug reports: https://github.com/juju/python-libjuju/issues

Documentation: https://pythonhosted.org/juju/

Requirements

  • 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.)

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.5

import asyncio
import logging

from juju.model import Model


async def run():
    # 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 revision 0 from the
    # stable channel of the Charm Store.
    ubuntu_app = await model.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()


def main():
    # 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 loop
    loop = asyncio.get_event_loop()

    # Queue up our `run()` coroutine for execution
    loop.create_task(run())

    # Start the event loop
    loop.run_forever()


if __name__ == '__main__':
    main()

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

juju-0.1.1.tar.gz (122.2 kB view details)

Uploaded Source

File details

Details for the file juju-0.1.1.tar.gz.

File metadata

  • Download URL: juju-0.1.1.tar.gz
  • Upload date:
  • Size: 122.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for juju-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b4d3b0185a71dc426abf5d6175b1e516ea84b8b34b98e7712d4c2dd4bcbee8f3
MD5 10e89db29a83fb076d90348f5f1fb753
BLAKE2b-256 d54d692763a7b93d2ee9ce44190e329dd60b63c508e44873d73136553ba8e66d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page