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 and MSVC 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. Additionally, you will require a working installation of Microsoft Visual Studio C/C++ compiler.

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.
  • CXX: Call C++ libraries from Rust.
  • Maturin: Build system to build and publish Rust-based Python packages.
  • Windows: Rust for Windows.

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

Uploaded Source

Built Distributions

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

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.7Windows x86-64

pywinpty-1.1.1-cp36-none-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.6Windows x86-64

File details

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

File metadata

  • Download URL: pywinpty-1.1.1.tar.gz
  • Upload date:
  • Size: 48.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pywinpty-1.1.1.tar.gz
Algorithm Hash digest
SHA256 4a3ffa2444daf15c5f65a76b5b2864447cc915564e41e2876816b9e4fe849070
MD5 ab3b3bcb099d7ba27bb0c4cfe477e4cc
BLAKE2b-256 40ed694e4a642e3b8afac6d6e70538a3684e1049f2020a33002b58e1ac5cd4b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pywinpty-1.1.1-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.10.4

File hashes

Hashes for pywinpty-1.1.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 50bce6f7d9857ffe9694847af7e8bf989b198d0ebc2bf30e26d54c4622cb5c50
MD5 009b19e837a21f4878b085f35a4cdd6f
BLAKE2b-256 b0e40c3eb06bf969a28f99e48b93aa4bcb44df120c548518d5b365116e2b85c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pywinpty-1.1.1-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.10.4

File hashes

Hashes for pywinpty-1.1.1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 12c89765b3102d2eea3d39d191d1b0baea68fb5e3bd094c67b2575b3c9ebfa12
MD5 4d65bb167e323d8b2709d1d89900a475
BLAKE2b-256 83f3910a5442914b70b8348060f1be0c372d13fd91cf01db0c1a8f140d217b34

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pywinpty-1.1.1-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.10.4

File hashes

Hashes for pywinpty-1.1.1-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 0fe3f538860c6b06e6fbe63da0ee5dab5194746b0df1be7ed65b4fce5da21d21
MD5 d95677293458b0b67c234de84f853ed2
BLAKE2b-256 c45a8330aadebc0459df378dcca5111337a493106166e4e850c090b44f76a575

See more details on using hashes here.

File details

Details for the file pywinpty-1.1.1-cp36-none-win_amd64.whl.

File metadata

  • Download URL: pywinpty-1.1.1-cp36-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.6, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.10.4

File hashes

Hashes for pywinpty-1.1.1-cp36-none-win_amd64.whl
Algorithm Hash digest
SHA256 fa2a0af28eaaacc59227c6edbc0f1525704d68b2dfa3e5b47ae21c5aa25d6d78
MD5 20805ef59c8c05b31dbe537e414efb32
BLAKE2b-256 3145c8d5f05089931725f8157111e1b3430071e3537402bef9b976563da63a70

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