Juju Python Library

3.6.1.3 · maintenance · verified Thu Apr 16

The `juju` library provides a Pythonic interface for interacting with Juju controllers and models, allowing programmatic control over Juju deployments. As of version 3.6.1.3, the library is not under active development and primarily receives critical bug fixes. Releases are infrequent and typically address specific issues rather than introducing new features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a Juju model using the `juju` library and retrieve information about deployed applications. It uses `asyncio` for asynchronous operations, which is the native way to interact with `libjuju`. Ensure you have a Juju controller configured and are logged in via the `juju` CLI.

import asyncio
import os
from juju.model import Model

async def main():
    model_name = os.environ.get('JUJU_MODEL', 'controller:default') # e.g., 'controller:my-model'
    
    model = Model()
    try:
        # Connect to a specific Juju model
        await model.connect(model_name=model_name)
        print(f"Connected to Juju model: {model.name}")
        
        # Example: Get applications
        applications = await model.get_applications()
        print(f"Applications in model: {[app.name for app in applications]}")
        
    except Exception as e:
        print(f"Error connecting to Juju: {e}")
    finally:
        if model.is_connected:
            await model.disconnect()
            print("Disconnected from Juju model.")

if __name__ == '__main__':
    # Ensure you have a Juju controller running and are logged in (e.g., via 'juju login')
    # Optionally set JUJU_MODEL environment variable to connect to a specific model
    asyncio.run(main())

view raw JSON →