<p>You can use <a href="https://www.blockonomics.co" rel="nofollow">blockonomics</a>, its pretty fast. It also has API to give balance of given xpub.  </p>

<p>If you don't want to submit your xpub to server you can use <a href="https://github.com/dan-da/hd-wallet-addrs" rel="nofollow">https://github.com/dan-da/hd-wallet-addrs</a>. This will select random balance API service for each address and do HD walkthrough.</p>

<p>Added example code using blockr api, fetches balances for 20 addreses at once, should be pretty fast</p>



<pre><code>import pycoin.key
import sys
import os
os.environ["PYCOIN_NATIVE"]="openssl"
import requests
BATCH_SIZE = 20
BLOCKR_URL= "http://btc.blockr.io/api/v1/address/info"
def get_used_addresses(xpub, account_type):
  xpub_subkey = xpub.subkey(account_type)
  index = 0
  addr_batch = []
  output = []
  while True:
    addr = xpub_subkey.subkey(index).bitcoin_address()
    addr_batch.append(addr)
    if (index+1)%BATCH_SIZE==0:
      results = requests.get("{}/{}".format(BLOCKR_URL, ",".join(addr_batch))).json()
      addr_batch = []
      used_addrs = [x["address"] for x in results['data'] if not x["is_unknown"]]   
      if (used_addrs):                       
        output.extend(used_addrs)
      else:  
        break                     
    index += 1
  return output

def main():
  xpub = pycoin.key.Key.from_text(sys.argv[1])
  result = []
  result.extend(get_used_addresses(xpub, 0))
  result.extend(get_used_addresses(xpub, 1))
  print result

if __name__ == "__main__":
  main()
</code></pre>

CC BY-SA 3.0
2016-08-22T22:30:58.803Z
1. Blockonomics has a 50 address limit. If I wanted to send my pubkey to a third party server, then I would use blockchain.ifo/xpub. It's faster.
Whyte the Weeabear
CC BY-SA 3.0
2016-08-22T22:31:39.490Z
2. This is the PHP script I was talking about. It takes way too long to process.
Whyte the Weeabear
CC BY-SA 3.0
2016-08-23T05:40:11.357Z
Not sure if you looked at --batch-size parameter in the PHP script. That way it will lookup multiple addresses at once and should be faster.  Another bottleneck is the generation of subkey, with python u can use https://github.com/richardkiss/pycoin with PYCOIN_NATIVE=openssl, this really helps to speed up.
dark knight
CC BY-SA 3.0
2016-08-23T11:50:03.763Z
added example code in python
dark knight
CC BY-SA 3.0
2016-08-23T11:58:33.247Z
I'm not sure how I would put these two together - one is PHP another is Python...
Whyte the Weeabear
CC BY-SA 3.0
2016-08-23T12:14:44.373Z
@WhytetheWeeabear I added the python code sample, you can directly use that, don't worry about php
dark knight
CC BY-SA 3.0
2016-08-23T12:50:08.847Z
Tried your code, gave me "IndexError: list index out of range"
Whyte the Weeabear
CC BY-SA 3.0
2016-08-23T12:53:57.160Z
You should pass xpub as parameter to program
dark knight
CC BY-SA 3.0
2016-08-23T12:57:00.613Z
Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/44356/discussion-between-dark-knight-and-whyte-the-weeabear).
dark knight
CC BY-SA 3.0
2017-12-09T10:37:52.530Z
The script does not work with segwit wallets (BIP49).
ccpizza
CC BY-SA 3.0
2016-08-22T14:01:20.533Z
2016-08-23T11:49:39.300Z
2016-08-23T11:49:39.300Z
dark knight
<p>I currently use a Ledger wallet and find it a hassle to plug it in every time I want to check my balance.</p>

<p>I have access to my master xpub key, how would I find out all the addresses corresponding to it? Is there any site that hosts this service and has an API? </p>

<p>I found a script online that does this, but it's written in PHP and is quite slow. I'm looking for something compatible with python.</p>

CC BY-SA 3.0
2017-12-09T10:28:49.973Z
There is an answer here: https://bitcoin.stackexchange.com/a/64685/38324
ccpizza
<api><bip32-hd-wallets>
Find all used addresses using xpub key
Whyte the Weeabear
# Find all used addresses using xpub key

(Asked by: username_0 on 2016-08-22)

I currently use a Ledger wallet and find it a hassle to plug it in every time I want to check my balance.

I have access to my master xpub key, how would I find out all the addresses corresponding to it? Is there any site that hosts this service and has an API?

I found a script online that does this, but it's written in PHP and is quite slow. I'm looking for something compatible with python.

**Tags:** api, bip32-hd-wallets

> **Comments:**
> **username_1**: There is an answer here: https://bitcoin.stackexchange.com/a/64685/38324  

---

## 1 answers

### Answer by username_2 on 2016-08-22. Score: 4

You can use [blockonomics](https://www.blockonomics.co), its pretty fast. It also has API to give balance of given xpub.

If you don't want to submit your xpub to server you can use <https://github.com/dan-da/hd-wallet-addrs>. This will select random balance API service for each address and do HD walkthrough.

Added example code using blockr api, fetches balances for 20 addreses at once, should be pretty fast

```
import pycoin.key
import sys
import os
os.environ["PYCOIN_NATIVE"]="openssl"
import requests
BATCH_SIZE = 20
BLOCKR_URL= "http://btc.blockr.io/api/v1/address/info"
def get_used_addresses(xpub, account_type):
  xpub_subkey = xpub.subkey(account_type)
  index = 0
  addr_batch = []
  output = []
  while True:
    addr = xpub_subkey.subkey(index).bitcoin_address()
    addr_batch.append(addr)
    if (index+1)%BATCH_SIZE==0:
      results = requests.get("{}/{}".format(BLOCKR_URL, ",".join(addr_batch))).json()
      addr_batch = []
      used_addrs = [x["address"] for x in results['data'] if not x["is_unknown"]]   
      if (used_addrs):                       
        output.extend(used_addrs)
      else:  
        break                     
    index += 1
  return output

def main():
  xpub = pycoin.key.Key.from_text(sys.argv[1])
  result = []
  result.extend(get_used_addresses(xpub, 0))
  result.extend(get_used_addresses(xpub, 1))
  print result

if __name__ == "__main__":
  main()

```

> **Comments:**
> **username_0**: 1. Blockonomics has a 50 address limit. If I wanted to send my pubkey to a third party server, then I would use blockchain.ifo/xpub. It's faster.  
> **username_0**: 2. This is the PHP script I was talking about. It takes way too long to process.  
> **username_2**: Not sure if you looked at --batch-size parameter in the PHP script. That way it will lookup multiple addresses at once and should be faster.  Another bottleneck is the generation of subkey, with python u can use https://github.com/richardkiss/pycoin with PYCOIN_NATIVE=openssl, this really helps to speed up.  
> **username_2**: added example code in python  
> **username_0**: I'm not sure how I would put these two together - one is PHP another is Python...  
> **username_2**: @username_0 I added the python code sample, you can directly use that, don't worry about php  
> **username_0**: Tried your code, gave me "IndexError: list index out of range"  
> **username_2**: You should pass xpub as parameter to program  
> **username_2**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/44356/discussion-between-username_2-and-username_0).  
> **username_1**: The script does not work with segwit wallets (BIP49).  

---

