Pseudo terminal support for Windows from Python.
Project description
PyWinpty: Pseudoterminals for Windows in Python
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pywinpty-2.0.14.tar.gz
.
File metadata
- Download URL: pywinpty-2.0.14.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18bd9529e4a5daf2d9719aa17788ba6013e594ae94c5a0c27e83df3278b0660e |
|
MD5 | 246129dd26269ee192acb88d079dc576 |
|
BLAKE2b-256 | f18290f8750423cba4b9b6c842df227609fb60704482d7abf6dd47e2babc055a |
File details
Details for the file pywinpty-2.0.14-cp313-none-win_amd64.whl
.
File metadata
- Download URL: pywinpty-2.0.14-cp313-none-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 074fb988a56ec79ca90ed03a896d40707131897cefb8f76f926e3834227f2819 |
|
MD5 | 4227262fde7291df269c577cf1c6b6b2 |
|
BLAKE2b-256 | 7d34b77b3c209bf2eaa6455390c8d5449241637f5957f41636a2204065d52bfa |
File details
Details for the file pywinpty-2.0.14-cp312-none-win_amd64.whl
.
File metadata
- Download URL: pywinpty-2.0.14-cp312-none-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55dad362ef3e9408ade68fd173e4f9032b3ce08f68cfe7eacb2c263ea1179737 |
|
MD5 | fffc3d7df42be6335ce5d938309ae2a6 |
|
BLAKE2b-256 | ad79759ae767a3b78d340446efd54dd1fe4f7dafa4fc7be96ed757e44bcdba54 |
File details
Details for the file pywinpty-2.0.14-cp311-none-win_amd64.whl
.
File metadata
- Download URL: pywinpty-2.0.14-cp311-none-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf2a43ac7065b3e0dc8510f8c1f13a75fb8fde805efa3b8cff7599a1ef497bc7 |
|
MD5 | 462ccae765bc89620cf76991f13d6745 |
|
BLAKE2b-256 | bee2af1a99c0432e4e58c9ac8e334ee191790ec9793d33559189b9d2069bdc1d |
File details
Details for the file pywinpty-2.0.14-cp310-none-win_amd64.whl
.
File metadata
- Download URL: pywinpty-2.0.14-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/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b149c2918c7974f575ba79f5a4aad58bd859a52fa9eb1296cc22aa412aa411f |
|
MD5 | 2427fc403d8f980b1a6398324acb6eeb |
|
BLAKE2b-256 | 070956376af256eab8cc5f8982a3b138d387136eca27fa1a8a68660e8ed59e4b |
File details
Details for the file pywinpty-2.0.14-cp39-none-win_amd64.whl
.
File metadata
- Download URL: pywinpty-2.0.14-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/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5725fd56f73c0531ec218663bd8c8ff5acc43c78962fab28564871b5fce053fd |
|
MD5 | 9772fa0dec1a24b271d0f98704d370a9 |
|
BLAKE2b-256 | d8ef85e1b0ef7864fa2c579b1c1efce92c5f6fa238c8e73cf9f53deee08f8605 |