Self-hosted service
nolar/kopf avatar
nolar/kopf

nolar/kopf: Kubernetes operators in a few lines of Python

A Python framework to write Kubernetes operators in just a few lines of code

2,662 stars206 forksPythonMIT

At a glance

What is it?
Kopf maps decorators onto Kubernetes resource events, so a working operator is mostly a Python file and a Dockerfile. It is stable and production-ready, but new major features are not planned.
Who is it for?
Adopt Kopf if your operator logic is Python and you want event handling, retries and peering without writing informer plumbing. Do not adopt it if you need a new major feature line, since the README states there is no active development of new major functionality.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • nolar/kopf2,662 ★ · +14
Star history
Repository2026-10-042026-11-22
nolar/kopf2.6k2.7k

14 Stars in the last 49 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The problem Kopf solves for Kubernetes operator authors

Writing a Kubernetes operator without a framework means writing an informer loop: watch the API for a resource kind, keep a local cache, decide what changed, call your logic, update the resource status, and handle the case where the process restarts halfway through. Kopf exists to remove that layer. The README describes the goal as bringing Domain-Driven Design to the infrastructure level, with Kubernetes as the orchestrator and database of custom resources, and the operator holding the domain logic. In practice that means you write functions decorated with kopf.on.create, kopf.on.update and similar, and the framework handles the API communication.

The audience is a Python developer who already knows what a custom resource is and does not want to learn a controller runtime in another language. The README states that a full-featured operator is two files: a Dockerfile and a Python file, with the caveat that deployment files such as RBAC roles, bindings and service accounts are still yours to produce. That caveat matters more than the headline. Kopf is not a packaging or deployment tool.

How handlers, kwargs and statuses fit together

The mechanism is decorator registration. A handler is a Python function registered against a resource kind, and Kopf marshals the resource data into the function's keyword arguments. The README lists available kwargs including body, meta, spec, status, name, namespace, retry, diff, old, new and logger. Return values are marshalled back into the resource status, and logging messages are published as Kubernetes events linked to the resource. That round trip is the core design: you read from kwargs, you return a value, and the framework writes it back.

Handlers come in several shapes. Low-level handlers receive events as they arrive from the Kubernetes API, comparable to informers. High-level handlers fire on detected causes such as creation, updates with diffs, or deletion. There are also timers that tick while a resource exists, daemons that run for the lifetime of a resource in threads or asyncio tasks, and admission webhooks for validating and mutating. Sync handlers are threaded under the hood, so mixing sync and async code is allowed.

Consistency is handled by retrying failed handlers until they succeed, with special exceptions to request a different retry policy or to stop retrying. Progress is persisted implicitly, which the README says survives operator restarts, and the framework tolerates restarts and lengthy downtimes by handling changes afterwards. For multiple Kopf-based operators watching the same resource kinds, configurable identities plus a peering mechanism avoid double-processing across pods, and a deployed operator can be paused while a dev-mode operator runs outside the cluster.

Installing Kopf and running a first handler

Kopf requires Python 3.10 or newer. CPython and PyPy are officially supported and tested according to the README, and the package is installed from PyPI. The project exposes a console script named kopf, declared in pyproject.toml as kopf = "kopf.cli:main".

bash
pip install kopf

A minimal operator is a single Python file. The README gives this example, which prints the spec of every newly created kopfexamples resource:

python
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}")

Save that as handlers.py and run it against your cluster with the CLI. The --verbose flag is the one shown in the README's Dockerfile example:

bash
kopf run handlers.py --verbose

For a deployment, the README's Dockerfile installs the package and starts the same command as the container entrypoint. Note that the base image in the README is python:3.14, which is above the minimum of 3.10.

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

Long-running work uses a different decorator. A daemon runs for as long as the resource exists and receives a stopped flag to check; a timer does the same on an interval.

python
import kopf

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

The repository keeps numbered examples under examples/, from 01-minimal through 17-admission and 99-all-at-once, with a crd.yaml and obj.yaml for trying them out. That directory is the fastest way to see a working operator of each shape.

Where Kopf is the wrong tool

The README is unusually direct about the project's own limits. It states that there is no active development of new major functionality, that the idea of a framework for operators is fully expressed, and that this might change. Minor feature requests can be implemented from time to time, and maintenance for new Python and Kubernetes versions happens regularly, with some internal optimizations planned around memory footprint and high-load readiness. If your roadmap depends on a feature Kopf does not have today, you should assume it will not arrive on a schedule.

The second boundary is deployment. Kopf gives you a framework, not an operator bundle. The README's small-font note is explicit that the two-file claim covers the operator itself, and that RBAC roles, bindings, service accounts and network policies are still needed for your infrastructure. Teams expecting a scaffolded project with generated manifests will be doing that work by hand.

Third, the dependencies are not trivial. The base install pulls in aiohttp, click, pyyaml, jsonpatch, iso8601 and python-json-logger. The optional full-auth extra adds pykube-ng and kubernetes, and the README's own comment marks the kubernetes package at roughly 40 MB. If image size is a hard constraint, that is a real cost to weigh. Kopf is also client-agnostic, which is a benefit for flexibility and a cost if you wanted one blessed client path.

Kopf compared with shelling out to kubectl in a controller loop

The obvious alternative for a small operator is a script that polls kubectl and acts on the output. The difference is not stylistic. A polling script has no in-memory cache of resources, no diff between old and new object state, and no persistence of which resources it has already processed. Kopf's high-level handlers receive diff, old and new, and its progress survives restarts, so a crash mid-handling does not silently skip an object. It also publishes logs as Kubernetes events tied to the resource, which a script printing to stdout does not.

The polling approach does have advantages worth naming. It has no framework dependency, no Python version floor, and no aiohttp in the image. For a one-off reconciliation that runs on a schedule and tolerates missed events, a CronJob calling kubectl is smaller and easier to reason about. Kopf earns its place when you need event-driven handling, retries with configurable limits, timers or daemons tied to resource lifetime, or admission webhooks. Below that threshold, the framework is overhead.

Licence, release cadence and the cost of upgrading

Kopf is MIT licensed, and pyproject.toml declares license = "MIT". That is permissive and places few obligations on how you distribute your operator, though the usual caveat applies that this is a description of the licence field and not legal advice.

Upgrade cost looks low by design. The README states that Kopf is production-ready and stable at semantic v1, that major bugs are fixed quickly, and that minor bugs are fixed as time and energy permit or a workaround is provided. It also states that there is no semantic v2 with breaking changes on the horizon, and that planned internal optimizations will be backwards-compatible. The recent releases follow a patch cadence: 1.44.4 on 2026-03-24, 1.44.5 on 2026-04-01 and 1.44.6 on 2026-06-03. The last push to the repository was on 2026-09-22.

The practical upgrade risk is therefore not API churn but environment churn. Version numbers are taken from git tags via setuptools-scm, and maintenance tracks new Python and Kubernetes versions. Your pinning strategy should account for the fact that the framework itself is finished while the platform underneath it keeps moving.

Editorial conclusion

Adopt Kopf if your operator logic is Python and you want event handling, retries and peering without writing informer plumbing. Do not adopt it if you need a new major feature line, since the README states there is no active development of new major functionality. Before committing, verify that your Python version is 3.10 or newer, that you are comfortable with the MIT licence, and that the RBAC and deployment manifests your operator needs are ones you are prepared to write yourself, because Kopf supplies the framework and not the deployment.

Frequently asked questions

What Python version does Kopf require?

The README states that Python 3.10 or newer is required, and that CPython and PyPy are officially supported and tested. The classifiers in pyproject.toml list 3.10 through 3.14.

How do I install and run a Kopf operator?

Install the package with pip install kopf, then run your handler file with the console script, for example kopf run handlers.py --verbose. The README shows the same command as the CMD in its Dockerfile example.

Is Kopf still actively developed?

The README states there is no active development of new major functionality and that the framework is finished, though minor feature requests may be implemented from time to time and maintenance for new Python and Kubernetes versions is performed regularly. The last push to the repository was on 2026-09-22.

Official sources

  1. License: MIT
  2. nolar/kopf on GitHub
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/nolar-kopf.svg)](https://hysenlabs.com/projects/nolar-kopf)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/nolar-kopf.svg)](https://hysenlabs.com/projects/nolar-kopf)

Was this useful?