core-lightning/contrib/pylightning
Christian Decker a707ae091d pylightning: Add hooks as a new type of method
Instead of creating a new map I opted to re-use the Plugin.methods
map, since the semantics are really similar and we don't allow
duplicates. The only difference is in how they are announced to
lightningd, so we use an enum to differentiate rpcmethods from hooks,
since only the former will get added to the JSON-RPC dispatch table in
lightningd.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-01-17 05:42:49 +00:00
..
lightning pylightning: Add hooks as a new type of method 2019-01-17 05:42:49 +00:00
tests pylightning: Added a tiny library for python plugins 2018-12-15 15:04:32 +01:00
lightning-pay [pylightning] Fix lightning-pay script 2018-11-19 21:24:03 +01:00
README.md [doc] Add lightning-pay script as example for using pylightning library 2018-12-10 17:07:34 +01:00
setup.py pylightning: Bump version number to 0.0.6 to make Pypi work again 2018-12-07 10:29:21 +01:00

pylightning: A python client library for lightningd

Installation

Note: With Python 2 you need to have the futures python library installed to be able to use pylightning:

pip install futures

pylightning is available on pip

pip install pylightning

Examples

"""
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']))

Also see the included lightning-pay script, which uses the client library to pay invoices

lightning-pay <bolt11 invoice>
# or explicitly with
lightning-pay <destination_id> <amount in millisatoshi> <payment_hash> <min_final_cltv_expiry>