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 OpenCollective Backers Join the chat at https://gitter.im/spyder-ide/public
PyPI status Windows tests

Copyright © 2017– Spyder Project Contributors

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.

Backers

Support us with a monthly donation and help us continue our activities.

Backers

Sponsors

Become a sponsor to get your logo on our README on Github.

Sponsors

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.1_pre0.tar.gz (22.5 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.1_pre0-cp310-none-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.8Windows x86-64

pywinpty-2.0.1_pre0-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.1_pre0.tar.gz.

File metadata

  • Download URL: pywinpty-2.0.1_pre0.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pywinpty-2.0.1_pre0.tar.gz
Algorithm Hash digest
SHA256 5d295f07ef21d84f556f9c1399a3cd2c7b49a0b5b427a8695b194c564dcdb3f3
MD5 3cc877ec46e513d2256cc8d9b3db64df
BLAKE2b-256 ef8c8e5fae9963f52f165407c21f313825f551b96830d1ff4c8eec1e4585aee3

See more details on using hashes here.

File details

Details for the file pywinpty-2.0.1_pre0-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-2.0.1_pre0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 f99cf3110be2efa403cc28013ab73085c5f5294c42407067851eb48ae258ce92
MD5 ac236dfdbe2039012f50dec5865a3f37
BLAKE2b-256 facfccbdf8e1c945cab440656e4e4f68dc343589b2cf58c453e7a9612c455019

See more details on using hashes here.

File details

Details for the file pywinpty-2.0.1_pre0-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-2.0.1_pre0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 30b2c83f7fdb23e8b494dfff12875508dde35079c006dcf7a962f138549ca5d0
MD5 e298718398fdc05b918cbf57a971e37c
BLAKE2b-256 132239d03b1881b6f70360f6748002476b9d3b194a8bb4e409a6d26bb0da642f

See more details on using hashes here.

File details

Details for the file pywinpty-2.0.1_pre0-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-2.0.1_pre0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 4905fb08dac00867e05592a440b97a893d6ed294aa5560091d2a683ae571b07c
MD5 4ec2534b0fffa5f5303d79f568cbd21e
BLAKE2b-256 cac6e0a8e2d906d9e7365640b879956339c4ed12b0f72589ea128c40b774401b

See more details on using hashes here.

File details

Details for the file pywinpty-2.0.1_pre0-cp37-none-win_amd64.whl.

File metadata

File hashes

Hashes for pywinpty-2.0.1_pre0-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 d68d3e784a3974199d3b9a461c63e3b44c676c83da6795824abc671569a8f8ac
MD5 5c3671c1a09427249a8996e9f344154e
BLAKE2b-256 7f536f4c811303896e4ad5b5b2b4a11615e96025a62f02387eb9e540c4ab0614

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