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
This is a simple python code to get the list of banned IP addresses from Fail2ban

Fail2ban Scripts Usage banned_list.py This script tries to get the banned list of IP addresses by Fail2ban for the service freeswitch. You can modify

Yehor Smoliakov 9 Dec 28, 2022
This is a Client-Server-System which can share the screen from the server to client and in the other direction.

Screenshare-Streaming-Python This is a Client-Server-System which can share the screen from the server to client and in the other direction. You have

VFX / Videoeffects Creator 1 Nov 19, 2021
Socialhome is best described as a federated personal profile with social networking functionality

Description Socialhome is best described as a federated personal profile with social networking functionality. Users can create rich content using Mar

Jason Robinson 332 Dec 30, 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
With Py-Autocrack you can crack WPA2 networks in no time.

With Py-Autocrack you can crack WPA2 networks in no time. All based on Aircrack-ng and Crunch.

Paul - FloatDesign 1 Dec 10, 2021
Simulate Attacks With Mininet And Hping3

Miniattack Simulate Attacks With Mininet And Hping3 It measures network load with bwm-ng when the net is under attack and plots the result. This demo

Geraked 3 Oct 03, 2022
This script will make it easier to connect to any wireguard vpn config

wireguard-linux-python-script-vpn This script will make it easier to connect to any wireguard vpn config also u will need your wireguard vpn from your

Jimo 1 Sep 21, 2022
Query protocol and response

whois Query protocol and response _MᵃˢᵗᵉʳBᵘʳⁿᵗ_ _ ( ) _ ( )( ) _ | | ( ) | || |__ _ (_) ___ | | | | | || _ `\ /'_`\ | |/',__) |

MasterBurnt 4 Sep 05, 2021
This is the code repository for Mastering Python for Networking and Security – Second Edition

Mastering Python for Networking and Security – Second Edition This is the code repository for Mastering Python for Networking and Security – Second Ed

Frank Gottinger 1 Feb 09, 2022
Converts from PC formatted MAC addresses (hardware addresses) to Cisco format or vice-versa

MAC-Converter Converts from PC formatted MAC addresses (hardware addresses) to Cisco format or vice-versa Stores the results to a file in the same dir

Stew Alexander 0 Dec 24, 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
A TrueCharts automatic and bulk update utility

trueupdate A TrueCharts automatic and bulk update utility How to install run pip install trueupdate Please be aware you will need to reinstall after e

TrueCharts 125 Jan 04, 2023
A Python module that allows you to create and use simple sockets.

EasySockets A Python module that allows you to create and use simple sockets. Installation The easysockets module can be installed using pip. pip inst

Matthias Wijnsma 2 Jan 16, 2022
GitHub action for sspanel automatically checks in to get free traffic quota

SSPanel_Checkin This is a dish chicken script for automatic check-in of sspanel for GitHub action, It is only applicable when there is no verification

FeedCatWithFish 7 Apr 28, 2022
The best way to send tokens into a specific server, which can be used for discord bots, and some tools..

XTRA420 The simplified version of sending tokens into a server, the basic and fastest way.. When using this, you have the option to use proxies (http)

07v 1 Nov 30, 2021
VRF-StarkNet - Contracts for verifiable randomness on StarkNet

VRF-StarkNet Contracts for verifiable randomness on StarkNet Motivation Deployed

Non 32 Oct 30, 2022
It's an extra broadcast driver for masonite. It adds support for socketio.

It's an extra broadcast driver for masonite. It adds support for socketio.

Yubaraj Shrestha 6 Feb 23, 2022
PySocks lets you send traffic through SOCKS proxy servers.

PySocks lets you send traffic through SOCKS proxy servers. It is a modern fork of SocksiPy with bug fixes and extra features. Acts as a drop-i

1.1k Dec 07, 2022
This is a simple python script to collect sub-domains from hackertarget API

Domain-Scraper 🌐 This is a simple python script to collect sub-domains from hackertarget API Note : This is tool is limited to 20 Queries / day with

CHINO TECH TOOLS 4 Sep 09, 2021
Implementing Cisco Support APIs into NetBox

NetBox Cisco Support API Plugin NetBox plugin using Cisco Support APIs to gather EoX and Contract coverage information for Cisco devices. Compatibilit

Timo Reimann 23 Dec 21, 2022