byrnereese / uphold-sdk-python

An SDK for the Uphold API.
MIT License
47 stars 27 forks source link

Uphold Python SDK

Welcome to the Uphold SDK for Python developers. Using this library, developers can more easily get started using the Uphold API.

Getting Started

To begin, visit the Uphold website and create an account. With a username and password in hand, you can begin building apps against the Uphold API immediately.

Authentication

There are three ways to authenticate against the API:

You can find out more about these two methods in our API documentation.

Basic Auth

Basic Authentication is performed when you transmit a username and password to Uphold.

Basic Auth is not recommended for most application due to security concerns, but is required in one circumstance: creating a Personal Access Token.

Please note that if your account has two factor authentication enabled, you will need to set the OTP parameter as well. The OTP parameter is the verification code sent to you when you attempt to login when 2FA is enabled.

Code Sample

from uphold import Uphold
api = Uphold()
api.opt( <code> )
api.auth_basic( <username>, <password> )
me = api.get_me()

Personal Access Token Example

A Personal Access Token, or "PAT," is ideal when you are accessing your own account. When using a PAT, two-factor authentication is bypassed making it easier to manage your account programmatically. This also means that a PAT is incredibly sensitive and extra care should be taken to protect it.

Creating a PAT

You create a PAT by calling the API. When doing so you will need to use basic authentication, and you may also need to transmit an OTP token.

Tip: Temporarily turn two-factor authentication off prior to generating a PAT. When you have a PAT, turn it back on again.

from uphold import Uphold
api = Uphold()
api.auth_basic( <username>, <password> )
api.otp( <code> )
pat = api.create_pat('This is a test auth token')
print "PAT: " + pat

Code Sample

from uphold import Uphold
api = Uphold()
api.auth_pat( <PAT> )
me = api.get_me()

Interacting with the Uphold Sandbox

The Uphold Sandbox is a test environment for developers to build and test their apps. The Sandbox environment uses fake money, but is otherwise an exact copy of our production system.

from uphold import Uphold
api = Uphold(True)

Conducting a Transaction

Transactions are conducted in two steps. First you prepare a transaction. This retrieves a quote for the transaction which will be honored for 30 seconds. This is a perfect way of generating a transaction preview for your user if you need to. Second is to execute a prepared transaction.

Example: Sending a Transaction

Below is an example of how one would send 1 BTC to someone using Uphold:

card_id = 'adc869d8-xxxx-xxxx-xxxx-72718f0a2be0'
from uphold import Uphold
api = Uphold()
api.auth(<username>, <password>)
txn_id = api.prepare_txn(card_id, 'luke@skywalker.net', 1, 'BTC')
api.execute_txn(card_id, txn_id)

A couple of notes about the sample above:

For a complete reference to the Uphold API, including examples in Python, please consult the Uphold API documentation.

Resources

Example Apps in Python

License

This software is licensed under the MIT License.