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 Distribution

pywinpty-3.0.2.tar.gz (30.7 kB view details)

Uploaded Source

Built Distributions

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

pywinpty-3.0.2-cp314-cp314t-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.14tWindows x86-64

pywinpty-3.0.2-cp314-cp314-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.14Windows x86-64

pywinpty-3.0.2-cp313-cp313t-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.13tWindows x86-64

pywinpty-3.0.2-cp313-cp313-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.13Windows x86-64

pywinpty-3.0.2-cp312-cp312-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.12Windows x86-64

pywinpty-3.0.2-cp311-cp311-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.11Windows x86-64

pywinpty-3.0.2-cp310-cp310-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.10Windows x86-64

pywinpty-3.0.2-cp39-cp39-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

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

File metadata

  • Download URL: pywinpty-3.0.2.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for pywinpty-3.0.2.tar.gz
Algorithm Hash digest
SHA256 1505cc4cb248af42cb6285a65c9c2086ee9e7e574078ee60933d5d7fa86fb004
MD5 b28c6ce167abb6afcfbe2e1200733f0d
BLAKE2b-256 f3bba7cc2967c5c4eceb6cc49cfe39447d4bfc56e6c865e7c2249b6eb978935f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-3.0.2-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 34b55ae9a1b671fe3eae071d86618110538e8eaad18fcb1531c0830b91a82767
MD5 c2066c8720c3f619c585a02b9e9243a6
BLAKE2b-256 de24c6907c5bb06043df98ad6a0a0ff5db2e0affcecbc3b15c42404393a3f72a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-3.0.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 28297cecc37bee9f24d8889e47231972d6e9e84f7b668909de54f36ca785029a
MD5 bce6c26d3c15b3719774b667058cdb84
BLAKE2b-256 ca15f12c6055e2d7a617d4d5820e8ac4ceaff849da4cb124640ef5116a230771

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-3.0.2-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 663383ecfab7fc382cc97ea5c4f7f0bb32c2f889259855df6ea34e5df42d305b
MD5 b51e91ff186338c49fc295f2fc12cc2d
BLAKE2b-256 cb44cbae12ecf6f4fa4129c36871fd09c6bef4f98d5f625ecefb5e2449765508

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-3.0.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 18f78b81e4cfee6aabe7ea8688441d30247b73e52cd9657138015c5f4ee13a51
MD5 db08f50011b29a235d33897b4115e735
BLAKE2b-256 fc19b757fe28008236a4a713e813283721b8a40aa60cd7d3f83549f2e25a3155

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-3.0.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 99fdd9b455f0ad6419aba6731a7a0d2f88ced83c3c94a80ff9533d95fa8d8a9e
MD5 4ef85d53fdf2285aed50f6792aa954ad
BLAKE2b-256 024e1098484e042c9485f56f16eb2b69b43b874bd526044ee401512234cf9e04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-3.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 327790d70e4c841ebd9d0f295a780177149aeb405bca44c7115a3de5c2054b23
MD5 83ddfe8545e47c338b29a03ffc9428cf
BLAKE2b-256 a6a1409c1651c9f874d598c10f51ff586c416625601df4bca315d08baec4c3e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pywinpty-3.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 65db57fd3387d71e8372b6a54269cbcd0f6dfa6d4616a29e0af749ec19f5c558
MD5 b14de81b5b971b170248765d00eeab3c
BLAKE2b-256 3ef5b17ae550841949c217ad557ee445b4a14e9c0b506ae51ee087eff53428a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pywinpty-3.0.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.4

File hashes

Hashes for pywinpty-3.0.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3962daf801bc38dd4de872108c424b5338c9a46c6efca5761854cd66370a9022
MD5 de8fc94d51940a092b780435423e9991
BLAKE2b-256 d3ea5cc069afc60f6dd5bc99b3e51fb8b219f10bcf5674882fc5d6dd2186d3aa

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