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.8.tar.gz (23.4 kB view details)

Uploaded Source

Built Distributions

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

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

pywinpty-2.0.8-cp38-none-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.8Windows x86-64

pywinpty-2.0.8-cp37-none-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.7Windows x86-64

File details

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

File metadata

  • Download URL: pywinpty-2.0.8.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pywinpty-2.0.8.tar.gz
Algorithm Hash digest
SHA256 a89b9021c63ef78b1e7d8e14f0fac4748c88a0c2e4f529c84f37f6e72b914280
MD5 18b19e7becf89e2af023836bb05cbf4f
BLAKE2b-256 9618904410ebeff904b0039bb918e2529e8f72dd34048bf1a719abcffefc0151

See more details on using hashes here.

File details

Details for the file pywinpty-2.0.8-cp310-none-win_amd64.whl.

File metadata

  • Download URL: pywinpty-2.0.8-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.13.3

File hashes

Hashes for pywinpty-2.0.8-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 9cbf89834abc8d4d4c5f295f11e15dd93889a8069db876f2bc10cc64aa4060ac
MD5 880631e109065ac9894b5dd9fd2a66f3
BLAKE2b-256 5d9181c9e6f5ee0dae519a40b5dd631295a25ad51513900372fda8c2014411f0

See more details on using hashes here.

File details

Details for the file pywinpty-2.0.8-cp39-none-win_amd64.whl.

File metadata

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

File hashes

Hashes for pywinpty-2.0.8-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 ea7c1da94eed5ef93e75026c67c60d4dca33ea9a1c212fa89221079a7b463c68
MD5 6f9b67be8f217d9e4dc5ffa007c809c4
BLAKE2b-256 96ffd17893f4fa9ba2a72b01360cb9e08c37719c15ed7e332938b287ba8d4c80

See more details on using hashes here.

File details

Details for the file pywinpty-2.0.8-cp38-none-win_amd64.whl.

File metadata

  • Download URL: pywinpty-2.0.8-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.13.3

File hashes

Hashes for pywinpty-2.0.8-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 23389d56258d6a1fbc4b41257bd65e5bdabaf6fde7f30a13806e557ea9ee6865
MD5 bbec811d1d37f311e261808ae505d204
BLAKE2b-256 fbe727e6357fb3ca70832c9c7ddae3dc3006bc3702372d22c969c0e31268f356

See more details on using hashes here.

File details

Details for the file pywinpty-2.0.8-cp37-none-win_amd64.whl.

File metadata

  • Download URL: pywinpty-2.0.8-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.7, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.13.3

File hashes

Hashes for pywinpty-2.0.8-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 a2f9a95f3b74262ef73f1be5257c295c8caab1f79f081aa3400ca61c724f9bc6
MD5 93da8422d1233cf7715a81958f34100a
BLAKE2b-256 0fe85dd278b7d9dac60d1989d14f381e0c4e2035ce97a74c01fb11adf3718e9e

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