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()
Metadata
Release files for pyln-client 26.6.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyln_client-26.6.9.tar.gz | 92.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyln_client-26.6.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 130.5 kB
Release files / pyln_client-26.6.9.tar.gz
| Download URL | pyln_client-26.6.9.tar.gz |
|---|---|
| Size | 92.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
881212d80accfb6d1d6cc000bfc4e1b98a837a6ca5b543f46d37d396929fbe99
|
|
BLAKE2b-256 checksum How to use checksums |
50b8b9ba64daf6af79e6894dbb5fb3b0742e699f800ddb1dde0da2f1b80e8616
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pyln_client-26.6.9-py3-none-any.whl
| Download URL | pyln_client-26.6.9-py3-none-any.whl |
|---|---|
| Size | 38.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a15e2494b8a580844296d2d6020bdb258b54e57f2a52c4c65993246ea720a26f
|
|
BLAKE2b-256 checksum How to use checksums |
1e41588fa6fc0f3f78577100615a5496659c35ce18ef8bf5f2e522e5251473f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pyln-client 26.6.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.