CSP-style concurrency for Python

Overview

aiochan

Build Status Documentation Status codecov PyPI version PyPI version PyPI status GitHub license

logo

Aiochan is a library written to bring the wonderful idiom of CSP-style concurrency to python. The implementation is based on the battle-tested Clojure library core.async, while the API is carefully crafted to feel as pythonic as possible.

Why?

  • Doing concurrency in Python was painful
  • asyncio sometimes feels too low-level
  • I am constantly missing capabilities from golang and core.async
  • It is much easier to port core.async to Python than to port all those wonderful python packages to some other language.

What am I getting?

  • Pythonic API that includes everything you'd need for CSP-style concurrency programming
  • Works seamlessly with existing asyncio-based libraries
  • Fully tested
  • Fully documented
  • Guaranteed to work with Python 3.5.2 or above and PyPy 3.5 or above
  • Depends only on python's core libraries, zero external dependencies
  • Proven, efficient implementation based on Clojure's battle-tested core.async
  • Familiar semantics for users of golang's channels and Clojure's core.async channels
  • Flexible implementation that does not depend on the inner workings of asyncio at all
  • Permissively licensed
  • A beginner-friendly tutorial to get newcomers onboard as quickly as possible

How to install?

pip3 install aiochan

How to use?

Read the beginner-friendly tutorial that starts from the basics. Or if you are already experienced with golang or Clojure's core.async, start with the quick introduction and then dive into the API documentation.

I want to try it first

The quick introduction and the beginner-friendly tutorial can both be run in jupyter notebooks, online in binders if you want (just look for the binder link at the top of each tutorial).

Examples

In addition to the introduction and the tutorial, we have the complete set of examples from Rob Pike's Go concurrency patterns translated into aiochan. Also, here is a solution to the classical dining philosophers problem.

I still don't know how to use it

We are just starting out, but we will try to answer aiochan-related questions on stackoverflow as quickly as possible.

I found a bug

File an issue, or if you think you can solve it, a pull request is even better.

Do you use it in production? For what use cases?

aiochan is definitely not a toy and we do use it in production, mainly in the two following scenarios:

  • Complex data-flow in routing. We integrate aiochan with an asyncio-based web server. This should be easy to understand.
  • Data-preparation piplelines. We prepare and pre-process data to feed into our machine learning algorithms as fast as possible so that our algorithms spend no time waiting for data to come in, but no faster than necessary so that we don't have a memory explosion due to data coming in faster than they can be consumed. For this we make heavy use of parallel_pipe and parallel_pipe_unordered. Currently we are not aware of any other library that can completely satisfy this need of ours.

What's up with the logo?

It is our 'hello world' example:

import aiochan as ac

async def blue_python(c):
    while True:
        # do some hard work
        product = "a product made by the blue python"
        await c.put(product)

async def yellow_python(c):
    while True:
        result = await c.get()
        # use result to do amazing things
        print("A yellow python has received", result)

async def main():
    c = ac.Chan()

    for _ in range(3):
        ac.go(blue_python(c))

    for _ in range(3):
        ac.go(yellow_python(c))

in other words, it is a 3-fan-in on top of a 3-fan-out. If you run it, you will have an endless stream of A yellow python has received a product made by the blue python.

If you have no idea what this is, read the tutorial.

Owner
Ziyang Hu
Attempting to build artificial general intelligence. Has a PhD in theoretical physics from the University of Cambridge.
Ziyang Hu
Quickly fetch your WiFi password and if needed, generate a QR code of your WiFi to allow phones to easily connect

wifi-password Quickly fetch your WiFi password and if needed, generate a QR code of your WiFi to allow phones to easily connect. Works on macOS and Li

Siddharth Dushantha 2.6k Jan 05, 2023
Jogo da forca simples com conexão entre cliente e servidor utilizando TCP.

JogoDaForcaTCP Um jogo da forca simples com conexão entre cliente e servidor utilizando o protocólo TCP. Como jogar: Habilite a porta 20000, inicie o

Kelvin Santos 1 Dec 01, 2021
Tiny Interactive File Transfer Application

TIFTA: Tiny Interactive File Transfer Application This repository holds all the source code, tests and documentation of the TIFTA software. The main g

Jorge Martínez 2 Dec 08, 2021
Utility for converting IP Fabric webhooks into a Teams format.

IP Fabric Webhook Integration for Microsoft Teams Setup IP Fabric Setup Go to Settings Webhooks Add webhook Provide a name URL will be: 'http://Y

Community Fabric 1 Jan 26, 2022
Test - Python project for Collection Server and API Server

QProjectPython Collection Server 와 API Server 를 위한 Python 프로젝트 입니다. [FastAPI참고]

1 Jan 03, 2022
simple subdomain finder

Subdomain-finder Simple SubDomain finder using python which is easy to use just download and run it Wordlist you can use your own wordlist but here i

AsjadOwO 5 Sep 24, 2021
FramIp - it a framework for work at IP and domain

FramIp FramIp - it a framework for work with IP and domain Installation (termux) $ pkg install git && pkg install python && git clone https://github.c

1 Jan 28, 2022
Python code that get the name and ip address of a computer/laptop

IP Address This is a python code that provides the name and the internet protocol address of the computer. You need to install socket pip install sock

CODE 2 Feb 21, 2022
Program can control your server via discord bot

GTPS Controller Program can control your server via discord bot Require Python How To Use Download This Source Extract The Zip File Paste gtps.py to y

Lamp 2 Mar 15, 2022
NanoChat - nano chat server and client

NanoChat This is a work in progress! NanoChat is an application for connecting with your friends using Python that uses ONLY default Python libraries.

Miss Bliss 1 Nov 13, 2021
A vpn that sits in your browser, accessible via a website

VPNInYourBrowser A vpn that sits in your browser, accessible via a website Example setup: https://VPNInBrowser.jaffa42.repl.co Setup Put the code onto

1 Jan 20, 2022
Ultimate transformation library that supports validation, contexts and aiohttp.

Trafaret Ultimate transformation library that supports validation, contexts and aiohttp. Trafaret is rigid and powerful lib to work with foreign data,

Mikhail Krivushin 174 Nov 27, 2022
A simple software which can use to make a server in local network

home-nas it is simple software which can use to make a server in local network, it has a web site on it which can use by multipale system, i use nginx

R ansh joseph 1 Nov 10, 2021
Raspberry Pi Based Serial Console Server, with PushBullet Notification of IP changes, Automatic VPN termination, custom menu, Power Outlet Control, and a lot more

ConsolePi Acts as a serial Console Server, allowing you to remotely connect to ConsolePi via Telnet/SSH/bluetooth to gain Console Access to devices co

120 Jan 05, 2023
Pywbem - A WBEM client and related utilities, written in pure Python.

Pywbem - A WBEM client and related utilities, written in pure Python Overview Pywbem is a WBEM client and WBEM indication listener and provides relate

PyWBEM Projects 39 Dec 22, 2022
This is a small python code that I use with my NAS server connected to Plex

Spotifarr This is a small python code that I use with my NAS server connected to Plex I didn't appreciate how Lidarr works because it downloads a full

Automator 35 Oct 04, 2022
PcapConverter - A project for generating 15min frames out of a .pcap file containing network traffic

CMB Assignment 02 code + notebooks This is a project for containing code for the

Yannik S 2 Jan 24, 2022
TsuserverMoS - A Python-based server for Attorney Online,

tsuserverMoS A Python-based server for Attorney Online, forked from RealKaiser/tsuserverCC Requires Python 3.7+ and PyYAML. Changes/additions from tsu

1 Dec 30, 2021
The module that allows the collection of data sampling, which is transmitted with WebSocket via WIFI or serial port for CSV file.

The module that allows the collection of data sampling, which is transmitted with WebSocket via WIFI or serial port for CSV file.

Nelson Wenner 2 Apr 01, 2022
A Project to resolve hostname and receive IP

hostname-resolver A Project to resolve hostname and receive IP Installation git clone https://github.com/ihapiw/hostname-resolver.git Head into the ho

iHapiW 5 Sep 12, 2022