newio for python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benchmark
src/newio
tests
.bumpversion.cfg
.coveragerc
.gitignore
.pre-commit-config.yaml
.travis.yml
MANIFEST.in
README.md
bootstrap.sh
invoke.yaml
pytest.ini
setup.py
tasks.py

README.md

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'