• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python Keybase Bot Library

pykeybasebot

PyPI Build Status

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 chat_client.py 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), ...

Installation

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.

Setup

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.

Examples

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

Contributing

PRs are extremely welcome. To start:

git clone https://github.com/keybase/pykeybasebot
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!

Remember that if you're making changes to pykeybasebot and want to test them locally, you'll need to first uninstall previously installed pykeybasebot, then install your local version:

pip uninstall pykeybasebot
poetry build
pip install ./dist/pykeybasebot-{tags}.whl

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.com 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.

Testing

To run tests, type

make test

Tests are admittedly weak. You could change that!

Types

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 github.com/keybase/client/go/keybase

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
make types

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

Publishing

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 https://test.pypi.org/legacy/
poetry publish -r testpypi
# Upload to real PyPi
poetry publish

More Repositories

1

client

Keybase Go Library, Client, Service, OS X, iOS, Android, Electron
Go
8,579
star
2

kbfs

Keybase Filesystem (KBFS)
Go
1,210
star
3

saltpack

a modern crypto messaging format
Go
987
star
4

keybase-issues

A single repo for managing publicly recognized issues with the keybase client, installer, and website.
902
star
5

go-keychain

Golang keychain package for iOS and macOS
Go
561
star
6

kbpgp

OpenPGP (RFC4880) Implementation in IcedCoffeeScript
JavaScript
530
star
7

triplesec

Triple Security for the browser and Node.js
JavaScript
398
star
8

node-client

CLI for keybase.io written in/for Node.js
CoffeeScript
299
star
9

keybase-bot

exploration with the keybase chat API
TypeScript
264
star
10

bot-sshca

A chat bot that can manage your team's SSH accounts
Go
222
star
11

warpwallet

A brain wallet generator that uses scrypt.
HTML
186
star
12

book-content

Jinja
173
star
13

managed-bots

Keybase managed bots
Go
130
star
14

node-installer

An installer/updater for the node client.
CoffeeScript
117
star
15

go-keybase-chat-bot

Official Go Keybase chat bot SDK
Go
110
star
16

proofs

Public Keybase Proof System
CoffeeScript
108
star
17

saltpack-python

A Python implementation of saltpack, mainly for testing. Only partial support for V2.
Python
103
star
18

go-merkle-tree

Go language to build and check keybase's sitewide merkle tree.
Go
101
star
19

go-updater

Update framework (golang)
Go
85
star
20

python-triplesec

A Python port of the triplesec library.
Python
80
star
21

slackbot

Slackbot for Keybase
Go
62
star
22

go-notifier

go-notifier: Cross platform system notifications in go (golang)
Go
57
star
23

go-triplesec

A fork of Fillipo's TripleSec
Go
49
star
24

more-entropy

entropy collection in JavaScript for your node and/or browser apps
CoffeeScript
42
star
25

node-merkle-tree

A JS Merkle Tree implementation
CoffeeScript
40
star
26

python-salsa20

Bindings for the NaCL implementation of Salsa20 and XSalsa20 by D. J. Bernstein
C
31
star
27

pgp-utils

Various crypto utilities for dealing with MACs, Signatures, and PGP message formats.
CoffeeScript
30
star
28

gpg-wrapper

A wrapper around the GPG CLI.
CoffeeScript
23
star
29

python-twofish

Bindings for the Twofish implementation by Niels Ferguson
C
22
star
30

node-nacl

NaCl wrapper; uses `sodium` for the server-side and `tweetnacl-js` for the client
JavaScript
22
star
31

node-saltpack

our standard saltpack implementation in JS
JavaScript
21
star
32

dokan-go

Go
19
star
33

pipeliner

A simplified pipline library, for parallel requests with bounded parallelism
Go
19
star
34

django-keybase-proofs

Reference implementation and drop in library for keybase proof integration
Python
19
star
35

go-kext

A library for accessing kernel extensions on OS X.
Go
18
star
36

libweb

A library for building Web clients for keybase, either in the browser or for testing in node.
CoffeeScript
15
star
37

kbfs-beta

Go
14
star
38

messenger

Description and code for a keybase-powered messenger
CoffeeScript
13
star
39

merkle-stellar

Library to read the Keybase Merkle root out of the Stellar blockchain
TypeScript
12
star
40

release

Release tool
Go
11
star
41

hubot-keybase

A Hubot adapter for Keybase bot development
JavaScript
11
star
42

search

Encrypted search of Keybase data (WIP)
Go
10
star
43

libkeybase-js

An library for processing keybase's signature tree.
CoffeeScript
9
star
44

prove_keybase

ruby on rails gemified plugin for implementing our open proof protocol
Ruby
9
star
45

stellarnet

Go
9
star
46

keybase-bot-serverless

JavaScript
9
star
47

node-lru

Simple JS LRU
TypeScript
8
star
48

node-login

A demo login system
CoffeeScript
8
star
49

node-bitcoyne

Bitcoin library built atop kbpgp
CoffeeScript
8
star
50

blockchain

Read a user's Keybase sigchain out of the Bitcoin Blockchain
JavaScript
7
star
51

node-forge-sigchain

A node library to sync and process user sigchains
CoffeeScript
7
star
52

keybase.github.io

Blog and announcements
HTML
7
star
53

blockchain-tools

A tool to insert our Merkle root into the bitcoin blockchain.
CoffeeScript
6
star
54

jenkins-helpers

Helpers for running Jenkins pipeline scripts
Groovy
6
star
55

ruby-client

CLI for keybase.io written for/in Ruby
Ruby
6
star
56

node-bitcoin

A bitcoin library that's browserify-able, forked from bitcoinaddress.org
JavaScript
6
star
57

go-flip

A way to flip coins with your friends
Go
6
star
58

codesign

directory contents summarizer - will be used for code signing feature
CoffeeScript
6
star
59

loopback

A loopback filesystem using bazil.org/fuse
Go
6
star
60

KBShellExt

Windows explorer extension for overlaying sync status icons
C++
6
star
61

colorbase

Example proof service in Clojure - colors for everyone!
Clojure
6
star
62

node-avdl-compiler

AVDL to Go compiler written in IcedCoffeeScript (node)
CoffeeScript
6
star
63

msgpackzip

A compressed for msgpack data that you can configure to not leak secrets
Go
6
star
64

messenger-inbox-server

Inbox Server for the new messaging protocol
CoffeeScript
5
star
65

node-spotty

Get the TTY device (e.g., /dev/pts/3) of the current node process
CoffeeScript
4
star
66

github-ci-status

Check the current CI status of a repo using GitHub's Statuses API
JavaScript
4
star
67

node-armor-x

A base-X-encoding library suitable for stream processing
CoffeeScript
4
star
68

homebrew-beta

Ruby
3
star
69

keybase-test-vectors

Go
3
star
70

go-libcmdline

A small library for handing command line flags
Go
3
star
71

nullFunctionModule

A module that exports a function that returns an empty object
JavaScript
3
star
72

messenger-core

Shared libraries between the client and servers; constants, etc.
CoffeeScript
3
star
73

node-acache

CoffeeScript
2
star
74

kbfs-binary-windows

Binaries required for building kbfs on windows
2
star
75

bot-jira

TypeScript
2
star
76

node-chunk-stream

base class for chunked node streams
JavaScript
2
star
77

node-base64-finder

Find and match base64 blobs
Makefile
2
star
78

logmux

A simple log muxing service
Go
2
star
79

badnode

Report if the node version we're using is bad.
CoffeeScript
2
star
80

player

Standalone sigchain player in TypeScript
TypeScript
2
star
81

clj-keybase-proofs

Helper Clojure library for integrating Keybase proofs
Clojure
2
star
82

vcr

Go
2
star
83

rsp2json

A small command-line utility to convert a NIST-issued RSP file to JSON.
2
star
84

signencrypt.rs

a Rust test implementation of the Go sign+encrypt attachment format
Rust
2
star
85

react-native-v8

Holder for react-native-v8 aars
2
star
86

debatebot

a bot that hooks people up for interesting discussions
TypeScript
2
star
87

nullModule

A null node module
JavaScript
2
star
88

node-http-server

HTTP Server Base classes for servers, build on express and Node.js
CoffeeScript
2
star
89

node-avdl2json

A nodeJS AVDL-to-JSON compiler
CoffeeScript
2
star
90

p2es

A P2ES implementation over Curve25519 using TweetNaCl
C
2
star
91

js-vendor-desktop

Vendored dependencies for Keybase desktop client
1
star
92

bn

JS Bigint Import
JavaScript
1
star
93

kb-styles

colors and styles for keybase
SCSS
1
star
94

node-bjson-express

Express body parsers for BJSON support
CoffeeScript
1
star
95

node-bzip-deflate

A simple bzip deflator
JavaScript
1
star
96

webpack-example

webpack example
JavaScript
1
star
97

proofs-test

Proofs for testing and development.
CoffeeScript
1
star
98

keybase-git

AUR keybase-git PKGBUILD
Shell
1
star
99

node-path

Getting home can be hard sometimes.
CoffeeScript
1
star
100

go-vendor-test

Go
1
star