Skip to content

alephzero/py

Repository files navigation

Aleph Zero: Python

CI

See https://github.com/alephzero/alephzero for details

See https://github.com/alephzero/playground for examples.

Install Instructions

pip install alephzero

Example Publish

import a0
p = a0.Publisher("topic")
p.pub("msg")

Example Subscribe

import a0
s = a0.Subscriber("topic", lambda pkt: print(pkt.payload))

CLI

Examples

Publish a message:

a0 pub topic msg

Subscribe to a topic:

a0 sub topic

Get more info:

a0 --help

Get more info for a command:

a0 cfg --help

Auto-complete

Add the following snippet to your ~/.bashrc:

eval "$(_A0_COMPLETE=bash_source a0)"
$ a0 <TAB><TAB>
cfg     log     prpc    pub     pubsub  rpc     sub
$ a0 cfg <TAB><TAB>
clear  echo   ls     set

Custom Commands

The a0 script searches for command plugins in three places:

  1. pip installed entry-points with key a0.cli.cmds
  2. ~/.config/alephzero/cli/cmds/
  3. env[A0_CLI_CMDS_PATH]

With (2) and (3), any python file in the path is expected to be a command file. The name of the file is the name of the command, for example foo.py will be triggered by the command line a0 foo. The file should export a symbol called cli which is either a click.command or click.group.

env[A0_CLI_CMDS_PATH] supports a colon separated list of paths.