Skip to main content

PyVirtualSerialPorts

A Python implementation of virtual serial ports. Useful for developing and testing programs which need to talk to a serial port.

You can:

  • Create a virtual port which echoes back any data sent to it: Demo showing characters being entered into a terminal emulator being echoed back

  • Create a two or more ports; sending data to one sends data to the others: Demo showing characters being sent alternately into two terminal emulators, with the characters appearing on the opposite terminal.

  • Monitor what is being sent between the ports: Demo showing characters being sent alternately in two terminal emulators, with the characters appearing on both terminals, and debug data showing in the pyvirtualserialports output.

It should work on Python 3.5+, however is only tested on supported Python versions.

Has no dependencies other than the Python standard library.

Currently works on *nix type systems. Tested on Ubuntu and MacOS, but should work on others e.g. BSD. Windows support is being worked on.

Installation

Install for current user

$ pip3 install PyVirtualSerialPorts

Install system-wide

$ sudo pip3 install PyVirtualSerialPorts

Running

If the script install folder is in your PATH (almost certainly the case if installed as root), you can simply run:

$ virtualserialports ...

Otherwise, you can use it as a module:

$ python3 -m virtualserialports ...

Usage

usage: virtualserialports [-h] [-l] [-d] num_ports

positional arguments:
  num_ports       number of ports to create

optional arguments:
  -h, --help      show this help message and exit
  -l, --loopback  echo data back to the sending device too
  -d, --debug     log received data to stderr

Examples

Create a single port, and echo back anything sent to it

$ virtualserialports -l 1

The created port will be printed on the command line e.g. /dev/pts/0, and can be used with any serial program, e.g. minicom:

$ minicom -D /dev/pts/0

Create a pair of ports, sending the data between them

$ virtualserialports 2

The two created ports will be printed, and again can be used with any serial program. E.g. in one terminal window:

$ minicom -D /dev/pts/0

and in a second:

$ minicom -D /dev/pts/1

Now typing data on one terminal will appear in the other.

Create three ports, sending data received from any of them to all three

$ virtualserialports -l 3

Use as a library

As of version 2.0.0, much improved support has been added for use as a library, with processing done in the background.

It is recommended to use as a context manager, which will handle setup and clean up nicely:

with VirtualSerialPorts(2) as ports:
    print(f'Port 1: {ports[0]}')
    print(f'Port 2: {ports[1]}')

    # Open and use ports as required.
    # When the context manager ends, ports will be removed.

ports is a list of strings, which can be used to open the ports, e.g with PySerial. A complete example is in example.py.

It can also be used without a context manager as follows:

vsp = VirtualSerialPorts(2)
vsp.open()
# `vsp.ports` is a list of strings of the created ports.

vsp.start()
# Use ports as you wish here.
vsp.stop()
vsp.close()

Metadata

Release files for PyVirtualSerialPorts 2.0.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 PyVirtualSerialPorts 2.0.0
File Size Uploaded Provenance
pyvirtualserialports-2.0.0.tar.gz 6.0 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 12.9 kB

Release files / pyvirtualserialports-2.0.0.tar.gz

Download URL pyvirtualserialports-2.0.0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0caa0f3b45911b0d818095cd0f0253ef2be0e1b9bd181b01f05d5ea7b6659a9a
BLAKE2b-256 checksum
How to use checksums
7c55e75f1c5d060f6e296966e74f4c8352bbafae9dd7248990924d3b1037f128
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / pyvirtualserialports-2.0.0-py3-none-any.whl

Download URL pyvirtualserialports-2.0.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d86177e8f2d0ddd1e04bd399a329f220a9c7b668dc14129417d9b556874f1f67
BLAKE2b-256 checksum
How to use checksums
997074328f514f27a233be781c628c40872e1408973e02538a536360e6a81f87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for PyVirtualSerialPorts 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

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