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

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

pywinpty-2.0.15.tar.gz (29.0 kB view details)

Uploaded Source

Built Distributions

pywinpty-2.0.15-cp313-cp313t-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13tWindows x86-64

pywinpty-2.0.15-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

pywinpty-2.0.15-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12Windows x86-64

pywinpty-2.0.15-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11Windows x86-64

pywinpty-2.0.15-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10Windows x86-64

pywinpty-2.0.15-cp39-cp39-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file pywinpty-2.0.15.tar.gz.

File metadata

  • Download URL: pywinpty-2.0.15.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for pywinpty-2.0.15.tar.gz
Algorithm Hash digest
SHA256 312cf39153a8736c617d45ce8b6ad6cd2107de121df91c455b10ce6bba7a39b2
MD5 d0f263a31c5dcb93f8d5db395c8228d5
BLAKE2b-256 2d7c917f9c4681bb8d34bfbe0b79d36bbcd902651aeab48790df3d30ba0202fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-2.0.15-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 a4560ad8c01e537708d2790dbe7da7d986791de805d89dd0d3697ca59e9e4901
MD5 96b725c8a4c1ee2ca0d71714692065c4
BLAKE2b-256 7c16edef3515dd2030db2795dbfbe392232c7a0f3dc41b98e92b38b42ba497c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-2.0.15-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ab5920877dd632c124b4ed17bc6dd6ef3b9f86cd492b963ffdb1a67b85b0f408
MD5 07d243d0c96384d8c4ad2548a51d321c
BLAKE2b-256 fb162ab7b3b7f55f3c6929e5f629e1a68362981e4e5fed592a2ed1cb4b4914a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-2.0.15-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 83a8f20b430bbc5d8957249f875341a60219a4e971580f2ba694fbfb54a45ebc
MD5 b2746c5736108f2edc25f5adfea9c551
BLAKE2b-256 88e59714def18c3a411809771a3fbcec70bffa764b9675afb00048a620fca604

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-2.0.15-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9a6bcec2df2707aaa9d08b86071970ee32c5026e10bcc3cc5f6f391d85baf7ca
MD5 cf58cd311e9cc50fa54778adb01fec19
BLAKE2b-256 5eac6884dcb7108af66ad53f73ef4dad096e768c9203a6e6ce5e6b0c4a46e238

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-2.0.15-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8e7f5de756a615a38b96cd86fa3cd65f901ce54ce147a3179c45907fa11b4c4e
MD5 44d25f8d427d87fc03ec4b3530b2899b
BLAKE2b-256 a6b7855db919ae526d2628f3f2e6c281c4cdff7a9a8af51bb84659a9f07b1861

See more details on using hashes here.

File details

Details for the file pywinpty-2.0.15-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-2.0.15-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d261cd88fcd358cfb48a7ca0700db3e1c088c9c10403c9ebc0d8a8b57aa6a117
MD5 6ee8d5a79fa3d1799705e86fd7b1fa62
BLAKE2b-256 479690fa02f19b1eff7469ad7bf0ef8efca248025de9f1d0a0b25682d2aacf68

See more details on using hashes here.

Supported by

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