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.3.tar.gz (48.6 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.3-cp39-none-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.9Windows x86-64

pywinpty-1.1.3-cp38-none-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.8Windows x86-64

pywinpty-1.1.3-cp37-none-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.7Windows x86-64

pywinpty-1.1.3-cp36-none-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.6Windows x86-64

File details

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

File metadata

  • Download URL: pywinpty-1.1.3.tar.gz
  • Upload date:
  • Size: 48.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for pywinpty-1.1.3.tar.gz
Algorithm Hash digest
SHA256 3a1d57b338390333812a5eed31c93c7d8ba82b131078063703e731946d90c9f2
MD5 d65b2da6f214f66c22fbcb727449535d
BLAKE2b-256 07e0a26c9ac4e16aefc0b66a203f0140373245b6298443fa35978a3c680c8726

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pywinpty-1.1.3-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 b767276224f86b7560eb9173ba7956758cafcdfab97bb33837d42d2a0f1dbf67
MD5 9bee6e6fe8aefe48000141f22f2b4ecb
BLAKE2b-256 a494be84faeb5d3443b9790a68b59f3f5cdd62f4c1b3474d972e2db0ea739e4a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pywinpty-1.1.3-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 f5e25197397f1fef0362caf3eb89f25441827a1e48bf15827c27021592fd2160
MD5 8d5eb4827a53e8f701cf17c5d5c8457d
BLAKE2b-256 a352ddfbef80c74deaaac6984633f0f3df09cd135a61bafc4d5e794a7c9bb8d9

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pywinpty-1.1.3-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 54557887e712ea3215ab0d9f089ed55a6cc8d826cd5d1e340d75300654c9663f
MD5 29c4016d5338d2a189ea934c8bb2e2ca
BLAKE2b-256 b851a9022f93de5ac31570a80ca94402011edf2d4ebc7f85cc667a8d1f6364f8

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pywinpty-1.1.3-cp36-none-win_amd64.whl
Algorithm Hash digest
SHA256 81dc6f16d917b756e06fc58943e9750d59dbefc0ffd2086871d3fa5f33824446
MD5 72c90593b1e8a623b0b35afd276659ce
BLAKE2b-256 ce2c65b394365d42ede8d6f27fff351ff673c42d31b7c4d9cd3b437103da5005

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