|
1 | | ---8<-- "README.md" |
| 1 | +# Frequenz Channels for Python |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +Frequenz Channels is a *channels* implementation for Python. |
| 6 | + |
| 7 | +According to [Wikipedia](https://en.wikipedia.org/wiki/Channel_(programming)): |
| 8 | + |
| 9 | +> A channel is a model for interprocess communication and synchronization via |
| 10 | +> message passing. A message may be sent over a channel, and another process or |
| 11 | +> thread is able to receive messages sent over a channel it has a reference to, |
| 12 | +> as a stream. Different implementations of channels may be buffered or not, |
| 13 | +> and either synchronous or asynchronous. |
| 14 | +
|
| 15 | +Frequenz Channels are mostly designed after [Go |
| 16 | +channels](https://tour.golang.org/concurrency/2) but it also borrows ideas from |
| 17 | +[Rust channels](https://doc.rust-lang.org/book/ch16-02-message-passing.html). |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +First, you need to make sure you have Python installed (at least version 3.11): |
| 22 | + |
| 23 | +```console |
| 24 | +$ python3 --version |
| 25 | +Python 3.11.4 |
| 26 | +``` |
| 27 | + |
| 28 | +!!! note |
| 29 | + |
| 30 | + These instructions assume you are using a [POSIX compatible |
| 31 | + `sh`](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html) |
| 32 | + shell. |
| 33 | + |
| 34 | +If that command doesn't print a version newer than 3.11.0, you'll need to |
| 35 | +[download and install Python](https://www.python.org/downloads/) first. |
| 36 | + |
| 37 | +To install Frequenz Channels, you probably want to create a new virtual |
| 38 | +environment first: |
| 39 | + |
| 40 | +```sh |
| 41 | +mkdir my-channels-project |
| 42 | +cd my-channels-project |
| 43 | +python3 -m venv .venv |
| 44 | +. .venv/bin/activate |
| 45 | +``` |
| 46 | + |
| 47 | +!!! tip |
| 48 | + |
| 49 | + Using [`direnv`](https://direnv.net/) can greatly simplify this process as |
| 50 | + it automates the creation, activation, and deactivation of the virtual |
| 51 | + environment. The first time you enable `direnv`, the virtual environment |
| 52 | + will be created, and each time you enter or leave a subdirectory, it will be |
| 53 | + activated and deactivated, respectively. |
| 54 | + |
| 55 | + ```sh |
| 56 | + sudo apt install direnv # if you use Debian/Ubuntu |
| 57 | + mkdir my-channels-project |
| 58 | + cd my-channels-project |
| 59 | + echo "layout python python3" > .envrc |
| 60 | + direnv allow |
| 61 | + ``` |
| 62 | + |
| 63 | + This will create the virtual environment and activate it automatically for you. |
| 64 | + |
| 65 | +Now you can install Frequenz Channels by using `pip` (if you don't have `pip` installed |
| 66 | +you can follow [the official instructions](https://pip.pypa.io/en/stable/installation/)): |
| 67 | + |
| 68 | +```sh |
| 69 | +python3 -m pip install frequenz-channels |
| 70 | +``` |
| 71 | + |
| 72 | +To verify that the installation worked, you can invoke the Python interpreter and |
| 73 | +import the `frequenz.channels` module: |
| 74 | + |
| 75 | +```console |
| 76 | +$ python3 |
| 77 | +Python 3.11.4 (main, Jun 7 2023, 10:13:09) [GCC 12.2.0] on linux |
| 78 | +Type "help", "copyright", "credits" or "license" for more information. |
| 79 | +>>> import frequenz.channels |
| 80 | +>>> |
| 81 | +``` |
0 commit comments