Skip to main content

Asyncio-based Telnet library

Project description

Python Telnet Utility: asyncio-powered

The asyncio-telnet library designed for convenient interaction with Telnet devices in both synchronous and asynchronous modes, making the process straightforward and flexible in various usage scenarios.

Documentation License: Apache License 2.0 PyPi Version PyPi downloads

  • Support for Asynchrony and Synchrony: Harness the power of asyncio for efficient and non-blocking communication with Telnet servers. With this library, you have the option to choose between asynchronous and synchronous modes, depending on the requirements of your project.
  • Ease of Use: The library provides a user-friendly interface for both synchronous and asynchronous cases, making it adaptable to different project needs.
  • Telnet Protocol Handling: Transparently handles the intricacies of the Telnet protocol, allowing you to focus on the logic of your application.
  • Flexible Integration: Easily integrate Telnet functionality into your Python applications with a simple API.

Installation

You can install the library using pip. Make sure you have Python 3.6 or later installed.

pip install asyncio-telnet

Usage

Example: Asynchronous Telnet Connection with Default Timeout

import asyncio
from asyncio_telnet import Telnet

async def main():
    tn = Telnet()
    await tn.open('example.com')
    await tn.write(b'Vladimir\r\n')
    response = await tn.read_until_eof()
    await tn.close()
    return response

if __name__ == '__main__':
    result = asyncio.run(main())
    print(result)


# Example of successful execution:
# b'\n***************** User Access Login ********************\r\n\r\nUser:'

Example: Synchronous Telnet Connection

from asyncio_telnet import Telnet

def main():
    tn = Telnet(sync_mode=True)
    tn.open('example.com')
    response = tn.read_until_eof()
    tn.close()
    return response

if __name__ == '__main__':
    result = main()
    print(result)


# Example of successful execution:
# b'\n***************** User Access Login ********************\r\n\r\nUser:'

Example: Asynchronous Telnet Connection with Custom Timeout.

By default, the timeout is set to 30 seconds.

import asyncio
from asyncio_telnet import Telnet

async def main():
    tn = Telnet(timeout=5)
    try:
        await tn.open('example.com')
        response = await tn.read_until_eof()
        await tn.close()
        return response
    except ValueError as e:
        print(f"Example of a timeout occurrence: {e}")

if __name__ == '__main__':
    asyncio.run(main())


# Example response:
# Example of a timeout occurrence: Timeout connecting to example.com:23

Example: Asynchronous Telnet Connection with Write Operation

import asyncio
from asyncio_telnet import Telnet

async def main():
    tn = Telnet()
    await tn.open('example.com')
    await tn.write(b'Vladimir\r\n')
    response = await tn.read_until_eof()
    await tn.close()
    return response

if __name__ == '__main__':
    result = asyncio.run(main())
    print(result)


# Example of successful execution:
# b'\n***************** User Access Login ********************\r\n\r\nUser:Vladimir\r\nPassword:'

Feel free to check the documentation and examples for more detailed information.

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

asyncio-telnet-0.1.20.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

asyncio_telnet-0.1.20-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file asyncio-telnet-0.1.20.tar.gz.

File metadata

  • Download URL: asyncio-telnet-0.1.20.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for asyncio-telnet-0.1.20.tar.gz
Algorithm Hash digest
SHA256 16b16811b20ee23bec243ce0166e7a988dbaff7b98bbcca6721a02b25530bb8b
MD5 80c5adcea9e8aa6131824d3287fbc0ee
BLAKE2b-256 33e6d1e34c9bdb2486b18432883f3ba31c4385199a1215198aa5a9d721bd9554

See more details on using hashes here.

File details

Details for the file asyncio_telnet-0.1.20-py3-none-any.whl.

File metadata

File hashes

Hashes for asyncio_telnet-0.1.20-py3-none-any.whl
Algorithm Hash digest
SHA256 3d2b3c076f80fd5088a6a3d06807fb3c77744845a00c53c5b132f42ae3c8cc93
MD5 88e8508216713c0525ab015b8f55e9fe
BLAKE2b-256 8b077ccb36fc523475dde184732b461c3542dd6307990ef54b085ab5700d3dd7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page