A generic asyncio Python package to use telnet.
Project description
aiotelnet: Async Telnet Client
aiotelnet is a lightweight, asynchronous Telnet client for Python, designed for easy integration into modern async applications.
Notice: AI has been used to generate parts of this project. It has been checked against Python documentation for correctness.
This project was born due to the lack of standard async telnet library, while it has been built primarily for telnet usage, it could also be used for any kind of low-level server/client network communication.
Features
- Asynchronous: Built on
asynciofor non-blocking network I/O. - Automatic Reconnection: Can automatically reconnect to the server if the connection is lost.
- Easy to Use: Simple and intuitive API for connecting, sending commands, and handling messages.
- Customizable: Allows customization of encoding, line breaks, and reconnection behavior.
Installation
pip install aiotelnet
Usage
Here's a basic example of how to use TelnetClient to connect to a Telnet server, send a command, and receive messages:
import asyncio
from aiotelnet.client import TelnetClient
# Define a message handler
async def message_handler(message: bytes):
"""Handle incoming messages from the Telnet server."""
print(f"Received: {message.decode('utf-8').strip()}")
async def main():
"""Connect to the Telnet server and send a command."""
# Create a Telnet client
client = TelnetClient(
host="telehack.com",
port=23,
message_handler=message_handler,
)
try:
# Establish the connection
await client.connect()
# Send a command
await client.send_command("hello")
# Keep the connection open for a while
await asyncio.sleep(10)
except ConnectionError as e:
print(f"Connection failed: {e}")
finally:
# Close the connection
if client.is_connected():
await client.close()
if __name__ == "__main__":
asyncio.run(main())
API Reference
TelnetClient(host, port, message_handler, ...)
host: The Telnet server host.port: The Telnet server port (default: 23).message_handler: An optional callable (sync or async) to handle incoming messages.break_line: The byte sequence that separates messages (default:b'\\n').encoding: The encoding to use for commands (default:'utf-8').auto_reconnect: Whether to automatically reconnect if the connection is lost (default:True).reconnect_interval: The interval in seconds between reconnection attempts (default:10).
async connect()
Establishes a connection to the Telnet server.
is_connected() -> bool
Returns True if the client is connected, False otherwise.
async send_command(command: str)
Sends a command to the Telnet server.
async close()
Closes the connection to the Telnet server.
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the Apache 2.0 License.
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 Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiotelnet-1.1.0.tar.gz.
File metadata
- Download URL: aiotelnet-1.1.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d940ac285ad48eac0064f70acfa7550e66a8a2d2ebc9322f0c5565b3136dfcfd
|
|
| MD5 |
8a98111ec9ffb81fed2f252d720ae0ac
|
|
| BLAKE2b-256 |
8ae55d7e6d598ed270f991d60ae69ab749ddaaa370194b0ce07b8c979fcdd2e7
|
Provenance
The following attestation bundles were made for aiotelnet-1.1.0.tar.gz:
Publisher:
release.yml on pantherale0/aiotelnet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiotelnet-1.1.0.tar.gz -
Subject digest:
d940ac285ad48eac0064f70acfa7550e66a8a2d2ebc9322f0c5565b3136dfcfd - Sigstore transparency entry: 773700708
- Sigstore integration time:
-
Permalink:
pantherale0/aiotelnet@95db89b42d9348e9747f097381cced1d4ead9099 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/pantherale0
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@95db89b42d9348e9747f097381cced1d4ead9099 -
Trigger Event:
release
-
Statement type:
File details
Details for the file aiotelnet-1.1.0-py3-none-any.whl.
File metadata
- Download URL: aiotelnet-1.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
def37f5b138a648b352e1aca99014423f09ac59c630be23facbe85e1a26b4825
|
|
| MD5 |
fb617983de2390c7c181438bb1208b17
|
|
| BLAKE2b-256 |
b25eb7e6f8cb81d56ebdf071cc07c806e8326b07a53dbf921985ea3c6ae7d290
|
Provenance
The following attestation bundles were made for aiotelnet-1.1.0-py3-none-any.whl:
Publisher:
release.yml on pantherale0/aiotelnet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiotelnet-1.1.0-py3-none-any.whl -
Subject digest:
def37f5b138a648b352e1aca99014423f09ac59c630be23facbe85e1a26b4825 - Sigstore transparency entry: 773700713
- Sigstore integration time:
-
Permalink:
pantherale0/aiotelnet@95db89b42d9348e9747f097381cced1d4ead9099 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/pantherale0
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@95db89b42d9348e9747f097381cced1d4ead9099 -
Trigger Event:
release
-
Statement type: