kopf 1.44.5


pip install kopf

  Latest version

Released: Apr 01, 2026


Meta
Author: Sergey Vasilyev
Maintainer: Sergey Vasilyev
Requires Python: >=3.10

Classifiers

Intended Audience
  • Developers

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 3
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14
  • Python :: 3 :: Only
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Topic
  • Software Development :: Libraries

Kubernetes Operator Pythonic Framework (Kopf)

GitHub CI Supported Python versions codecov coverage

Kopf — Kubernetes Operator Pythonic Framework — is a framework and a library to make Kubernetes operator development easier, in just a few lines of Python code.

The main goal is to bring the Domain-Driven Design to the infrastructure level, with Kubernetes being an orchestrator/database of the domain objects (custom resources), and the operators containing the domain logic (with no or minimal infrastructure logic).

The project was originally started as zalando-incubator/kopf in March 2019, and then forked as nolar/kopf in August 2020 — but it is the same codebase, the same packages, the same developer(s).

Documentation

Status

Kopf is production-ready and stable (semantic v1). Major bugs are fixed ASAP (there were none for a long time). Minor bugs are fixed as time and energy permit, or a workaround is provided.

There is no active development of new major functionality for Kopf — the whole idea of a framework for operators is fully expressed and implemented, I have nothing more to add. This piece of art is finished. (This might change.)

Minor feature requests can be implemented from time to time. Maintenance for new versions of Python and Kubernetes is performed regularly. Some internal optimizations are planned, such as minimizing the memory footprint, high-load readiness, or agentic friendliness — but will be backwards-compatible (no semantic v2 with breaking changes on the horizon).

Features

  • Simple, but powerful:
    • A full-featured operator in just 2 files: a Dockerfile + a Python file (*).
    • Handling functions registered via decorators with a declarative approach.
    • No infrastructure boilerplate code for K8s API communication.
    • Both sync and async handlers, with sync ones being threaded under the hood.
    • Detailed documentation with examples.
  • Intuitive mapping of Python concepts to Kubernetes concepts and back:
    • Marshalling of resources' data to the handlers' kwargs.
    • Marshalling of handlers' results to the resources' statuses.
    • Publishing of logging messages as Kubernetes events linked to the resources.
  • Support for anything that exists in K8s:
    • Custom K8s resources.
    • Built-in K8s resources (pods, namespaces, etc).
    • Multiple resource types in one operator.
    • Both cluster and namespaced operators.
  • All the ways of handling that a developer can wish for:
    • Low-level handlers for events received from K8s APIs "as is" (an equivalent of informers).
    • High-level handlers for detected causes of changes (creation, updates with diffs, deletion).
    • Handling of selected fields only instead of the whole objects (if needed).
    • Dynamically generated or conditional sub-handlers (an advanced feature).
    • Timers that tick as long as the resource exists, optionally with a delay since the last change.
    • Daemons that run as long as the resource exists (in threads or asyncio-tasks).
    • Validating and mutating admission webhook (with dev-mode tunneling).
    • Live in-memory indexing of resources or their excerpts.
    • Filtering with stealth mode (no logging): by arbitrary filtering functions, by labels/annotations with values, presence/absence, or dynamic callbacks.
    • In-memory all-purpose containers to store non-serializable objects for individual resources.
  • Eventual consistency of handling:
    • Retrying the handlers in case of arbitrary errors until they succeed.
    • Special exceptions to request a special retry or to never retry again.
    • Custom limits for the number of attempts or the time allowed.
    • Implicit persistence of the progress that survives the operator restarts.
    • Tolerance to restarts and lengthy downtimes: handles the changes afterwards.
  • Awareness of other Kopf-based operators:
    • Configurable identities for different Kopf-based operators for the same resource kinds.
    • Avoiding double-processing due to cross-pod awareness of the same operator ("peering").
    • Pausing of a deployed operator when a dev-mode operator runs outside of the cluster.
  • Extra toolkits and integrations:
    • Some limited support for object hierarchies with name/labels propagation.
    • Friendly to any K8s client libraries (and is client agnostic).
    • Startup/cleanup operator-level handlers.
    • Liveness probing endpoints and rudimentary metrics exports.
    • Basic testing toolkit for in-memory per-test operator running.
    • Embeddable into other Python applications.
  • Highly configurable (to some reasonable extent).

(*) Small font: two files of the operator itself, plus some amount of deployment files like RBAC roles, bindings, service accounts, network policies — everything needed to deploy an application in your specific infrastructure.

Examples

See examples for examples of typical use cases.

A minimalistic operator can look like this:

import kopf

@kopf.on.create('kopfexamples')
def create_fn(spec, name, meta, status, **kwargs):
    print(f"And here we are! Created {name} with spec: {spec}")

Numerous kwargs are available, such as body, meta, spec, status, name, namespace, retry, diff, old, new, logger, etc: see Arguments

To run a never-exiting function for every resource as long as it exists:

import time
import kopf

@kopf.daemon('kopfexamples')
def my_daemon(spec, stopped, **kwargs):
    while not stopped:
        print(f"Object's spec: {spec}")
        time.sleep(1)

Or the same with the timers:

import kopf

@kopf.timer('kopfexamples', interval=1)
def my_timer(spec, **kwargs):
    print(f"Object's spec: {spec}")

That's easy! For more features, see the documentation.

Usage

Python 3.10+ is required: CPython and PyPy are officially supported and tested; other Python implementations can work too.

We assume that when the operator is executed in the cluster, it must be packaged into a docker image with a CI/CD tool of your preference.

FROM python:3.14
ADD . /src
RUN pip install kopf
CMD kopf run /src/handlers.py --verbose

Where handlers.py is your Python script with the handlers (see examples/*/example.py for examples).

For quick experimentation, a pre-built image with all extras is available on GHCR — just mount your operator file and go:

# Minimize the credentials exposure.
kubectl config view --minify --flatten > dev.kubeconfig

# Run the operator locally, target a local cluster (host networking).
docker run --rm -it --network=host \
    -v ./handlers.py:/app/main.py:ro \
    -v ./dev.kubeconfig:/root/.kube/config:ro \
    ghcr.io/nolar/kopf

See the Docker image documentation for more details.

See kopf run --help for other ways of attaching the handlers.

Contributing

Please read CONTRIBUTING.md for details on our process for submitting pull requests to us, and please ensure you follow the CODE_OF_CONDUCT.md.

To install the environment for the local development, read DEVELOPMENT.md.

Versioning

We use SemVer for versioning. For the versions available, see the releases on this repository.

License

This project is licensed under the MIT License — see the LICENSE file for details.

Acknowledgments

  • Thanks to Zalando for starting this project in Zalando's Open-Source Incubator in the first place.
  • Thanks to @side8 and their k8s-operator for inspiration.
1.44.5 Apr 01, 2026
1.44.4 Mar 24, 2026
1.44.3 Mar 23, 2026
1.44.2 Mar 19, 2026
1.44.1 Mar 17, 2026
1.44.0 Mar 14, 2026
1.43.0 Feb 12, 2026
1.42.5 Feb 07, 2026
1.42.4 Feb 02, 2026
1.42.3 Feb 01, 2026
1.42.2 Jan 31, 2026
1.42.1 Jan 30, 2026
1.42.0 Jan 29, 2026
1.41.1 Jan 27, 2026
1.41.0 Jan 26, 2026
1.40.1 Jan 22, 2026
1.40.0 Jan 03, 2026
1.39.1 Dec 19, 2025
1.39.0 Dec 08, 2025
1.38.0 May 12, 2025
1.37.5 Mar 22, 2025
1.37.4 Dec 13, 2024
1.37.3 Nov 18, 2024
1.37.2 Apr 08, 2024
1.37.1 Jan 20, 2024
1.37.0 Jan 19, 2024
1.36.2 Jul 27, 2023
1.36.1 May 06, 2023
1.36.0 Nov 04, 2022
1.35.6 Aug 01, 2022
1.35.5 Jun 20, 2022
1.35.4 Apr 02, 2022
1.35.3 Nov 17, 2021
1.35.2 Oct 26, 2021
1.35.1 Oct 10, 2021
1.35.0 Oct 10, 2021
1.35rc1 Oct 05, 2021
1.34.0 Sep 20, 2021
1.34rc1 Sep 12, 2021
1.33.0 Aug 03, 2021
1.33rc2 Jul 22, 2021
1.33rc1 Jul 04, 2021
1.32.1 May 19, 2021
1.32.0 May 19, 2021
1.32rc2 May 14, 2021
1.32rc1 May 13, 2021
1.31.0 Apr 27, 2021
1.31rc3 Apr 03, 2021
1.31rc2 Mar 29, 2021
1.31rc1 Mar 28, 2021
1.30.3 Mar 29, 2021
1.30.2 Mar 18, 2021
1.30.1 Mar 10, 2021
1.30.0 Mar 10, 2021
1.30.0rc1 Feb 25, 2021
1.30.0.dev1 Feb 06, 2021
1.29.2 Feb 09, 2021
1.29.1 Jan 30, 2021
1.29.0 Jan 27, 2021
1.29.0rc5 Jan 26, 2021
1.29.0rc4 Jan 24, 2021
1.29.0rc3 Jan 22, 2021
1.29.0rc2 Jan 19, 2021
1.29.0rc1 Jan 03, 2021
0.28.3 Dec 15, 2020
0.28.2 Dec 11, 2020
0.28.2rc1 Dec 10, 2020
0.28.1 Dec 03, 2020
0.28 Oct 08, 2020
0.28rc6 Oct 05, 2020
0.28rc5 Oct 01, 2020
0.28rc4 Sep 26, 2020
0.28rc3 Sep 12, 2020
0.28rc2 Sep 12, 2020
0.27.1 Oct 07, 2020
0.27 Jun 08, 2020
0.27rc6 May 11, 2020
0.27rc5 Apr 28, 2020
0.27rc4 Apr 16, 2020
0.27rc3 Apr 08, 2020
0.27rc2 Apr 07, 2020
0.27rc1 Apr 01, 2020
0.26 Mar 05, 2020
0.26rc1 Feb 20, 2020
0.25 Jan 29, 2020
0.25rc1 Jan 21, 2020
0.24 Dec 23, 2019
0.24rc1 Dec 19, 2019
0.23.2 Nov 21, 2019
0.23.1 Nov 20, 2019
0.23 Nov 20, 2019
0.23rc5 Nov 20, 2019
0.23rc4 Nov 15, 2019
0.23rc3 Nov 14, 2019
0.23rc2 Nov 14, 2019
0.23rc1 Nov 13, 2019
0.22 Oct 23, 2019
0.22rc1 Sep 26, 2019
0.21 Sep 13, 2019
0.21rc5 Aug 14, 2019
0.21rc4 Aug 14, 2019
0.21rc3 Aug 08, 2019
0.21rc2 Aug 08, 2019
0.21rc1 Aug 08, 2019
0.20 Jul 24, 2019
0.19 Jul 18, 2019
0.19rc2 Jul 12, 2019
0.19rc1 Jul 09, 2019
0.18 Jul 08, 2019
0.17.post1 Jul 04, 2019
0.17 Jul 03, 2019
0.17.dev1 Jun 18, 2019
0.16 Jun 14, 2019
0.15 Jun 14, 2019
0.14 May 31, 2019
0.13 May 28, 2019
0.12 May 28, 2019
0.11 May 17, 2019
0.10 Apr 26, 2019
0.9.1 Apr 25, 2019
0.9 Apr 24, 2019
0.8 Apr 18, 2019
0.7 Apr 16, 2019
0.6.1 Mar 28, 2019
0.6 Mar 27, 2019
0.5 Mar 27, 2019

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
python-json-logger
jsonpatch
iso8601
pyyaml
click (>=8.2.0)
aiohttp (>=3.11.0)
aiohttp (>=3.9.0)