Skip to main content

side-cli

Run a command with piped standard streams and bridge them to local TCP ports. Use the console, the Tk desktop window, or the async Python API. Receive stdout and stderr on separate ports or on one framed output port.

Quick start

Install uv and run these commands from the project directory. The project requires Python 3.11 or later and has no third-party runtime dependencies.

uv sync --locked
uv run side-cli run -- python -u -c "import sys; print('Ready'); print('Status', file=sys.stderr); print(input())"

Type a line in the terminal, or send it to the stdin TCP port. The example prints the line and exits. side_cli and python -m side_cli are also entry points. Put run options before -- and the child command and its arguments after it. Run side-cli run --help for supervisor options. Commands run directly; use an explicit shell for shell syntax, for example -- sh -c "printf 'hello\n'" on Linux or -- cmd /c "echo hello" on Windows.

uv run side-cli run --gui -- python -u -c "import sys; print('Ready'); print('Status', file=sys.stderr); print(input())"

The GUI shows stdout and stderr in the left-hand console. Both use the same default colors; ANSI color sequences in each stream control their text colors. When the end of the output is visible, a blinking caret marks it without changing the text or taking keyboard focus. Click the output to focus the input field; selecting output text keeps focus in the output so it can be copied. On the right, Send echoes the text immediately. Uncheck Append newline to add text to the pending line without writing to the child yet. Send a newline to deliver the full line, including the newline, to the child. The TCP panel shows each bound address, listening state, and active connection count. The window keeps the output visible after the command exits. Closing the window stops a command that is still running. GUI mode requires Tkinter and a desktop session; run uv run python -m tkinter to check. If you use the system Python on Debian or Ubuntu, install its python3-tk package if needed.

TCP and process behavior

Stream Default address Direction
stdin 127.0.0.1:8765 TCP client to child stdin
stdout 127.0.0.1:8766 Child stdout to connected TCP clients
stderr 127.0.0.1:8767 Child stderr to connected TCP clients
  • Configure ports with --stdin-port, --stdout-port, and --stderr-port. Use 0 for an available port and --show-ports to print the actual addresses. Listeners accept unauthenticated connections from the local machine only.
  • The stdin port carries LF-delimited byte frames. Separate output ports carry raw bytes. Output goes to clients connected at the time of the write, with no replay. To capture output from the first byte, use --wait-for-output-clients and connect to each enabled output port before the child starts. Keep output clients connected in both directions until done. A slow client may be disconnected to keep other readers moving.
  • Both modes mirror the child's stdout and stderr separately. Console mode also forwards terminal or piped stdin, unless you set --no-local-stdin. The GUI, local stdin, and each input connection buffer their own input until a newline. Complete lines from concurrent sources can interleave only between lines. On EOF an incomplete line is discarded; stdin stays open for other clients unless --close-stdin-on-eof is set. Combine that option with --no-local-stdin for commands that read TCP input until EOF.
  • Input echo is a local display feature. The GUI and the terminal running side-cli run show submitted GUI and TCP input, even before a newline. A terminal keyboard already provides its own echo. Synthetic echo is not sent to the child, the TCP output ports, panel, or redirected stdout or stderr. Output echoed by the child itself is still forwarded normally.
  • Ctrl+C reaches the child as SIGINT on Linux. On Windows, the child shares the console and receives the native Ctrl+C event directly. A child that handles the interrupt can clean up or continue. Console mode returns the child's exit code, with POSIX signal exits reported as 128 + signal.
  • The child gets pipes, not a terminal. For timely output from buffered commands, enable their unbuffered mode (such as Python's -u). The GUI renders ANSI foreground and background colors (basic, bright, 256-color, and RGB), but does not emulate cursor movement or screen clearing. If a command disables colors when writing to a pipe, use its force-color option.
  • On Windows, when launching cmd.exe directly, side-cli removes Clink's hidden tag from the child PROMPT but preserves the rest of the prompt. Clink's interactive editing and completion still require a console.

Text encoding

--encoding describes the encoding used by the child process. It defaults to utf-8 and accepts Python text encodings such as gb2312, gbk, and cp936. Choose the encoding that matches the command; the option does not change the child's locale or code page.

uv run side-cli run --gui --encoding gb2312 -- cmd.exe
uv run side-cli panel --port 8766 --encoding gb2312
uv run side-cli input --port 8765 --encoding gb2312

run converts terminal and GUI text in both directions. panel decodes output for the terminal, and input encodes lines typed at the terminal. Redirected files and pipes, TCP payloads, and the byte-oriented Python API do not transcode. Byte-framed input uses encodings with an ASCII LF, such as UTF-8, GB2312, and GBK. Each client sets its own encoding for terminal display or entry; the TCP protocol does not negotiate encodings.

Single framed output port

Set --output-port to replace both output TCP listeners with one connection point carrying both streams. This option cannot be combined with --stdout-port or --stderr-port. The stdin listener, local output, and GUI ANSI rendering keep their existing behavior. The GUI and --show-ports report one combined output listener; --wait-for-output-clients waits for one client on it.

uv run side-cli run --output-port 8766 --wait-for-output-clients --no-local-stdin -- python -u -c "import sys; print('Ready'); print('Status', file=sys.stderr); sys.stdout.writelines(sys.stdin)"

In a second terminal, connect to the framed output port:

uv run side-cli panel --port 8766

panel writes frames to its own stdout or stderr according to their stream ID. Redirect either stream independently to capture its raw bytes. The child still writes to the supervisor's own stdout and stderr too.

In a third terminal, send lines to the stdin port:

uv run side-cli input --port 8765

input writes nothing to stdout and reports connection errors to stderr. It forwards complete lines, preserving line endings, and drops any final unterminated line at local EOF. Multiple input clients can connect at once. Ctrl+C disconnects that input client without sending a signal or an orderly EOF to the child. An ordinary local EOF disconnects cleanly and leaves child stdin open unless the supervisor was started with --close-stdin-on-eof. Use separate terminals for the supervisor and its clients so Ctrl+C goes to the intended command.

Frame format

The stdin connection uses LF (0x0a) as the frame delimiter. A frame includes its delimiter; CRLF is passed through unchanged. One TCP read may contain several frames, and a single frame can span reads. The supervisor buffers at most 1 MiB per line, including the delimiter. An oversized line closes that input connection. An incomplete line is never written to the child.

The combined output port uses a separate protocol:

The connection carries consecutive binary frames with no initial preamble:

Field Size Value
Stream ID 1 byte 1 = stdout, 2 = stderr
Payload length 4 bytes Unsigned big-endian byte count, 1–65,536
Payload As specified above Raw bytes from the selected stream, including ANSI escapes

Read five bytes for the header, then exactly the specified number of payload bytes. Frames represent chunks, not lines, characters, or individual child writes. Each stream retains its own byte order. Frames from the two streams interleave in the order side-cli reads them. EOF at a frame boundary ends the connection; EOF inside a frame indicates truncation.

Python API

Import Supervisor, Ports, and Stream from side_cli. An async context opens the listeners on entry and releases them on exit. start() launches the child; wait() drains its output and returns its original exit code.

import asyncio
import sys

from side_cli import Ports, Stream, Supervisor


def show_output(stream: Stream, data: bytes) -> None:
    destination = sys.stdout if stream is Stream.STDOUT else sys.stderr
    destination.buffer.write(data)
    destination.buffer.flush()


async def main() -> int:
    command = [sys.executable, "-u", "-c", "print(input())"]
    async with Supervisor(command, ports=Ports(0, 0, 0), on_output=show_output) as child:
        print(child.status()[Stream.STDIN].port, flush=True)
        await child.start()
        await child.send(b"Hello from Python\n")
        await child.close_stdin()
        return await child.wait()


if __name__ == "__main__":
    raise SystemExit(asyncio.run(main()))

on_output can also be an async function. It receives raw chunks in order within each stream; stdout and stderr may interleave. status() exposes port and connection information, including when the child has not started yet. Supervisor.send() is the low-level raw stdin write for programs that need to bypass line framing. To display TCP input separately, supply on_input_echo with a synchronous or async callback that receives text decoded with input_encoding (UTF-8 by default). Pass Ports(stdin=0, output=0) to enable framed mode with automatic ports. In this mode, status()["output"] reports the combined listener, and on_output still receives the original Stream.STDOUT or Stream.STDERR. The stdout and stderr port settings apply only in separate-port mode. Call listen() directly if you need to bind before starting without a context manager, and use aclose() to clean up. An embedding app owns its own signal handlers. On Windows, use the default asyncio Proactor event loop.

TCP clients

Import PanelClient and InputClient from side_cli. Both connect to the local supervisor as async context managers. PanelClient yields (Stream.STDOUT, bytes) or (Stream.STDERR, bytes) pairs until the connection ends; malformed or truncated frames raise ValueError. InputClient.send() writes bytes unchanged to the TCP connection, and send_line() appends an LF if one is missing. The supervisor only forwards complete LF-delimited lines. Context cancellation aborts the input connection rather than sending an orderly EOF. Use close(abort=True) for an explicit abort.

import sys

from side_cli import InputClient, PanelClient, Stream


async def receive_output(port: int = 8766) -> None:
    async with PanelClient(port) as panel:
        async for stream, data in panel:
            destination = sys.stdout if stream is Stream.STDOUT else sys.stderr
            destination.buffer.write(data)
            destination.buffer.flush()


async def send_input(port: int = 8765) -> None:
    async with InputClient(port) as client:
        await client.send_line(b"Hello from Python")

Build

uv build

Released under the MIT License.

Metadata

Release files for side-cli 0.1.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 side-cli 0.1.0
File Size Uploaded Provenance Actions
side_cli-0.1.0.tar.gz 20.4 kB Without provenance Details for side_cli-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for side-cli 0.1.0
File Interpreter ABI Platform Actions
side_cli-0.1.0-py3-none-any.whl Python 3 none any Details for side_cli-0.1.0-py3-none-any.whl

Total release size: 44.1 kB

Release files / side_cli-0.1.0.tar.gz

Download URL side_cli-0.1.0.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
047bc73c897e82dc18a8b8a29185f74fc9a3c7842bb11f8ea2e0a82b75562171
BLAKE2b-256 checksum
How to use checksums
732f8c651fb9fc22a8e1b3ca8873455fcf5a04689a79227a3a0f213f782df2c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Windows/11

Release files / side_cli-0.1.0-py3-none-any.whl

Download URL side_cli-0.1.0-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bb13e30908f9b052a419a1f6ad0b3504dccf04750ebb2c104057a2fbff22ed2
BLAKE2b-256 checksum
How to use checksums
6e79c3ec5c18e1e49a573a59aec6d2787fff7caa826ffaad311793a91a88f162
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Windows/11

Security for side-cli 0.1.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

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