Skip to main content

async-compatible libreadline wrapper

Project description

aioreadline

Python has a builtin readline module. However, the builtin module is difficult to use in async Python code. This module provides an interface around the async-compatible functions of libreadline using a ctypes wrapper.

Example

import asyncio, atexit

async def _main():
	while True:
		line = await aiorl.getLine()
		
		if line is None or line == b"quit":
			aiorl.stop()
			loop.stop()
			break
		elif len(line) > 0:
			aiorl.add_history(line)
			print(line)

loop = asyncio.get_event_loop()
loop.create_task(_main())

aiorl = AIOReadline(prompt="> ", loop=loop, history_file=".aioreadline_history")

atexit.register(lambda: aiorl.stop())

try:
	loop.run_forever()
except KeyboardInterrupt:
	loop.stop()

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

aioreadline-2024.1.25.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

aioreadline-2024.1.25-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

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