Newio


License
MIT
Install
pip install newio==0.6.2

Documentation

Newio: New Async API for Python!

travis-ci codecov

Overview

import os
from newio import socket, spawn, run

async def echo_handler(client, address):
    async with client:
        while True:
            data = await client.recv(1024)
            if not data:
                break
            await client.sendall(data)

async def start_echo_server(host, port):
    print(f'Echo server pid={os.getpid()}, listening at tcp://{host}:{port}')
    server = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
    server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server.bind((host, port))
    server.listen()
    while True:
        client, address = await server.accept()
        await spawn(echo_handler(client, address))

if __name__ == '__main__':
    run(start_echo_server('127.0.0.1', 25000))

Install

Note: Only support python 3.6+

pip install 'newio>=0.6.1'