portforward
Easy Kubernetes Port-Forward For Python
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 portforwarduv
uv add portforwardpoetry
poetry add portforwardInstalling 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
Tags
More Networking packages
h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
psutilpsutil retrieves real-time information about…
permissive · top 1,000 on PyPI
pyOpenSSLpyOpenSSL wraps OpenSSL's SSL/TLS functionality…
permissive · top 1,000 on PyPI
uvloopuvloop is a drop-in replacement for Python's…
permissive · top 1,000 on PyPI
execnetexecnet lets you spawn and communicate with…
permissive · top 1,000 on PyPI
pyzmqPyZMQ provides Python bindings for ZeroMQ…
permissive · top 1,000 on PyPI
kr8sA Python client library for Kubernetes that…
permissive · top 5,000 on PyPI
pykube-ngpykube-ng is a Python client library for…
permissive · top 15,000 on PyPI
kubernetesProvides a Python interface to the Kubernetes…
permissive · top 1,000 on PyPI
k8s-agent-sandboxA Python client library for creating and…
permissive · top 15,000 on PyPI
kubernetes-asyncioAsynchronous Python client for the Kubernetes…
permissive · top 5,000 on PyPI
kopfKopf is a Python framework for building…
permissive · top 5,000 on PyPI
kfp-kubernetesExtends Kubeflow Pipelines SDK with…
permissive · top 15,000 on PyPI
pulumi-kubernetesPulumi Kubernetes Resource Provider lets you…
permissive · top 5,000 on PyPI
ngrokExposes ngrok's secure gateway service to…
permissive · top 15,000 on PyPI
foxglove-sdkIntegrates Python applications with the…
permissive · top 15,000 on PyPI