Skip to main content

Pseudo terminal support for Windows from Python.

Project description

PyWinpty: Pseudoterminals for Windows in Python

Project License - MIT pypi version conda version download count Downloads PyPI status Windows tests

Copyright © 2017–2022 Spyder Project Contributors Copyright © 2022– Edgar Andrés Margffoy Tuay

Overview

PyWinpty allows creating and communicating with Windows processes that receive input and print outputs via console input and output pipes. PyWinpty supports both the native ConPTY interface and the previous, fallback winpty library.

Dependencies

To compile pywinpty sources, you must have Rust installed. Optionally, you can also have Winpty's C header and library files available on your include path.

Installation

You can install this library by using conda or pip package managers, as it follows:

Using conda (Recommended):

conda install pywinpty

Using pip:

pip install pywinpty

Building from source

To build from sources, you will require both a working stable or nightly Rust toolchain with target x86_64-pc-windows-msvc, which can be installed using rustup.

Optionally, this library can be linked against winpty library, which you can install using conda-forge:

conda install winpty -c conda-forge

If you don't want to use conda, you will need to have the winpty binaries and headers available on your PATH.

Finally, pywinpty uses Maturin as the build backend, which can be installed using pip:

pip install maturin

To test your compilation environment settings, you can build pywinpty sources locally, by executing:

maturin develop

This package depends on the following Rust crates:

  • PyO3: Library used to produce Python bindings from Rust code.
  • WinPTY-rs: Create and spawn processes inside a pseudoterminal in Windows from Rust.
  • Maturin: Build system to build and publish Rust-based Python packages.

Package usage

Pywinpty offers a single python wrapper around winpty library functions. This implies that using a single object (winpty.PTY) it is possible to access to all functionality, as it follows:

# High level usage using `spawn`
from winpty import PtyProcess

proc = PtyProcess.spawn('python')
proc.write('print("hello, world!")\r\n')
proc.write('exit()\r\n')
while proc.isalive():
	print(proc.readline())

# Low level usage using the raw `PTY` object
from winpty import PTY

# Start a new winpty-agent process of size (cols, rows)
cols, rows = 80, 25
process = PTY(cols, rows)

# Spawn a new console process, e.g., CMD
process.spawn(br'C:\windows\system32\cmd.exe')

# Read console output (Unicode)
process.read()

# Write input to console (Unicode)
process.write(b'Text')

# Resize console size
new_cols, new_rows = 90, 30
process.set_size(new_cols, new_rows)

# Know if the process is alive
alive = process.isalive()

# End winpty-agent process
del process

Running tests

We use pytest to run tests as it follows (after calling maturin develop), the test suite depends on pytest-lazy-fixture, which can be installed via pip:

pip install pytest pytest-lazy-fixture flaky

All the tests can be executed using the following command

python runtests.py

Changelog

Visit our CHANGELOG file to learn more about our new features and improvements.

Contribution guidelines

We follow PEP8 and PEP257 for pure python packages and Rust to compile extensions. We use MyPy type annotations for all functions and classes declared on this package. Feel free to send a PR or create an issue if you have any problem/question.

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pywinpty-3.0.4-cp314-cp314t-win_arm64.whl (237.1 kB view details)

Uploaded CPython 3.14tWindows ARM64

pywinpty-3.0.4-cp314-cp314t-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.14tWindows x86-64

pywinpty-3.0.4-cp314-cp314-win_arm64.whl (238.2 kB view details)

Uploaded CPython 3.14Windows ARM64

pywinpty-3.0.4-cp314-cp314-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.14Windows x86-64

pywinpty-3.0.4-cp313-cp313t-win_arm64.whl (237.0 kB view details)

Uploaded CPython 3.13tWindows ARM64

pywinpty-3.0.4-cp313-cp313t-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.13tWindows x86-64

pywinpty-3.0.4-cp313-cp313-win_arm64.whl (238.0 kB view details)

Uploaded CPython 3.13Windows ARM64

pywinpty-3.0.4-cp313-cp313-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.13Windows x86-64

pywinpty-3.0.4-cp312-cp312-win_arm64.whl (238.5 kB view details)

Uploaded CPython 3.12Windows ARM64

pywinpty-3.0.4-cp312-cp312-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.12Windows x86-64

pywinpty-3.0.4-cp311-cp311-win_arm64.whl (240.9 kB view details)

Uploaded CPython 3.11Windows ARM64

pywinpty-3.0.4-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11Windows x86-64

pywinpty-3.0.4-cp310-cp310-win_arm64.whl (240.6 kB view details)

Uploaded CPython 3.10Windows ARM64

pywinpty-3.0.4-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10Windows x86-64

File details

Details for the file pywinpty-3.0.4-cp314-cp314t-win_arm64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 819eb417254eac67553c93d2f38b12617bb0ebb65e6b840d51fe7e5a4a824646
MD5 cb3b27f945cbae23eea6c9b29893fb26
BLAKE2b-256 2a40a94cf31db8a759ed871c0e9f10f8aa0a042ddc6592f233a26a4c0d757047

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 3771c364b38a5e4956582ee68d912e35763d78310e362ddce6d390cf5ff94f58
MD5 dea1f1ed1a8affcc1dbb05f662030bba
BLAKE2b-256 b08648fb10e2c7db43461dcc69179e81a648ebf8f350271c8cc079aed65b354b

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp314-cp314-win_arm64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp314-cp314-win_arm64.whl
Algorithm Hash digest
SHA256 171b60831057b519bc3673970eb970352b99e6efdfd22cad169b7a815699d862
MD5 d21e5280dbc7564925d3d472511837c5
BLAKE2b-256 4cae76cc0e1e9fa92ce1dddb3d90d082c5eb0facb1665446019916156e244ba6

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 b028b4d8ece77a4b35282461234d2e38c472c6dc4be6e5cccdeffcd2776ebf7f
MD5 d4a93c84825376e07bb1b0bd7f20ca93
BLAKE2b-256 5b7739af026e681e350073495155d885b82947a88b29ae7a61f016e1ac8c744e

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp313-cp313t-win_arm64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp313-cp313t-win_arm64.whl
Algorithm Hash digest
SHA256 1ab08db89053c0f31405c842c129c8f1a2610b463861ac22202c763cdbb16d75
MD5 d5ba7d2c2894c7ee0eb3fbb2e05677d7
BLAKE2b-256 ec0de10f2516703e3141d84948a46ec253d47c8ad04e78ec37e508f7c7a8a9a2

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp313-cp313t-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 397e12405c5c8749bac56bb447453d6200a515cf8ef3802e1a83dd3fb2e7384a
MD5 6ce15110e2f3ede22df8896f928b489d
BLAKE2b-256 d9dca087e1d8ad4bc5c8ae61fb23cb104fadc55e9242c22dd81620483b648b1e

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp313-cp313-win_arm64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp313-cp313-win_arm64.whl
Algorithm Hash digest
SHA256 f8fae0cdbf3d7c9a3e72490d2460dedc4c050fd1eff5d3b715097bea89cb9239
MD5 df1f0fa83965f2a901c5cefc29845457
BLAKE2b-256 c9ca4b554caf70f2821b3dd5f58208b584a821eeabff56643049d1938dca9306

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b63b22ab53fea5ae3f10a55180efb8d089be82632256d9a783c1f6dbfc3faf29
MD5 c6c702e2daa499690bd546ab32d3d676
BLAKE2b-256 d677f5db2802d2583af7b52eec513cbcabc521daa5fe2cb57380b2e1245cac64

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp312-cp312-win_arm64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp312-cp312-win_arm64.whl
Algorithm Hash digest
SHA256 8b26b58eff31fea6018afe6e1eba47382ccee1e879376b09a591ff3259d5a4e3
MD5 7941d7dd75a2f511f11c5a45149f7d8d
BLAKE2b-256 b1e8672de7fafae62dfbc0b57bb5d825bfcca97cc3050fe090d222edc2b7f756

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3c8af7d7f37e7d2a2bcfd5625fbd6158b49fef620b6d10682d081f63b47c6aab
MD5 7f019905e98062ef4fe87b5e671ec678
BLAKE2b-256 b755e5a95c61e693941458dbf6ed8164c766e6166802364efabe1d610533e6b7

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp311-cp311-win_arm64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp311-cp311-win_arm64.whl
Algorithm Hash digest
SHA256 27af19cb9f633ae04bf4062fc8e89042d4d60ea99678e8b44ea1f412ac2b4a77
MD5 f255127c96e97d3b39c3dff02ff8ee44
BLAKE2b-256 2031393eed64a7d1951e155bc34039f47fc1af661442f356dae9b0a514a2e087

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7648ef6c572896859efcba546026ceed6c6790deb7891246cbacc3d31e1eed56
MD5 4e59e04b5a3a753e776e039feeef19d4
BLAKE2b-256 354ea0d067b2a8762cf85dd9c409c9ad6650621ff6fb5b29c5d6834f5401890c

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp310-cp310-win_arm64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp310-cp310-win_arm64.whl
Algorithm Hash digest
SHA256 368323d836edf6b3f81c7b2dab8493d0d6df3796080963bf03109a0e2f6afeb9
MD5 9184111c3f81f81396f59884a06cc632
BLAKE2b-256 c244c5d5cc8f1e58db1b2c060f96cea1c2ce4e806768647cc22529e17af60eaa

See more details on using hashes here.

File details

Details for the file pywinpty-3.0.4-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-3.0.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 aa231b3e63bf8b97170d0889225c1805390d3839675c6a9398bdc26a4603ee3b
MD5 de9d54e86f56897d7194a4eed44a7c16
BLAKE2b-256 91399fcb2d8c796e222ef95ddc0b72dbc8907d9a42eb4d8ea40f6bcf5dfe75bb

See more details on using hashes here.

Supported by

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