Skip to main content

pylightning: A python client library for lightningd

This package implements the Unix socket based JSON-RPC protocol that lightningd exposes to the rest of the world. It can be used to call arbitrary functions on the RPC interface, and serves as a basis for plugins written in python.

Installation

pylightning is available on pip:

pip install pylightning

Alternatively you can also install the development version to get access to currently unreleased features by checking out the c-lightning source code and installing into your python3 environment:

git clone https://github.com/ElementsProject/lightning.git
cd lightning/contrib/pylightning
python3 setup.py develop

This will add links to the library into your environment so changing the checked out source code will also result in the environment picking up these changes. Notice however that unreleased versions may change API without warning, so test thoroughly with the released version.

Examples

Using the JSON-RPC client

"""
Generate invoice on one daemon and pay it on the other
"""
from lightning import LightningRpc
import random

# Create two instances of the LightningRpc object using two different c-lightning daemons on your computer
l1 = LightningRpc("/tmp/lightning1/lightning-rpc")
l5 = LightningRpc("/tmp/lightning5/lightning-rpc")

info5 = l5.getinfo()
print(info5)

# Create invoice for test payment
invoice = l5.invoice(100, "lbl{}".format(random.random()), "testpayment")
print(invoice)

# Get route to l1
route = l1.getroute(info5['id'], 100, 1)
print(route)

# Pay invoice
print(l1.sendpay(route['route'], invoice['payment_hash']))

Writing a plugin

Plugins are programs that lightningd can be configured to execute alongside the main daemon. They allow advanced interactions with and customizations to the daemon.

#!/usr/bin/env python3
from lightning import Plugin

plugin = Plugin()

@plugin.method("hello")
def hello(plugin, name="world"):
    """This is the documentation string for the hello-function.

    It gets reported as the description when registering the function
    as a method with `lightningd`.

    """
    greeting = plugin.get_option('greeting')
    s = '{} {}'.format(greeting, name)
    plugin.log(s)
    return s


@plugin.init()
def init(options, configuration, plugin):
    plugin.log("Plugin helloworld.py initialized")


@plugin.subscribe("connect")
def on_connect(plugin, id, address):
    plugin.log("Received connect event for peer {}".format(id))


plugin.add_option('greeting', 'Hello', 'The greeting I should use.')
plugin.run()

Release files for pylightning 0.0.7.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylightning 0.0.7.3
File Size Uploaded
pylightning-0.0.7.3.tar.gz 15.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylightning 0.0.7.3
File Interpreter ABI Platform
pylightning-0.0.7.3-py3-none-any.whl Python 3 none any Details

Total release size: 31.9 kB

Release files / pylightning-0.0.7.3.tar.gz

Download URL pylightning-0.0.7.3.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6a07b62b27e01baaf51165e2dfb8b7d1d47f61aef8304a9da3ca5081608a32c0
BLAKE2b-256 checksum
How to use checksums
7fc418e10a5d9ecd60888f892ba78b4ab8be280e62834d4e02ea3111af83b7c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.6.7

Release files / pylightning-0.0.7.3-py3-none-any.whl

Download URL pylightning-0.0.7.3-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b7df2c6f0faf17450ea3024f29f901a114d4c68da116a1b130958df510a0557
BLAKE2b-256 checksum
How to use checksums
1a17501d6159fd6d98a2e4dfc1b320ab7f44b9c08f914631dffde7a09fe52b0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

0.0.7.3 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page