Basilisk developer guide
Basilisk runs on your own computer and has no HTTP API. Its developer surface is the plugin API (version 1): commands and event hooks written in Python.
Add a command
A plugin is one Python file with a register(api) function. api.register_command(name, help, func, configure=None) adds basilisk <name>. func(args) gets the argparse namespace and may return an exit code. configure(subparser) adds the command's own arguments.
hello.py
def hello(args):
print("Hello, %s." % args.name)
return 0
def configure_hello(parser):
parser.add_argument("--name", default="world", help="Who to greet.")
def on_encrypt(event):
# event is a read-only mapping: status, fingerprints, filename, signed, armored ...
print("encrypt %s for %d recipient(s)" % (event["status"], len(event.get("fingerprints", ()))))
def register(api):
api.register_command("hello", "Print a greeting.", hello, configure=configure_hello)
api.on_encrypt(on_encrypt)Rules
- Command names are lowercase letters, digits and hyphens, up to 32 characters, starting with a letter.
- Built-in names (
plugins,encrypt,decrypt,sign,verify,help,versionand other reserved names) and names another plugin already took are refused withPluginError. - Registration is only allowed while
register(api)runs. api.name,api.api_version(currently 1) andapi.eventsare read-only.
React to events
api.on(event, handler) calls handler(event) with a read-only mapping. Shortcuts: api.on_startup, on_encrypt, on_decrypt, on_sign, on_verify.
| Event | When | Typical fields |
|---|---|---|
on_startup | The desktop window is created | version, plugins |
on_encrypt | After text or a file is encrypted | status, fingerprints, signed, armored, filename |
on_decrypt | After a decrypt attempt | status, key_fingerprint, signed, signature_valid, filename |
on_sign | After signing | status, key_fingerprint, mode, filename |
on_verify | After a verify attempt | status, signature_valid, signer_fingerprint |
Events only ever hold non-secret fields: event, status (ok or failed), version, plugins, fingerprints, key_fingerprint, signer_fingerprint, signer_fingerprints, filename (base name only), mode, armored, signed, signature_valid. Handlers run after the operation, cannot change its result, and an exception in a handler is logged by plugin name and ignored.
Turn plugins on
Plugins are off by default. Run Basilisk with --plugins, or set enabled = true in plugins.toml.
plugins.toml
enabled = true
# Optional pin list. When present, only files with these SHA-256 hashes are loaded.
allow_sha256 = ["<64 hex characters>"]Locations
- Plugin folder:
%APPDATA%\Basilisk\pluginson Windows,~/.config/basilisk/pluginselsewhere ($XDG_CONFIG_HOME/basilisk/pluginsif set). Override withBASILISK_PLUGIN_DIR. plugins.tomlsits next to the plugin folder. Override withBASILISK_PLUGIN_CONFIG.basilisk plugins listshows each loaded plugin with its SHA-256 and what it registered, and each skipped plugin with the reason.
What plugins can and cannot see
The plugin API has no vault, keyring or key access. Plaintext, passphrases, private keys and authenticator seeds are never passed to a handler.
- A plugin is ordinary Python running inside Basilisk. It is not sandboxed: it can read files or open network connections like any script you run. Only use code you wrote or trust, and pin it with
allow_sha256. - The hash is taken from the exact bytes that are then executed, and no bytecode is written next to the plugin.
- A plugin that fails to load (syntax error, exception, missing
register, hash not allowed, bad name) is logged by file name with the error type and skipped. Basilisk keeps running. - Files starting with
_or., sub-folders and symbolic links are ignored. A brokenplugins.tomldisables plugins rather than loading everything.