ops

Pure Python framework for writing Juju charms

https://github.com/canonical/operator

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.2%) to scientific vocabulary

Keywords

charms juju python

Keywords from Contributors

flexible interactive distribution packaging alignment distance nested recursive genomics observability
Last synced: 6 months ago · JSON representation

Repository

Pure Python framework for writing Juju charms

Basic Info
Statistics
  • Stars: 253
  • Watchers: 17
  • Forks: 125
  • Open Issues: 81
  • Releases: 61
Topics
charms juju python
Created over 6 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Security

README.md

The ops library

CI Status

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.

  • ops is available on PyPI.
  • The latest version of ops requires 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:

shell-script mkdir ops-example cd ops-example charmcraft init This has created a standard charm directory structure:

```shell-script $ 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.yaml file shows that what we have is an example charm called ops-example, which uses an OCI image resource httpbin from kennethreitz/httpbin.

  • The requirements.txt file lists the version of ops to use.

  • The src/charm.py file imports ops and uses ops constructs to create a charm class OpsExampleCharm, observe Juju events, and pair them to event handlers:

```python import ops

class OpsExampleCharm(ops.CharmBase): """Charm the service."""

def __init__(self, *args):
    super().__init__(*args)
    self.framework.observe(self.on['httpbin'].pebble_ready, self._on_httpbin_pebble_ready)
    self.framework.observe(self.on.config_changed, self._on_config_changed)

def _on_httpbin_pebble_ready(self, event: ops.PebbleReadyEvent):
    """Define and start a workload using the Pebble API.

    Change this example to suit your needs. You'll need to specify the right entrypoint and
    environment configuration for your specific workload.

    Learn more about interacting with Pebble at
        https://documentation.ubuntu.com/ops/latest/reference/pebble/
    """
    # Get a reference the container attribute on the PebbleReadyEvent
    container = event.workload
    # Add initial Pebble config layer using the Pebble API
    container.add_layer("httpbin", self._pebble_layer, combine=True)
    # Make Pebble reevaluate its plan, ensuring any services are started if enabled.
    container.replan()
    # Learn more about statuses at
    # https://documentation.ubuntu.com/juju/3.6/reference/status/
    self.unit.status = ops.ActiveStatus()

```

See more: ops.PebbleReadyEvent

  • The tests/unit/test_charm.py file imports ops.testing and uses it to set up a unit test:

```python import ops from ops import testing

from charm import OpsExampleCharm

def testhttpbinpebbleready(): # Arrange: ctx = testing.Context(OpsExampleCharm) container = testing.Container("httpbin", canconnect=True) state_in = testing.State(containers={container})

# Act:
state_out = ctx.run(ctx.on.pebble_ready(container), state_in)

# Assert:
updated_plan = state_out.get_container(container.name).plan
expected_plan = {
    "services": {
        "httpbin": {
            "override": "replace",
            "summary": "httpbin",
            "command": "gunicorn -b 0.0.0.0:80 httpbin:app -k gevent",
            "startup": "enabled",
            "environment": {"GUNICORN_CMD_ARGS": "--log-level info"},
        }
    },
}
assert expected_plan == updated_plan
assert (
    state_out.get_container(container.name).service_statuses["httpbin"]
    == ops.pebble.ServiceStatus.ACTIVE
)
assert state_out.unit_status == testing.ActiveStatus()

```

See more: ops.testing

Explore further, start editing the files, or skip ahead and pack the charm:

shell-script charmcraft pack

If you didn't take any wrong turn or simply left the charm exactly as it was, this has created a file called ops-example_ubuntu-22.04-amd64.charm (the architecture bit may be different depending on your system's architecture). Use this name and the resource from the metadata.yaml to deploy your example charm to your local MicroK8s cloud:

shell-script juju deploy ./ops-example_ubuntu-22.04-amd64.charm --resource httpbin-image=kennethreitz/httpbin

Congratulations, you’ve just built your first Kubernetes charm using ops!

Clean up

See Juju | Tear things down.
Choose the automatic track.

Next steps

Owner

  • Name: Canonical
  • Login: canonical
  • Kind: organization
  • Location: London, UK

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 1,483
  • Total Committers: 69
  • Avg Commits per committer: 21.493
  • Development Distribution Score (DDS): 0.701
Past Year
  • Commits: 397
  • Committers: 16
  • Avg Commits per committer: 24.813
  • Development Distribution Score (DDS): 0.526
Top Committers
Name Email Commits
Pietro Pasotti s****n@g****m 444
Tony Meyer t****r@c****m 293
Ben Hoyt b****t@c****m 129
Tiexin Guo t****o@c****m 75
chipaca c****a 70
Dima Tisnek d****k@c****m 50
John Arbash Meinel j****n@a****m 49
Dmitrii Shcherbakov d****b 44
Cory Johns j****a@g****m 33
James Garner j****r@c****m 33
dependabot[bot] 4****] 27
Dave Wilding d****g@c****m 26
Robert Carlsen r****n@c****m 21
Jon Seager j****r@c****m 18
Facundo Batista f****o@t****r 17
Ryan Barry r****y@c****m 16
Gustavo Niemeyer g****o@n****t 15
Jose C. Massón j****n@c****m 13
Pete Vander Giessen p****g@g****m 12
Leon 8****i 9
Teodora Mihoc t****c@g****m 5
Prints Charming b****t@c****m 5
Michele Mancioppi m****i@c****m 5
Harry Pidcock h****k@c****m 4
Paul Goins g****l@v****t 4
Weii Wang w****g@c****m 4
Balbir Thomas b****s@h****m 4
mthaddon t****m@h****t 3
Yanks Yoon 3****n 3
Harish Navnit h****t@g****m 3
and 39 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 394
  • Total pull requests: 1,263
  • Average time to close issues: 8 months
  • Average time to close pull requests: 7 days
  • Total issue authors: 81
  • Total pull request authors: 40
  • Average comments per issue: 2.92
  • Average comments per pull request: 1.49
  • Merged pull requests: 976
  • Bot issues: 0
  • Bot pull requests: 62
Past Year
  • Issues: 171
  • Pull requests: 773
  • Average time to close issues: 25 days
  • Average time to close pull requests: 6 days
  • Issue authors: 29
  • Pull request authors: 17
  • Average comments per issue: 1.12
  • Average comments per pull request: 1.33
  • Merged pull requests: 572
  • Bot issues: 0
  • Bot pull requests: 31
Top Authors
Issue Authors
  • tonyandrewmeyer (54)
  • dimaqq (50)
  • benhoyt (48)
  • sed-i (40)
  • PietroPasotti (32)
  • dwilding (27)
  • rwcarlsen (9)
  • stub42 (8)
  • jameinel (7)
  • james-garner-canonical (7)
  • pengale (7)
  • gruyaume (4)
  • balbirthomas (4)
  • arturo-seijas (3)
  • weiiwang01 (3)
Pull Request Authors
  • tonyandrewmeyer (436)
  • dimaqq (186)
  • IronCore864 (147)
  • benhoyt (126)
  • dwilding (109)
  • james-garner-canonical (82)
  • dependabot[bot] (61)
  • PietroPasotti (34)
  • prints-charming-bot (16)
  • tmihoc (8)
  • sed-i (5)
  • weiiwang01 (4)
  • jameinel (3)
  • ghislainbourgeois (3)
  • carlcsaposs-canonical (3)
Top Labels
Issue Labels
small item (92) feature (65) docs (57) 25.10 (39) bug (36) needs design (17) harness (16) testing (15) 25.04 (14) 24.10 (14) 24.04 (12) blocked (11) type hints (10) ops-next (9) tests (8) investigate (8) low priority (8) needs spec (7) roadmap (5) next release (4) refactoring (4) 23.10 (3) github_actions (2) juju change required (2) python (1)
Pull Request Labels
dependencies (57) github_actions (14) type hints (12) python (9) docs (6) bug (6) feature (6) harness (2) small item (2)

Packages

  • Total packages: 5
  • Total downloads:
    • pypi 379,354 last-month
  • Total docker downloads: 4,331
  • Total dependent packages: 9
    (may contain duplicates)
  • Total dependent repositories: 482
    (may contain duplicates)
  • Total versions: 167
  • Total maintainers: 7
  • Total advisories: 1
pypi.org: ops

The Python library behind great charms

  • Versions: 67
  • Dependent Packages: 8
  • Dependent Repositories: 478
  • Downloads: 276,086 Last month
  • Docker Downloads: 4,331
Rankings
Dependent repos count: 0.7%
Dependent packages count: 1.2%
Downloads: 1.4%
Docker downloads count: 1.6%
Average: 2.3%
Forks count: 4.4%
Stargazers count: 4.4%
Last synced: 6 months ago
pypi.org: smooth
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 3
  • Downloads: 39 Last month
Rankings
Forks count: 4.4%
Stargazers count: 4.4%
Dependent repos count: 9.0%
Dependent packages count: 10.1%
Average: 10.5%
Downloads: 24.6%
Maintainers (1)
Last synced: 6 months ago
pypi.org: ops-scenario

Python library providing a state-transition testing API for Operator Framework charms.

  • Versions: 83
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Downloads: 97,488 Last month
Rankings
Downloads: 3.1%
Dependent packages count: 4.8%
Average: 12.7%
Forks count: 15.4%
Stargazers count: 18.5%
Dependent repos count: 21.6%
Maintainers (1)
Last synced: 6 months ago
spack.io: py-ops

The Python library behind great charms

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 28.8%
Dependent packages count: 57.7%
Last synced: 6 months ago
pypi.org: ops-tracing

The tracing facility for the Ops library.

  • Versions: 14
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 5,741 Last month
Rankings
Dependent packages count: 9.5%
Average: 31.5%
Dependent repos count: 53.5%
Maintainers (3)
Last synced: 6 months ago

Dependencies

docs/requirements.txt pypi
  • sphinx ==3.
  • sphinx_rtd_theme *
requirements-dev.txt pypi
  • PyYAML *
  • typing_extensions ==4.2.0
requirements.txt pypi
  • PyYAML *
setup.py pypi
  • PyYAML *
.github/workflows/charmcraft-pack.yaml actions
  • actions/checkout v3 composite
  • canonical/setup-lxd ea57509243d3cf39f8ab926e021bb353947b01b5 composite
.github/workflows/db-charm-tests.yaml actions
  • actions/checkout v3 composite
.github/workflows/framework-tests.yaml actions
  • actions/checkout v3 composite
  • actions/setup-go v1 composite
  • actions/setup-python v2 composite
.github/workflows/hello-charm-tests.yaml actions
  • actions/checkout v3 composite
  • actions/setup-python v2 composite
.github/workflows/observability-charm-tests.yaml actions
  • actions/checkout v3 composite
.github/workflows/publish.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v1 composite
  • pypa/gh-action-pypi-publish release/v1 composite
docs/requirements.in pypi
  • furo *
  • lxd-sphinx-extensions *
  • sphinx ==6.2.1
  • sphinx-copybutton *
  • sphinx-design *
  • sphinx-tabs *
pyproject.toml pypi