The Python library behind great charms
Actively maintained. Last release 10 days ago, commits in 24 of the last 26 weeks. A safe choice.
pip install opsThe ops library
The ops library is a Python framework for developing and testing Kubernetes and machine charms. While charms can be written in any language, ops defines the latest standard, and charmers are encouraged to use Python with ops for all charms. The library is an official component of the Charm SDK, itself a part of the Juju universe.
opsis available on PyPI.- The latest version of
opsrequires Python 3.10 or above.- Read our docs for tutorials, how-to guides, the library reference, and more.
Give it a try
Let's use ops to build a Kubernetes charm:
Set up
See Juju | Set things up.
Choose the automatic track and MicroK8s.
Write your charm
On your Multipass VM, create a charm directory and use Charmcraft to initialise your charm file structure:
mkdir ops-example
cd ops-example
charmcraft init
This has created a standard charm directory structure:
$ ls -R
.:
CONTRIBUTING.md README.md pyproject.toml src tox.ini
LICENSE charmcraft.yaml requirements.txt tests
./src:
charm.py
./tests:
integration unit
./tests/integration:
test_charm.py
./tests/unit:
test_charm.py
Things to note:
-
The
charmcraft.yamlfile shows that what we have is an example charm calledops-example, which uses an OCI image resourcehttpbinfromkennethreitz/httpbin. -
The
requirements.txtfile lists the version ofopsto use. -
The
src/charm.pyfile importsopsand usesopsconstructs to create a charm class , observe Juju events, and pair them to event handlers: