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
Simple client for the Sirah Matisse Commander TCP server.

Simple client for the Sirah Matisse Commander TCP server.

Nelson Darkwah Oppong 1 Nov 02, 2021
IPV4 network calculation project in Python

Curso de Python 3 do Básico ao Avançado Desafio: Calculando redes IPV4 Criar um programa que obtem um numero de IP com o prefixo da mascara de rede. O

Diego Guedes 3 Jan 21, 2022
Find information about an IP address, such as its location, ISP, hostname, region, country, and city.

Find information about an IP address, such as its location, ISP, hostname, region, country, and city. An IP address can be traced, tracked, and located.

Sachit Yadav 2 Jul 09, 2022
Blockchain-Enabled IoT Sensor Framework that uses Augmented Reality and Artificial Intelligence.

Arduino + Raspberry Pi + Unity3D + Cloud + Hyperledger Our Mission: Keep it simple, leave no one behind. Blockchain-Enabled Smart Sensor Framework usi

DappAR 23 Dec 05, 2021
Asynchronous For Python(asyncio)

asyncio is a library to write concurrent code using the async/await syntax.asyncio is used as a foundation for multiple Python asynchronous frameworks that provide high-performance network and web-se

Janak raikhola 0 Feb 05, 2022
euserv auto-renew script - A Python script which can help you renew your free EUserv IPv6 VPS.

eu_ex eu_ex means EUserv_extend. A Python script which can help you renew your free EUserv IPv6 VPS. This Script can check the VPS amount in your acco

A beam of light 92 Jan 25, 2022
Wallc - Calculate the layout on the wall to hang up pictures

wallc Calculate the layout on the wall to hang up pictures. Installation pip install git+https://github.com/trbznk/wallc.git Getting Started Currently

Alex Trbznk 68 Sep 09, 2022
QUIC and HTTP/3 implementation in Python

aioquic What is aioquic? aioquic is a library for the QUIC network protocol in Python. It features a minimal TLS 1.3 implementation, a QUIC stack and

1.2k Dec 29, 2022
BaseSpec is a system that performs a comparative analysis of baseband implementation and the specifications of cellular networks.

BaseSpec is a system that performs a comparative analysis of baseband implementation and the specifications of cellular networks. The key intuition of BaseSpec is that a message decoder in baseband s

SysSec Lab 35 Dec 06, 2022
pureSxS - A tool to export Component Based Servicing packages from a full Windows installation

pureSxS A tool to export Component Based Servicing packages from a full Windows installation. Usage pureSxS.py source_mum destination pureSxS wor

Gamers Against Weed 3 Oct 03, 2022
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
Distribute a portion of your yield to other addresses 💙

YSHARE Distribute a portion of your yield to other addresses. How does it work Desposit your yToken or tokens into this contract Set the benificiaries

11 Nov 24, 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
Easily share folders between VMs.

This package aims to solve the problem of inter-VM file sharing (rather than manual copying) by allowing a VM to mount folders from any other VM's file system (or mounted network shares).

Rudd-O 12 Oct 17, 2022
Event-driven networking engine written in Python.

Twisted For information on changes in this release, see the NEWS file. What is this? Twisted is an event-based framework for internet applications, su

Twisted Matrix Labs 4.9k Jan 08, 2023
Build surface water network for MODFLOW's SFR Package

Surface water network Creates surface water network, which can be used to create MODFLOW's SFR. Python packages Python 3.6+ is required. Required geop

Mike Taves 20 Nov 22, 2022
EUserv - A Python script which can help you renew your free EUserv IPv6 VPS

English | 简体中文 This project comes from https://github.com/a-beam-of-light/eu_ex

阿两 0 Jan 06, 2022
MS Iot Device Can Platform

Kavo MS IoT Platform Version: 2.0 Author: Luke Garceau Requirements Read CAN messages in real-time Convert the given variables to engineering useful v

Luke Garceau 1 Oct 13, 2021
Easy-to-use sync library for handy proxy parse

Proxy Parser About Synchronous library, for convenient and fast parsing of proxies from different sources. Uses Scrapy as a parser. At the moment the

Michael Mironov 2 Nov 22, 2022
wg-exporter is a simple yet effective Prometheus exporter for Wireguard

wg-exporter wg-exporter is a simple yet effective Prometheus exporter for Wireguard. What are the collected metrics ? General: wg_connected_peers: num

men1n2 3 May 20, 2022