Skip to main content

Easy Kubernetes Port-Forward For Python

Project description

https://img.shields.io/pypi/v/portforward.svg https://img.shields.io/pypi/status/portforward.svg PyPI - Downloads Documentation Status Build status

Easy Kubernetes Port-Forward For Python

Installation

Wheels are available for:

  • Windows

  • MacOS X

  • Linux

with Python versions:

  • 3.7

  • 3.8

  • 3.9

  • 3.10

  • 3.11

and architectures:

  • x84_64

  • arm64 (known as M1/Apple Chip - MacOS only)

Requirements for installation from source

The following things are required when there is no wheel available for the target system.

Pip knows how to install portforward.

pip install portforward

Quickstart

import requests

import portforward


def main():
    namespace = "test"
    pod_name = "web"  # You can also use a service name instead
    local_port = 9000  # from port
    pod_port = 80  # to port

    # No path to kube config provided - will use default from $HOME/.kube/config
    with portforward.forward(namespace, pod_name, local_port, pod_port):
        response = requests.get("http://localhost:9000")
        print(f"Done: \n'{response.status_code}'\n'{response.text[:20]}...'")


if __name__ == "__main__":
    main()

Features

  • Native Kubernetes port-forwarding with the .kube/config from the home dir or any other path to config.

  • Portforward for pods and services - the lib will first look for a pod with matching name then for a service

  • Waiting for a pod to become ready

  • Multiple forwards per pod or service

  • As context manager, sync or async client

Development

In case you want to develop on this library itself please take a look at the CONTRIBUTING page.

Credits

This project is enabled by PyO3.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

portforward-0.6.1.tar.gz (35.8 kB view hashes)

Uploaded Source

Built Distributions

portforward-0.6.1-cp311-none-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

portforward-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

portforward-0.6.1-cp311-cp311-macosx_11_0_arm64.whl (7.1 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

portforward-0.6.1-cp311-cp311-macosx_10_7_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.11 macOS 10.7+ x86-64

portforward-0.6.1-cp310-none-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

portforward-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

portforward-0.6.1-cp310-cp310-macosx_11_0_arm64.whl (7.1 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

portforward-0.6.1-cp310-cp310-macosx_10_7_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

portforward-0.6.1-cp39-none-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

portforward-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

portforward-0.6.1-cp39-cp39-macosx_11_0_arm64.whl (7.1 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

portforward-0.6.1-cp39-cp39-macosx_10_7_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

portforward-0.6.1-cp38-none-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

portforward-0.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

portforward-0.6.1-cp38-cp38-macosx_11_0_arm64.whl (7.1 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

portforward-0.6.1-cp38-cp38-macosx_10_7_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

portforward-0.6.1-cp37-none-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.7 Windows x86-64

portforward-0.6.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

portforward-0.6.1-cp37-cp37m-macosx_11_0_arm64.whl (7.1 MB view hashes)

Uploaded CPython 3.7m macOS 11.0+ ARM64

portforward-0.6.1-cp37-cp37m-macosx_10_7_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.7m macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page