Install & Compatibility
Where this runs
tested against v1.9.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.915 runs
installs and imports cleanly · install 0.0s · import 0.000s · 33.4MB
glibcpy 3.10–3.915 runs
installs and imports cleanly · install 3.8s · import 0.000s · 34MB
32MB installed
● package 32MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
COSIntegration
✓ from cosl import COSIntegration
✗ from cosl import COSIntegration
This quickstart demonstrates how to define observability rules using the `Rules` class and illustrates the typical integration pattern of `COSIntegration` within a Juju charm. Note that `COSIntegration` requires an instance of `ops.charm.CharmBase` and a running Juju environment or a test harness to be fully functional.
from ops.charm import CharmBase # Required for actual COSIntegration usage
from cosl.integrator import COSIntegration
from cosl.rules import Rules
# The 'cosl' library is primarily designed to be used within Juju charms.
# 1. Basic usage: Defining observability rules
# The Rules object encapsulates Prometheus/Grafana rules.
try:
# Rules are defined as a dictionary, typically loaded from YAML.
example_rules_content = {
"groups": [
{
"name": "example_group",
"rules": [
{"alert": "MyHighCPU", "expr": "node_cpu_usage_total > 0.9", "for": "5m"},
{"record": "job:cpu_usage_rate:avg1m", "expr": "rate(node_cpu_seconds_total[1m])"}
]
}
]
}
my_rules = Rules(content=example_rules_content)
print(f"Successfully created a Rules object:")
print(my_rules.content)
except Exception as e:
print(f"Error creating Rules object: {e}")
# 2. Advanced usage: Integrating with COS Lite in a Juju charm
# The COSIntegration class requires a 'CharmBase' instance from the 'ops' library.
# This part is illustrative and needs to be run within a Juju charm's context
# (e.g., in a charm's __init__.py or a Juju 'ops' test harness).
# class MyCOSCharm(CharmBase):
# def __init__(self, framework):
# super().__init__(framework)
# self.cos = COSIntegration(self) # 'self' is the CharmBase instance
# # You would then use self.cos to add rules, dashboards, etc.
# # For example: self.cos.add_rules(my_rules)
# self.framework.observe(self.cos.on.metrics_alert_rules_changed, self._on_rules_changed)
#
# def _on_rules_changed(self, event):
# print(f"COS rules changed event detected for: {event.rules_path}")
print("\nTo use COSIntegration, you need a Juju charm context (from 'ops' library).")
print("See the commented-out code above for an example of how it's typically used.")
Upgrade
Version history
1.9.1latest on PyPI · released Mar 31, 2026
Audit
Dependencies
opsrequiredRequired for typical usage within Juju charms, as 'cosl' classes like `COSIntegration` depend on 'ops.charm.CharmBase'.