[BREAKGLASS] Python client for the BTCPay API. https://docs.btcpayserver.org/integrations/customintegration
Go to file
2019-03-11 11:07:53 -04:00
btcpay Prepare Prior PR #4 for PyPI to Make It Installable (#5) 2019-01-16 23:24:17 -05:00
.gitignore version bump 2019-01-16 23:39:34 -05:00
LICENSE switched to MIT license 2018-03-07 18:42:22 -05:00
README.md Update README.md 2019-03-11 11:07:53 -04:00
setup.py match name 2019-01-17 09:58:45 -05:00

btcpay-python

Install

pip3 install btcpay-python

If you were a user of the prior unofficial client library for Python, you would need to uninstall it first:

pip3 uninstall btcpay
pip3 install btcpay-python

This library is fully backward compatibile with the prior unofficial library; no code changes are needed.

The "easy method" to create a new BTCPay client

  • On BTCPay server > shop > access tokens > create new token, copy pairing code.
  • Then use that code in the below Python code:
from btcpay import BTCPayClient

client = BTCPayClient.create_client(host='https://btcpay.example.com', code=<pairing-code>)

Uses for the client object you just created above

Get rates

client.get_rates()

Create specific rate

client.get_rate('USD')

Create invoice

See bitpay api documentation: https://bitpay.com/api#resource-Invoices

client.create_invoice({"price": 20, "currency": "USD"})

Get invoice

client.get_invoice(<invoice-id>)

Storing the client object for later

You do not need to store any tokens or private keys. Simply pickle the client object and save it to your persistent storage method (Redis, SQLAlchemy, etc). Pull it from persistent storage later, unpickle it, and perform any of the methods above on it which you may need.

Creating a client the manual way (not necessary if you used the 'easy' method above)

  • Generate and save private key:
import btcpay.crypto
privkey = btcpay.crypto.generate_privkey()
  • Create client:
from btcpay import BTCPayClient
client = BTCPayClient(host='http://hostname', pem=privkey)
  • On BTCPay server > shop > access tokens > create new token, copy pairing code:
  • Pair client to server and save returned token:
client.pair_client(<pairing-code>)
>>> {'merchant': "xdr9vw3v5wc0w90859v45"}
  • Recreate client:
client = BTCPayClient(
    host='http://hostname',
    pem=privkey,
    tokens={'merchant': "xdr9vw3v5wc0w90859v45"}
)