<p>I'm currently compiling a master thesis on the topic of coin selection and I'm not aware of a Python implementation of Bitcoin Core's coin selection algorithm.</p>

CC BY-SA 3.0
2016-07-30T10:50:21.720Z
thanks @Murch ! Your response: bitcoin.stackexchange.com/a/32445/15567 alludes to what I am after, but as you pointed out, there is no such implementation in Python yet. Since I am looking to replicate what Bitcoin Core does(admittedly not optimal), I will code it up in Python from guidance on that post and paste on here later.
kumarz
CC BY-SA 3.0
2016-07-27T06:10:14.873Z
2016-07-27T06:10:14.873Z
Murch
<p>Does anyone know of a good coin selection algorithm <strong><em>in Python</em></strong> that's perhaps similar to the one in Bitcoin Core (currently this: <a href="https://github.com/bitcoin/bitcoin/blob/v0.5.3/src/wallet.cpp#L760" rel="nofollow noreferrer">github/bitcoin/src/wallet.cpp</a> <em>(per guidance from <a href="https://bitcoin.stackexchange.com/questions/1077/what-is-the-coin-selection-algorithm">stackexchange/1077</a>)</em>)?</p>

<p>I see the popular python libraries: <a href="https://github.com/vbuterin/pybitcointools" rel="nofollow noreferrer">pybitcointools</a> and <a href="https://github.com/richardkiss/pycoin" rel="nofollow noreferrer">pycoin</a> both seem to be selecting all existing UTXOs which might not be optimal, and might fail @over 100 utxos. Andreas Antonopoulos' <a href="https://books.google.co.uk/books?id=k3qrBQAAQBAJ&amp;pg=PT132&amp;lpg=PT132&amp;dq=greedy%20algorithm%20select%20utxo&amp;source=bl&amp;ots=7B3n_2Q33M&amp;sig=7JHq6wDmcLGVPGbvcu7xnf4aTBg&amp;hl=en&amp;sa=X&amp;ved=0ahUKEwi32Jubj5HOAhXsKsAKHbCdClYQ6AEIFDAA" rel="nofollow noreferrer">"greedy selection algo"</a> is not as efficient as that in <code>wallet.cpp</code> of Bitcoin Core, am I right?</p>

CC BY-SA 3.0
2016-07-26T20:55:06.667Z
Just a note, there is no 'optimal' coin selection algorithm. There are trade-offs between privacy, UTXO set size, and a few other things, as is described well here: http://bitcoin.stackexchange.com/q/32145/18196.
morsecoder
CC BY-SA 3.0
2016-07-27T06:11:55.153Z
I'm currently compiling a master thesis on the topic of coin selection and I'm not aware of a Python implementation of Bitcoin Core's coin selection algorithm. I am however not up-to-date whether there are more Bitcoin wallet implementations in Python.
Murch
CC BY-SA 3.0
2016-07-30T10:49:09.610Z
thanks so much @StephenM347 , Murch 's response: http://bitcoin.stackexchange.com/a/32445/15567 alludes to what I am after, but as he pointed out, there is no such implementation in Python yet. Since I am looking to replicate what Bitcoin Core does(admittedly not optimal), I will code it up in Python from guidance on that post and paste on here later.
kumarz
<bitcoin-core><python><coin-selection>
Coin selection algorithm in Python to optimally select UTXO
kumarz
# Coin selection algorithm in Python to optimally select UTXO

(Asked by: username_0 on 2016-07-26)

Does anyone know of a good coin selection algorithm ***in Python*** that's perhaps similar to the one in Bitcoin Core (currently this: [github/bitcoin/src/wallet.cpp](https://github.com/bitcoin/bitcoin/blob/v0.5.3/src/wallet.cpp#L760) *(per guidance from [stackexchange/1077](https://bitcoin.stackexchange.com/questions/1077/what-is-the-coin-selection-algorithm))*)?

I see the popular python libraries: [pybitcointools](https://github.com/vbuterin/pybitcointools) and [pycoin](https://github.com/richardkiss/pycoin) both seem to be selecting all existing UTXOs which might not be optimal, and might fail @over 100 utxos. Andreas Antonopoulos' ["greedy selection algo"](https://books.google.co.uk/books?id=k3qrBQAAQBAJ&pg=PT132&lpg=PT132&dq=greedy%20algorithm%20select%20utxo&source=bl&ots=7B3n_2Q33M&sig=7JHq6wDmcLGVPGbvcu7xnf4aTBg&hl=en&sa=X&ved=0ahUKEwi32Jubj5HOAhXsKsAKHbCdClYQ6AEIFDAA) is not as efficient as that in `wallet.cpp` of Bitcoin Core, am I right?

**Tags:** bitcoin-core, python, coin-selection

> **Comments:**
> **username_1**: Just a note, there is no 'optimal' coin selection algorithm. There are trade-offs between privacy, UTXO set size, and a few other things, as is described well here: http://bitcoin.stackexchange.com/q/32145/18196.  
> **username_2**: I'm currently compiling a master thesis on the topic of coin selection and I'm not aware of a Python implementation of Bitcoin Core's coin selection algorithm. I am however not up-to-date whether there are more Bitcoin wallet implementations in Python.  
> **username_0**: thanks so much @StephenM347 , username_2 's response: http://bitcoin.stackexchange.com/a/32445/15567 alludes to what I am after, but as he pointed out, there is no such implementation in Python yet. Since I am looking to replicate what Bitcoin Core does(admittedly not optimal), I will code it up in Python from guidance on that post and paste on here later.  

---

## 1 answers

### Answer by username_2 on 2016-07-27. Score: 1

I'm currently compiling a master thesis on the topic of coin selection and I'm not aware of a Python implementation of Bitcoin Core's coin selection algorithm.

> **Comments:**
> **username_0**: thanks @username_2 ! Your response: bitcoin.stackexchange.com/a/32445/15567 alludes to what I am after, but as you pointed out, there is no such implementation in Python yet. Since I am looking to replicate what Bitcoin Core does(admittedly not optimal), I will code it up in Python from guidance on that post and paste on here later.  

---

