Skip to main content

Python library for Juju (fork of python-libjuju; installs as juju-resolute, imports as juju)

Project description

This is juju-resolute, a fork of python-libjuju (published on PyPI as juju). It installs as juju-resolute but is imported as juju, so it stays a drop-in replacement. Note: because both packages own the on-disk juju directory, only one of juju or juju-resolute can be installed in a given environment at a time.

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

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

Upstream: https://github.com/juju/python-libjuju

Documentation: https://pythonlibjuju.readthedocs.io/en/latest/

Supported Python versions: 3.8 through 3.13 Supported Juju versions: 3.1 through 3.6

Design Notes

  • Asynchronous - Uses asyncio and async/await features of Python

  • 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

pip3 install juju-resolute

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:

Note : Pylibjuju requires an already bootstrapped Juju controller to connect to.

#!/usr/bin/python3

import asyncio
import logging
import sys

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()

    try:
        # 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(
          'ubuntu',
          application_name='my-ubuntu',
        )

        if '--wait' in sys.argv:
            # optionally block until the application is ready
            await model.wait_for_idle(status='active')

    finally:
        # Disconnect from the api server and cleanup.
        await model.disconnect()


def main():
    logging.basicConfig(level=logging.INFO)

    # 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)

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


if __name__ == '__main__':
    main()

More examples can be found in the docs, as well as in the examples/ directory of the source tree which can be run using tox. For example, to run examples/connect_current_model.py, use:

tox -e example -- examples/connect_current_model.py

REPL

To experiment with the library in a REPL, launch python in asyncio mode

$ python3 -m asyncio

and then, to connect to the current model and fetch status:

>>> from juju.model import Model
>>> model = Model()
>>> await model.connect_current()
>>> status = await model.get_status()

Versioning

The current Pylibjuju release policy tracks the Juju release cadence. In particular, whenever Juju makes a latest/stable release, pylibjuju pushes out a release with the same version in the following week. Newly generated schemas will be updated per Juju releases.

Project details


Download files

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

Source Distribution

juju_resolute-3.6.1.3.tar.gz (306.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

juju_resolute-3.6.1.3-py3-none-any.whl (288.0 kB view details)

Uploaded Python 3

File details

Details for the file juju_resolute-3.6.1.3.tar.gz.

File metadata

  • Download URL: juju_resolute-3.6.1.3.tar.gz
  • Upload date:
  • Size: 306.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for juju_resolute-3.6.1.3.tar.gz
Algorithm Hash digest
SHA256 8e2a26f2fee4276accd33a6c6977867146872083191c0264000223c05f633e47
MD5 9638395122553f4311f6fce4d5bd2ce4
BLAKE2b-256 6b793e8a50a235f3912bb46fce0a4a0b77bd0ddb360c27ed44a27449071ed5f3

See more details on using hashes here.

File details

Details for the file juju_resolute-3.6.1.3-py3-none-any.whl.

File metadata

  • Download URL: juju_resolute-3.6.1.3-py3-none-any.whl
  • Upload date:
  • Size: 288.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for juju_resolute-3.6.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 88e46ce5453be0e16b26b787afd688cf3b3e3c187bc5e574bb11193378ac3dc0
MD5 78dd48cc368074ae22112cf3fb6fdf16
BLAKE2b-256 8360aa806a596a2d81cdf200fb5d2d5d556603a5ca9b96f956b2460b501c26f2

See more details on using hashes here.

Supported by

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