Package: py-lnd-grpc
lndgrpcA python grpc client for LND (Lightning Network Daemon) ⚡⚡⚡This is a wrapper around the default grpc interface that handles setting up credentials (including macaroons). An async client is also available to do fun async stuff like listening for invoices in the background.DependenciesPython 3.6+Working LND lightning node, take note of its ip address.Copy your admin.macaroon and tls.cert files from your node to a directoy on your machine.Installationpipinstallpy-lnd-grpc# Test it is working# Set these values as needed!exportCRED_PATH=/path/to/macaroon/and/tls/certexportLND_NODE_IP=192.168.1.xx# This will run a get_info() request on your node, checking its connection.python3-mlndgrpcEnvironment VariablesThese environment variables are only used when testing node connectivity and/or correct module installation from the command line. This library is primarily used through Python scripting.exportCRED_PATH=/path/to/macaroon/and/tls/certexportLND_NODE_IP=192.168.1.xx

python3-mlndgrpc# You should expect to see:## .....# .....# .....# lndgrpc package is installed... Wow it works!Basic UsageThe api mirrors the underlying lnd grpc api (http://api.lightning.community/) but methods will be in pep8 style. ie..GetInfo()becomes.get_info().fromlndgrpcimportLNDClient# pass in the ip-address with RPC port and network ('mainnet', 'testnet', 'simnet')# the client defaults to 127.0.0.1:10009 and mainnet if no args providedlnd=LNDClient("127.0.0.1:10009",network='simnet')# Unlock you walletlnd.unlock_wallet(wallet_password=b"your_wallet_password")# Get general data about your nodelnd.get_info()print('Listening for invoices...')forinvoiceinlnd.subscribe_invoices():print(invoice)AsyncimportasynciofromlndgrpcimportAsyncLNDClientasync_lnd=AsyncLNDClient()asyncdefsubscribe_invoices():print('Listening for invoices...')asyncforinvoiceinasync_lnd.subscribe_invoices():print(invoice)asyncdefget_info():whileTrue:info=awaitasync_lnd.get_info()print(info)awaitasyncio.sleep(5)asyncdefrun():coros=[subscribe_invoices(),get_info()]awaitasyncio.gather(*coros)loop=asyncio.get_event_loop()loop.run_until_complete(run())Specifying Macaroon/Cert filesBy default the client will attempt to lookup thereadonly.macaronandtls.certfiles in the mainnet directory.
However if you want to specify a different macaroon or different path you can pass in the filepath explicitly.lnd=LNDClient(macaroon_filepath='~/.lnd/invoice.macaroon',cert_filepath='path/to/tls.cert')Generating LND Proto Filesvirtualenvlndsourcelnd/bin/activate
pipinstallgrpciogrpcio-toolsgoogleapis-common-protossh
gitclonehttps://github.com/lightningnetwork/lnd.git
mkdirgenprotos
gitclonehttps://github.com/googleapis/googleapis.gitfrompathlibimportPathimportshutilimportsh# TODO: these paths are messed upforprotoinlist(Path("../../../lnd/lnrpc").rglob("*.proto")):shutil.copy(proto,Path.cwd())protos=list(Path(".").joinpath("lndgrpc/compiled/").glob("*.proto"))args=["-m","grpc_tools.protoc","--proto_path=lndgrpc/compiled/googleapis:.","--python_out=.","--grpc_python_out=.",]forprotofileinprotos:args.append(str(protofile))# Generate the compiled protofilessh.python(args)Last Step:
In File: verrpc_pb2_grpc.py
Change:
import verrpc_pb2 as verrpc__pb2
To:
from lndgrpc import verrpc_pb2 as verrpc__pb2Deploy to Test-PyPipoetrybuild
twinecheckdist/*
twineupload--repository-urlhttps://test.pypi.org/legacy/dist/*