Skip to main content

Kubernetes Port-Forward Go-Edition For Python

Project description

portforward

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

Kubernetes Port-Forward Go-Edition For Python

Installation

Wheels are available for:

  • Windows

  • MacOS X

  • Linux

with Python versions:

  • 3.6

  • 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.

  • Go installed and available in the path (at least v1.16 / https://go.dev)

  • Python (at least v3.6 - below was never tested but might work)

  • gcc (for Windows available via MinGW)

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

  • Go 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

Development

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

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

This project is enabled by setuptools-golang.

History

unreleased

  • Move pytogo Go code into portforward

0.4.5 (2023-03-06)

  • Fix panic when logging an error

  • Change default log level to INFO

0.4.4 (2023-02-28)

  • Fix endless waiting

0.4.3 (2023-02-27)

  • Throw error instead of panic when port is in usage

0.4.2 (2023-02-06)

  • Use in-cluster-config when no kube config file is available

0.4.1 (2023-02-01)

  • Bump pytogo/portforward version

0.4.0 (2023-01-31)

  • Respect environment variable KUBECONFIG

  • Wait if a pod is not ready yet

  • Be able to use service as targets

0.3.1 (2022-12-26)

  • Allow selecting kubernetes target context

0.3.0 (2022-10-08)

  • Introduction of logging level as replacement for verbose mode

0.2.8 (2022-08-22)

  • Added verbose mode

0.2.7 (2021-10-05)

  • Added missing import

  • Added type hint

0.2.6 (2021-10-05)

  • Fixed type hint

0.2.5 (2021-09-09)

  • Moved the actual portforward to own module

0.2.4 (2021-08-23)

  • Added adal import for Azure AD

  • Fixed host IPs with paths

  • Made timeout flexible

0.2.3 (2021-08-23)

  • Fixed case when hostIP contains a path

  • Added common and cloud provider auth plugins

0.2.2 (2021-08-23)

  • Fixed missing module portforward

0.2.1 (2021-08-19)

  • Decrease binary size if pre-compile wheels (Improvement of setuptools-golang)

0.2.0 (2021-08-14)

  • First Release on PyPI.

  • Made path to kube config variable.

  • Port-forwarding became non-blocking.

  • Fixed verification bug when port was None.

  • Added throwing own error.

0.1.0 (2021-08-09)

  • First release on Test PyPI.

  • Blocking port-forward with fixed path for kube config.

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.4.5.tar.gz (95.6 kB view hashes)

Uploaded Source

Built Distributions

portforward-0.4.5-cp311-cp311-win_amd64.whl (8.5 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

portforward-0.4.5-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

portforward-0.4.5-cp311-cp311-macosx_13_0_arm64.whl (8.4 MB view hashes)

Uploaded CPython 3.11 macOS 13.0+ ARM64

portforward-0.4.5-cp311-cp311-macosx_10_14_x86_64.whl (9.3 MB view hashes)

Uploaded CPython 3.11 macOS 10.14+ x86-64

portforward-0.4.5-cp310-cp310-win_amd64.whl (8.5 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

portforward-0.4.5-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

portforward-0.4.5-cp310-cp310-macosx_13_0_arm64.whl (8.4 MB view hashes)

Uploaded CPython 3.10 macOS 13.0+ ARM64

portforward-0.4.5-cp310-cp310-macosx_10_14_x86_64.whl (9.3 MB view hashes)

Uploaded CPython 3.10 macOS 10.14+ x86-64

portforward-0.4.5-cp39-cp39-win_amd64.whl (8.5 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

portforward-0.4.5-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

portforward-0.4.5-cp39-cp39-macosx_13_0_arm64.whl (8.4 MB view hashes)

Uploaded CPython 3.9 macOS 13.0+ ARM64

portforward-0.4.5-cp39-cp39-macosx_10_14_x86_64.whl (9.3 MB view hashes)

Uploaded CPython 3.9 macOS 10.14+ x86-64

portforward-0.4.5-cp38-cp38-win_amd64.whl (8.5 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

portforward-0.4.5-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

portforward-0.4.5-cp38-cp38-macosx_13_0_arm64.whl (8.4 MB view hashes)

Uploaded CPython 3.8 macOS 13.0+ ARM64

portforward-0.4.5-cp38-cp38-macosx_10_14_x86_64.whl (9.3 MB view hashes)

Uploaded CPython 3.8 macOS 10.14+ x86-64

portforward-0.4.5-cp37-cp37m-win_amd64.whl (8.5 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

portforward-0.4.5-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view hashes)

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

portforward-0.4.5-cp37-cp37m-macosx_13_0_arm64.whl (8.4 MB view hashes)

Uploaded CPython 3.7m macOS 13.0+ ARM64

portforward-0.4.5-cp37-cp37m-macosx_10_14_x86_64.whl (9.3 MB view hashes)

Uploaded CPython 3.7m macOS 10.14+ x86-64

portforward-0.4.5-cp36-cp36m-win_amd64.whl (8.5 MB view hashes)

Uploaded CPython 3.6m Windows x86-64

portforward-0.4.5-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

portforward-0.4.5-cp36-cp36m-macosx_13_0_arm64.whl (8.4 MB view hashes)

Uploaded CPython 3.6m macOS 13.0+ ARM64

portforward-0.4.5-cp36-cp36m-macosx_10_14_x86_64.whl (9.3 MB view hashes)

Uploaded CPython 3.6m macOS 10.14+ 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