<p>Here is a simple implementation that just works</p>

<pre><code>import requests

class EclairClient():
    def __init__(self,host, port, password, service_name=None, session=None):
        self._host = host
        self._port = port
        self._password = password
        self._session = session
        if session is None:
            self._session = requests.Session()
        self._service_name = service_name
        self._url = "http://%s:%s/%s" % (self._host, self._port, self._service_name)

    def __getattr__(self, name):
        if name.startswith('__') and name.endswith('__'):
            # Python internal stuff
            raise AttributeError
        if self._service_name is not None:
            name = "%s.%s" % (self._service_name, name)
        return EclairClient(self._host, self._port, self._password, name, self._session )

    def __call__(self, *args, **kwargs):
        return self._session.post(self._url, data=kwargs,auth=('', self._password)).json()
</code></pre>

<pre><code>password = "mypassword"
c = EclairClient("localhost", 8080, password)
c.getinfo()
&gt;&gt;&gt; {u'alias': u'blinktrade DEV',
&gt;&gt;&gt;  u'blockHeight': 1583023,
&gt;&gt;&gt; u'chainHash': u'43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea330900000000',
&gt;&gt;&gt; u'nodeId': u'038b3f00c4a535238b748f025038dcbb825c4e2a03f08ab1c391f0bfada4b31b45',
&gt;&gt;&gt; u'publicAddresses': []}

c.createinvoice(description="testing", amountMsat=15000)
&gt;&gt;&gt;{u'amount': 15000,
&gt;&gt;&gt; u'description': u'testing',
&gt;&gt;&gt; u'expiry': 3600,
&gt;&gt;&gt; u'nodeId': u'038b3f00c4a535238b748f025038dcbb825c4e2a03f08ab1c391f0bfada4b31b45',
&gt;&gt;&gt; u'paymentHash': u'0eb6ea2dcb36b99a0e7ab3e09bff97c0e32277a5017034cf2e39859de00f4a8e',
&gt;&gt;&gt; u'prefix': u'lntb',
&gt;&gt;&gt; u'serialized': u'lntb150n1pw62a8zpp5p6mw5twtx6ue5rn6k0sfhluhcr3jyaa9q9crfnew8xzemcq0f28qdqvw3jhxarfdensxqrrssdwfxdxrvkdtaetg5k8dz3j42hpupffvdzljsl3nls9faujuxt5e4elu0cnvszg0vhs3m2gw28d4h9c83saxfk0qs4ygwd6yaa5dt8uqpamka3f',
&gt;&gt;&gt; u'timestamp': 1571124450}
</code></pre>

CC BY-SA 4.0
2019-12-16T11:49:25.830Z
This script provides strange results for [sendtoroute](https://acinq.github.io/eclair/#sendtoroute) command. Given a `route`, it seems that it tries to route to the first element of the list (i.e. sending node), and the payment gets stuck in `pending` state. An analogous command in CLI works as expected. What may be the reason?
Sergei Tikhomirov
CC BY-SA 4.0
2019-10-15T07:40:00.390Z
2019-10-15T07:40:00.390Z
Rodrigo Pinho Pereira de Souza
<p>This might not be a satisfying answer but if you look at the eclair git repo and their <a href="https://github.com/ACINQ/eclair/wiki/API" rel="nofollow noreferrer">Wiki</a> you will find that <a href="https://acinq.github.io/eclair/" rel="nofollow noreferrer">the eclair API</a> is a JSON API and is exposed via http and web sockets and can be queried with regular http requests.</p>

<p>If you look at the <a href="https://github.com/ElementsProject/lightning/blob/master/contrib/pylightning/lightning/lightning.py" rel="nofollow noreferrer">c-lightning python client</a> it is a tool that talks via a unixDomainSocket to the exposed <code>lightningd</code> api. So I guess you could in a smilar way quickly create a python wrapper to be able to talk to eclair. </p>

<p>It seems to me that currently no one has bothered to do so. </p>

CC BY-SA 4.0
2019-09-18T11:23:23.577Z
This is a good idea, the wrapper python for eclair should be an good training for my skill with python
vincenzopalazzo
CC BY-SA 4.0
2019-09-18T10:41:33.077Z
2019-09-18T10:41:33.077Z
Rene Pickhardt
<p>I want to write some scripts for experiments with Lightning. Python is the language I'm most comfortable with. From the three major implementations, LND has <a href="https://dev.lightning.community/guides/python-grpc/" rel="nofollow noreferrer">python-grpc</a> and c-lightning has <a href="https://github.com/ElementsProject/lightning/tree/master/contrib/pylightning" rel="nofollow noreferrer">pylightning</a>, but what about Eclair? How can I interact with an Eclair node from a Python script?</p>

<lightning-network><python><eclair>
How can I interact with Eclair from Python?
Sergei Tikhomirov
# How can I interact with Eclair from Python?

(Asked by: username_0 on 2019-09-18)

I want to write some scripts for experiments with Lightning. Python is the language I'm most comfortable with. From the three major implementations, LND has [python-grpc](https://dev.lightning.community/guides/python-grpc/) and c-lightning has [pylightning](https://github.com/ElementsProject/lightning/tree/master/contrib/pylightning), but what about Eclair? How can I interact with an Eclair node from a Python script?

**Tags:** lightning-network, python, eclair


---

## 2 answers

### Answer by username_1 on 2019-10-15. Score: 2 | Accepted answer

Here is a simple implementation that just works

```
import requests

class EclairClient():
    def __init__(self,host, port, password, service_name=None, session=None):
        self._host = host
        self._port = port
        self._password = password
        self._session = session
        if session is None:
            self._session = requests.Session()
        self._service_name = service_name
        self._url = "http://%s:%s/%s" % (self._host, self._port, self._service_name)

    def __getattr__(self, name):
        if name.startswith('__') and name.endswith('__'):
            # Python internal stuff
            raise AttributeError
        if self._service_name is not None:
            name = "%s.%s" % (self._service_name, name)
        return EclairClient(self._host, self._port, self._password, name, self._session )

    def __call__(self, *args, **kwargs):
        return self._session.post(self._url, data=kwargs,auth=('', self._password)).json()

```

```
password = "mypassword"
c = EclairClient("localhost", 8080, password)
c.getinfo()
>>> {u'alias': u'blinktrade DEV',
>>>  u'blockHeight': 1583023,
>>> u'chainHash': u'43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea330900000000',
>>> u'nodeId': u'038b3f00c4a535238b748f025038dcbb825c4e2a03f08ab1c391f0bfada4b31b45',
>>> u'publicAddresses': []}

c.createinvoice(description="testing", amountMsat=15000)
>>>{u'amount': 15000,
>>> u'description': u'testing',
>>> u'expiry': 3600,
>>> u'nodeId': u'038b3f00c4a535238b748f025038dcbb825c4e2a03f08ab1c391f0bfada4b31b45',
>>> u'paymentHash': u'0eb6ea2dcb36b99a0e7ab3e09bff97c0e32277a5017034cf2e39859de00f4a8e',
>>> u'prefix': u'lntb',
>>> u'serialized': u'lntb150n1pw62a8zpp5p6mw5twtx6ue5rn6k0sfhluhcr3jyaa9q9crfnew8xzemcq0f28qdqvw3jhxarfdensxqrrssdwfxdxrvkdtaetg5k8dz3j42hpupffvdzljsl3nls9faujuxt5e4elu0cnvszg0vhs3m2gw28d4h9c83saxfk0qs4ygwd6yaa5dt8uqpamka3f',
>>> u'timestamp': 1571124450}

```

> **Comments:**
> **username_0**: This script provides strange results for [sendtoroute](https://acinq.github.io/eclair/#sendtoroute) command. Given a `route`, it seems that it tries to route to the first element of the list (i.e. sending node), and the payment gets stuck in `pending` state. An analogous command in CLI works as expected. What may be the reason?  

---

### Answer by username_2 on 2019-09-18. Score: 2

This might not be a satisfying answer but if you look at the eclair git repo and their [Wiki](https://github.com/ACINQ/eclair/wiki/API) you will find that [the eclair API](https://acinq.github.io/eclair/) is a JSON API and is exposed via http and web sockets and can be queried with regular http requests.

If you look at the [c-lightning python client](https://github.com/ElementsProject/lightning/blob/master/contrib/pylightning/lightning/lightning.py) it is a tool that talks via a unixDomainSocket to the exposed `lightningd` api. So I guess you could in a smilar way quickly create a python wrapper to be able to talk to eclair.

It seems to me that currently no one has bothered to do so.

> **Comments:**
> **username_3**: This is a good idea, the wrapper python for eclair should be an good training for my skill with python  

---

