Skip to main content

charmlibs-pathops

pathops provides a pathlib-like interface for local filesystem and workload container paths for Juju Charms.

To install, add charmlibs-pathops to your requirements. Then in your Python code, import as:

from charmlibs import pathops

Check out the reference docs on the charmlibs docsite.

Getting started

To get started, you can create an attribute self.root with the root directory for the local or remote paths you'll be working with.

import ops
from charmlibs import pathops

class KubernetesCharm(ops.CharmBase):
    def __init__(self, framework: ops.Framework):
        super().__init__(framework)
        container = self.unit.get_container('container-name')
        self.root = pathops.ContainerPath('/', container=container)

# or

class MachineCharm(ops.CharmBase):
    def __init__(self, framework: ops.Framework):
        super().__init__(framework)
        self.root = pathops.LocalPath('/')

You can then write code that could be used by either charm, using the pathops.PathProtocol type, which describes the operations supported by both local and container paths.

CONFIG_FILE_LOCATION = '/foo/bar'
CONFIG_FILE_CONTENTS = '...'

def write_config_file(root: pathops.PathProtocol) -> None:
    path = root / CONFIG_FILE_LOCATION
    path.write_text(CONFIG_FILE_CONTENTS)

For a Kubernetes charm, this also allows you to use the same API to work with paths in the charm container or the workload container.

import ops
from charmlibs import pathops

class KubernetesCharm(ops.CharmBase):
    def __init__(self, framework: ops.Framework):
        super().__init__(framework)
        self.charm_root = pathops.LocalPath('/')
        container = self.unit.get_container('container-name')
        self.workload_root = pathops.ContainerPath('/', container=container)
        ...

    def copy_config(self):
        source = self.charm_root / 'foo/bar'
        dest = self.workload_root / 'foo/bar/baz'
        dest.parent.mkdir(parents=True, exist_ok=True)
        dest.write_bytes(source.read_bytes())

pathops also provides a helper function for ensuring that a file is present with specified content, which returns whether changes were made.

import ops
from charmlibs import pathops

class KubernetesCharm(ops.CharmBase):
    ...

    def copy_config(self):
        changed = pathops.ensure_contents(
            path=self.workload_root / 'foo/bar/baz',
            source=(self.charm_root / 'foo/bar').read_bytes(),
        )
        if changed:
            # make the workload reload its configuration
            ...

pathops.PathProtocol provides a subset of the pathlib.Path API. PathProtocol doesn't support relative paths, open, or manipulating hardlinks and symlinks.

pathops doesn't provide a separate chmod method, as Pebble doesn't currently support this. Instead, mkdir, write_bytes, and write_text have arguments mode, user, and group to set directory or file permissions and ownership. ensure_contents also has these arguments.

Release files for charmlibs-pathops 1.3.0.post0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for charmlibs-pathops 1.3.0.post0
File Size Uploaded
charmlibs_pathops-1.3.0.post0.tar.gz 22.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for charmlibs-pathops 1.3.0.post0
File Interpreter ABI Platform
charmlibs_pathops-1.3.0.post0-py3-none-any.whl Python 3 none any Details

Total release size: 49.4 kB

Release files / charmlibs_pathops-1.3.0.post0.tar.gz

Download URL charmlibs_pathops-1.3.0.post0.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
36ac11b0c7c55b71341a549a1803f5c8d61c2279204862b8d50736041b782f59
BLAKE2b-256 checksum
How to use checksums
091f37cd5c74fd6adbb01f4947651af55b8ff8461eed034de3f6d018988022ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

Release files / charmlibs_pathops-1.3.0.post0-py3-none-any.whl

Download URL charmlibs_pathops-1.3.0.post0-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6fc3e3460ffa03a7d4273cc7784c9d74378609a098c728cd9bbb2ed90bdfa5b
BLAKE2b-256 checksum
How to use checksums
4cae04b8e77ecbc84ef605feb8a35137570facbc191cbff37ca2b024ea8be466
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page