Skip to main content
Build status

pfm – a ssh port forward manager for data scientists

Data scientists launch a Jupyter Notebook servers to tackle each machine learning task. Usually local computers are not enough to handle multiple machine learning tasks. And therefore data scientists do their experiments in servers launched in remote hosts such as EC2 instances.

To connect Jupyter Notebook servers in remote hosts, we use ssh port forwarding. Port forwarding is useful since we do not consume resources in local PC.

Unfortunately, when connecting servers in multiple remote hosts and ports numbers, we easily forget the port number or assign the local port number which is used in another task. Especially when there are multiple remote hosts and ssh servers as the following image, understanding the combinations of remote hosts and local ports are difficult.

images/port-forwarding.jpeg

pfm manages the remote hosts and port numbers used in port forwarding. Users understand which local ports are used and which ports are not. Once users register the port forwarding information, pfm generates ssh parameters any time specifying the task name.

Install

We can install pfm with pip.

pip install pfm

Usage

Register settings of ssh port forwarding

pfm add registers port forward settings.

Register settings with options

The following is a sample of adding port forward settings with command line options.

$ pfm add -n image-classification --local-port 9999 --remote-port 8888 --ssh-server myml.aws.com --remote-host localhost

pfm add provides the following options.

Usage: pfm add [OPTIONS]

add port forwarding target

Options:
    -n, --name TEXT        name of port fowarding
    --forward-type TEXT    port forwarding type [L (local) or R (remote)]
    --local-port INTEGER   local port
    --remote-port INTEGER  remote host port
    --ssh-server TEXT      server to ssh login
    --server-port INTEGER  server port
    --remote-host TEXT     remote host for port forwarding
    --login-user TEXT      login user of ssh server
    --help                 Show this message and exit.

Note that when local port number (--local-port) is not specified, pfm add automatically assigns the local port not to collide to other port forward settings.

Register settings with a argument

If you think adding many options are tedious, pfm add also provides argument style of registration.

The following is a sample of registration which forwards port 8888 in takahi-i-ml.aws.com to port 9999 of localhost with a local port forward setting.

$pfm add -n image-classification "9999:localhost:8888 takahi-i-ml.aws.com"

As we see the above example is simple and just uses -n option. Note that default forward type is set to local (L). If you want to set forward type to remote please specify the type with --forward_type parameter.

Generate ssh port forward parameters

After the registration of port forward settings with pfm add , we can generate ssh parameters with pfm param.

$ ssh `pfm param image-classification`

Or we can also use pfm connect in order to do same (Note that this command includes -A ssh option).

$ pfm connect image-classification

Update port forward settings

After the registration of port forward settings with pfm add , we can modify ssh parameters with pfm update. For example, the following command changes the port forwarding type of image-classification setting from local to remote.

$ pfm update --name image-classification --forward-type R

List registered ssh port forward settings

We can see the list of registered port forward settings.

$ pfm list
+----------------------+------------+------------+--------------------------------+--------------+-----------------+--------------------------------+--------------+
|         name         |    type    | local_port |          remote_host           | remote_port  |   login_user    |           ssh_server           | server_port  |
+======================+============+============+================================+==============+=================+================================+==============+
| image-processing     | L          | 9999       | localhost                      | 8888         | None            | my-ml-instance.aws.com         |              |
+----------------------+------------+------------+--------------------------------+--------------+-----------------+--------------------------------+--------------+
| text-processing      | L          | 7777       | localhost                      | 8888         | None            | my-ml-instance-2.aws.com       |              |
+----------------------+------------+------------+--------------------------------+--------------+-----------------+--------------------------------+--------------+

Delete registered forwarding setting

When a port forward settings is not needed, we can remove the setting with pfm delete command

$ pfm delete image-process

License

  • Free software: MIT license

Resources

Slides on pfm.

For developers

We are welcome any contribution. For details, please see CONTRIBUTING.rst.

Metadata

Release files for pfm 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pfm 0.6.0
File Size Uploaded
pfm-0.6.0.tar.gz 10.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pfm 0.6.0
File Interpreter ABI Platform
pfm-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.0 kB

Release files / pfm-0.6.0.tar.gz

Download URL pfm-0.6.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
371ed512188624c2ba6f4b48a3ace2b7695393dcd89e4d464d658c17b024ab60
BLAKE2b-256 checksum
How to use checksums
de0566a87ccf4c89ea347905ea6418d1cf03eceb36d048e9082d510e8a21cf7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.3 Darwin/19.2.0

Release files / pfm-0.6.0-py3-none-any.whl

Download URL pfm-0.6.0-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ae06448981b579768296a45e5d257f43c6fc3135e131e066605a6e79e8b2148
BLAKE2b-256 checksum
How to use checksums
27881840ba4155f59d47912745ffd7d462ec7bc2eb3b38100885a6d983d3706d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.3 Darwin/19.2.0

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.1

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page