Skip to main content

pyln-client: 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

pyln-client is available on pip:

pip install pyln-client

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

git clone https://github.com/ElementsProject/lightning.git
cd lightning/contrib/pyln-client
uv sync

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 pyln.client import LightningRpc
import random

# Create two instances of the LightningRpc object using two different Core 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 pyln.client 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`.

    If this returns (a dict), that's the JSON "result" returned.  If
    it raises an exception, that causes a JSON "error" return (raising
    pyln.client.RpcException allows finer control over the return).
    """
    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")
    # This can also return {'disabled': <reason>} to self-disable,
	# but normally it returns None.


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


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

Release files for pyln-client 26.6.7

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

Source distribution (sdist)

Source distribution for pyln-client 26.6.7
File Size Uploaded
pyln_client-26.6.7.tar.gz 92.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyln-client 26.6.7
File Interpreter ABI Platform
pyln_client-26.6.7-py3-none-any.whl Python 3 none any Details

Total release size: 130.5 kB

Release files / pyln_client-26.6.7.tar.gz

Download URL pyln_client-26.6.7.tar.gz
Size 92.5 kB
Tags Source
SHA-256 checksum
How to use checksums
544c57d50f8fc8576673a890d937e6bee35c1e77037f62c6cb360fda7e74e061
BLAKE2b-256 checksum
How to use checksums
322701dae9bb20896a16d3f9a76ca701ac4b45a0c260897822662a9480d91816
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pyln_client-26.6.7-py3-none-any.whl

Download URL pyln_client-26.6.7-py3-none-any.whl
Size 38.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57e88d5e380986f817a613849089f173ae09f0ffd73bf63d89262e8ca25aeb21
BLAKE2b-256 checksum
How to use checksums
bf4bcfa9a2f42d52eaee3e8114701ebb7b328e2a093d726be5ed1bbbaa40d5f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

26.6.8

2 release files

This release

26.6.7 This release

2 release files

26.6.6

2 release files

26.6.2

2 release files

26.6

2 release files

26.4.2

2 release files

26.4.1

2 release files

26.4

2 release files

25.12

2 release files

25.9.1

2 release files

25.9

2 release files

25.5

2 release files

25.2.2

2 release files

25.2

2 release files

24.11

2 release files

24.8.2

2 release files

24.8

2 release files

24.5

2 release files

24.2

2 release files

23.11

2 release files

23.8

2 release files

23.5.2

2 release files

23.5

2 release files

23.2

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.8.2

2 release files

0.8.0

2 release files

0.7.3

3 release files

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