Skip to content
Python Keybase Bot Library
Python Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples add custom client example Sep 7, 2019
pykeybasebot print JSON error output to aid in debugging (#13) Sep 8, 2019
tests make the tests pass Sep 5, 2019
.flake8 Update line length to 88 Aug 28, 2019
.gitignore Add mypy Aug 28, 2019
.pre-commit-config.yaml attach and download Sep 7, 2019
.python-version Add python version Aug 26, 2019
LICENSE first commit May 30, 2019
Makefile add the types Sep 4, 2019 readme Sep 6, 2019
poetry.lock Add typing_extensions as a dependency (#16) Sep 12, 2019
pyproject.toml Add typing_extensions as a dependency (#16) Sep 12, 2019


This is the officially support Keybase Python library. It is an unopinionated, simple wrapper around the Keybase CLI API for creating an interactive bot or general scripting. This library does not attempt to do intent parsing or manage state at all. You'll have to build that yourself, but with the examples, this library will hopefully make whatever you want to build much much easier :).

There are also similar libraries for JavaScript and Go.

This library is very far from exhaustively covering the complete Keybase API, but it is our hope that it will be easy to add to (see for the pattern). It currently does reading from channels and writing messages/reactions pretty well. That's enough for the vast majority of basic functionality. Future work can add teams behavior, more wallet functionality (e.g. sending money), ...


pip install pykeybasebot

Python 3.7 or greater, please. And it's all async, so you'll need to call into it with that in mind.


Generally speaking, here's what you need to do:

  1. Create a handler function that takes event objects and does something with them. This function will get called with your bot instance (described below) and the KbEvent instance.
  2. Create a bot. You must initialize this with the handler function to call with each event. You may optionally pass in: (1) the username and/or paperkey for the bot's identity (it'll default to the currently logged-in user otherwise), (1) the event loop that you want new tasks to be sent to (this is necessary if you want to lock on async behavior -- see the examples), (2) the location of the running keybase app (defaults to keybase which is fine if it's in your PATH), your user's home directory, or pid_file. These three are more useful for complicated local development with multiple accounts and less useful if you're running in a docker container or as the only user on your system.
  3. If you are not already running on a logged-in device, you need to do that. We recommend doing this with the oneshot command. It's in the examples.
  4. start the bot inside the asyncio event loop. This bot command wraps keybase chat api-listen, (and it takes basically the same exact options) and fires off events to your handler function.


Definitely definitely check out the examples. We're really counting on them to make it clear how to use this library.


PRs are extremely welcome. To start:

git clone
cd pykeybasebot

We use Poetry to handle our packaging. Go check out their website for installation instructions. To start Poetry, you'll need the python executable in your path to link to Python 3.7. We recommend using pyenv to handle different versions of Python on your machine. With pyenv installed, it should automatically set python to 3.7 when you cd into this repo.

Once you have the right Python version, you can run:

pip install poetry
poetry install

This will set up a virtualenv for you and install all the dependencies needed into it!

Static code analysis tools

We use a few different static analysis tools to perform linting, type-checking, formatting, etc. The correct versions should be install when you run poetry install, but you'll probably want to configure your editor to work with:

pre-commit hooks

We check all git commits with the above tools with pre-commit hooks. To enable use of these pre-commit hooks:

  • Install the pre-commit utility.
  • Remove any existing pre-commit hooks via rm .git/hooks/pre-commit
  • Configure via pre-commit install

Then proceed as normal.


To run tests, type

poetry run python -m pytest

Tests are admittedly weak. You could change that!


Most of the types the bot uses are generated from definitions defined in the protocol/ directory inside the Keybase client repo. This ensures that the types that the bot uses are consistent across bots and always up to date with the output of the API.

To build the types for the Python bot, you'll need to clone the client repo. This requires Go and your GOPATH to be set up.

go get

and install the necessary dependencies for compiling the protocol files. This requires node.js and Yarn.

cd client/protocol
yarn install

Then you can generate the types by using the provided Makefile in this repo.

cd path/to/keybase-bot

Should you need to remove all the types for some reason, you can run make clean.


Poetry can build and publish packages to PyPI. We've run into some issues with uploading to PyPI and Poetry, though, so for now we're recommending building with Poetry and uploading with Twine.

poetry build
# Upload to Test PyPi. You only need to run the first command once
poetry config repositories.testpypi
poetry publish -r testpypi
# Upload to real PyPi
poetry publish
You can’t perform that action at this time.