skillfed

portforward

Easy Kubernetes Port-Forward For Python

portforward v0.7.6 275.5K downloads/30d#8,174 on PyPI25
Permissive license MIT License Active released

What it is and what it does

portforward is a Python library that wraps Kubernetes port-forwarding functionality, letting you programmatically tunnel local ports to pods or services in a cluster without invoking kubectl as a subprocess. It reads your kubeconfig (or a path you provide) and establishes the same kind of port-forward connection that kubectl port-forward would create, but from within Python code.

The library is built on Rust via PyO3 for performance and reliability. It supports both synchronous context-manager usage and async clients, can forward to either pods or services (trying pods first), and handles multiple forwards per target. It's useful for integration testing, local development against staging clusters, or any scenario where you need programmatic access to remote services without manual kubectl commands.

Use it for:

  • Integration tests that need to reach Kubernetes services from a test runner without spawning kubectl subprocesses.
  • Local development workflows where you want to proxy a remote service to localhost within a Python application.
  • Automated deployment or health-check scripts that need to temporarily access cluster services.
  • Multi-service testing setups where you forward several pods to different local ports in a single test session.

Worth the install?

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

Provides Python bindings for Kubernetes port-forwarding, allowing you to forward local ports to pods or services in a cluster using your kubeconfig file.

Yes, if you need programmatic Kubernetes port-forwarding in Python. The package is actively maintained, has no known vulnerabilities, supports modern Python versions with pre-built wheels, and solves a real problem for developers and CI/CD pipelines. The MIT license is permissive. Install friction is moderate due to Rust compilation, but wheels cover most platforms. Start with the quickstart example in the documentation.

Install

portforward on PyPI

pip

pip install portforward

uv

uv add portforward

poetry

poetry add portforward

Installing portforward

Before you install

Medium install friction due to compiled Rust components, but wheels are available for Python 3.9–3.13 across Windows, macOS, and Linux (including Alpine). Installation from source requires Rust toolchain. Last release was 197 days ago; repository is active with recent commits.

License in practice

MIT License permits commercial and private use with minimal restrictions; you may use, modify, and distribute this package freely as long as you include the license notice.

Quickstart

pip install portforward

import portforward

with portforward.forward("default", "my-pod", 9000, 80):
    # Local port 9000 now forwards to port 80 on the pod
    pass

Requires a valid kubeconfig file (defaults to ~/.kube/config) and access to a Kubernetes cluster; Rust is needed only if installing from source on an unsupported platform.

Verify before relying

  • Whether the package supports async/await patterns beyond the context manager interface mentioned in the description.
  • Performance characteristics and limits on concurrent port forwards or sustained traffic throughput.
  • Compatibility with non-standard kubeconfig formats or authentication methods beyond standard kubectl setup.

Package facts

License MIT License (permissive)
Python support supports the current Python release (>=3.7)
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance actively maintained — 197 days since the last release
Last repo commit
First released
Downloads 275,535/month — #8,174 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: portforward-0.7.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; portforward-0.7.6-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; portforward-0.7.6-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl; portforward-0.7.6-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl; portforward-0.7.6-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl; portforward-0.7.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; portforward-0.7.6-cp310-cp310-musllinux_1_2_aarch64.whl; portforward-0.7.6-cp310-cp310-musllinux_1_2_armv7l.whl; portforward-0.7.6-cp310-cp310-musllinux_1_2_i686.whl; portforward-0.7.6-cp310-cp310-musllinux_1_2_x86_64.whl; portforward-0.7.6-cp310-cp310-win_amd64.whl; portforward-0.7.6-cp311-cp311-macosx_10_12_x86_64.whl; portforward-0.7.6-cp311-cp311-macosx_11_0_arm64.whl; portforward-0.7.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; portforward-0.7.6-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; portforward-0.7.6-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl; portforward-0.7.6-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl; portforward-0.7.6-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl; portforward-0.7.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; portforward-0.7.6-cp311-cp311-musllinux_1_2_aarch64.whl

Keywords: portforward, kubernetes, k8s

Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyProgramming Language :: Rust

Tags

kubernetes port forward pythonk8s port forwarding librarykubectl port-forward programmaticlocal port to pod tunnelkubernetes service proxy python
kubernetesport-forwardingdevops

More Networking packages