skillfed

charmlibs-pathops

A pathlib-like interface for Juju K8s charms to interact with files in their workload container.

charmlibs-pathops v1.3.0.post0 80.3K downloads/30d#14,296 on PyPI5
Permissive license Apache-2.0 Active released

What it is and what it does

charmlibs-pathops is a filesystem abstraction library for Juju Charms that unifies file operations across local charm containers and remote workload containers. It wraps the ops framework and provides LocalPath and ContainerPath classes that implement a common PathProtocol interface—a subset of pathlib.Path—allowing charm code to work with either filesystem using identical method calls.

The library is designed for Kubernetes charms that need to read from or write to files in both the charm container and the workload container. It handles path operations like mkdir, read_bytes, write_text, and a helper ensure_contents function that idempotently sets file contents and reports whether changes were made. It does not support relative paths, the open method, or symlink/hardlink manipulation; mkdir, write_bytes, and write_text accept mode, user, and group parameters to set permissions and ownership directly.

Use it for:

  • Copy configuration files from a charm container to a workload container with permission and ownership control.
  • Write charm-generated configuration to a workload container and detect whether the workload needs to reload.
  • Implement charm logic that works identically on both machine and Kubernetes charms by accepting a PathProtocol argument.
  • Ensure a file exists with specific content and ownership in a workload container, idempotently.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides a pathlib-like interface for reading and writing files in local filesystems and Juju workload container paths, supporting both Kubernetes and machine charms.

Yes—if you are writing Juju Charms that need to interact with container filesystems. The library eliminates boilerplate for path handling and unifies the API across charm types. No known vulnerabilities, permissive license, low install friction, and active maintenance. Not relevant for non-charm Python projects.

Install

charmlibs-pathops on PyPI

pip

pip install charmlibs-pathops

uv

uv add charmlibs-pathops

poetry

poetry add charmlibs-pathops

Installing charmlibs-pathops

Before you install

Low friction: pure Python wheel with a single runtime dependency (ops). Active maintenance with recent releases; last commit 2026-08-14.

License in practice

Apache-2.0 permissive license allows commercial and private use with minimal restrictions.

Quickstart

from charmlibs import pathops
import ops

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)
        path = self.root / 'foo/bar'
        path.write_text('content')

Requires Python >=3.10 and ops as a runtime dependency.

Verify before relying

  • Whether PathProtocol's subset of pathlib.Path API covers typical charm file-handling workflows beyond the documented examples.
  • Performance characteristics when working with large files or many operations across container boundaries.

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — ops
Maintenance actively maintained — 59 days since the last release
Last repo commit
First released
Downloads 80,338/month — #14,296 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: charmlibs_pathops-1.3.0.post0-py3-none-any.whl

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3

Tags

juju charm file operationspathlib container pathskubernetes charm filesystemworkload container file accesscharm path abstractionjuju charm io
juju-charmscontainer-filesystem

More Application Frameworks packages