Skip to main content

CircleCI

coinbase-commerce-python

Coinbase Commerce Python

Table of contents

Python Version

Python 2.7+ and 3.4+ are supported and tested.

Third Party Libraries and Dependencies

The following libraries will be installed when you install the client library:

Documentation

For more details visit Coinbase API docs.

To start using library, you need to register on Commerce SignUp. And get your API_KEY from user settings.

Next create a Client object for interacting with the API:

from coinbase_commerce.client import Client

API_KEY = "API KEY"
client = Client(api_key=API_KEY)

Client contains links to an every Python Class representations of the API resources Checkout, Charge, Event

You can call list, list_paging_iter, create, retrieve, modify methods from an API resource classes

client.charge.create
client.checkout.list_paging_iter 
client.event.list
client.charge.retrieve
client.checkout.modify

as well as save, delete, refresh methods from API resource class instances.

checkout = client.checkout.retrieve(<id>)
checkout.refresh()
checkout.save()
checkout.delete()

Each API method returns an APIObject (a subclass of dict) representing the JSON response from the API, all of the models are dumpable with JSON.
Also when the response data is parsed into Python objects, the appropriate APIObject subclasses will be used automatically. All subclasses of APIResource class support refresh method. This will update their attributes and all nested data by making a fresh GET request to the relevant API endpoint.

Client support Common API Errors and Warnings handling. All errors occuring during interaction with the API will be raised as exceptions.

Error Status Code
APIError *
InvalidRequestError 400
ParamRequiredError 400
ValidationError 400
AuthenticationError 401
ResourceNotFoundError 404
RateLimitExceededError 429
InternalServerError 500
ServiceUnavailableError 503

Installation

Install with pip:

pip install --upgrade coinbase-commerce

or with easy_install:

easy_install --upgrade coinbase-commerce

Usage

from coinbase_commerce.client import Client

client = Client(api_key=API_KEY)

Checkouts

Checkouts API docs

Retrieve

checkout = client.checkout.retrieve(<checkout_id>)

Create

checkout_info = {
    "name": 'The Sovereign Individual',
    "description": 'Mastering the Transition to the Information Age',
    "pricing_type": 'fixed_price',
    "local_price": {
        "amount": "100.00",
        "currency": "USD"
    },
    "requested_info": ["name", "email"]
}
checkout = client.checkout.create(**checkout_info)

# or

checkout = client.checkout.create(name='The Sovereign Individual',
                                  description='Mastering the Transition to the Information Age',
                                  pricing_type='fixed_price',
                                  local_price={
                                          "amount": "100.00",
                                          "currency": "USD"
                                          },
                                  requested_info=["name", "email"])                            

Update

checkout = client.checkout.retrieve(<checkout_id>)
checkout.name = 'new name'
checkout.save()

# or

checkout = client.checkout.modify('<checkout_id>',
                                  name='new name')

Delete

checkout.delete()

List

checkouts = client.checkout.list()

Paging list iterations

for checkout in client.checkout.list_paging_iter():
    print("{!r}".format(checkout))

Charges

Charges API docs

Retrieve

charge = client.charge.retrieve(<charge_id>)

Create

charge_info = {
    "name": "The Sovereign Individual",
    "description": "Mastering the Transition to the Information Age",
    "local_price": {
        "amount": "100.00",
        "currency": "USD"
    },
    "pricing_type": "fixed_price"

}
charge = client.charge.create(**charge_info)

# or

charge = client.charge.create(name='The Sovereign Individual',
                              description='Mastering the Transition to the Information Age',
                              pricing_type='fixed_price',
                              local_price={
                                  "amount": "100.00",
                                  "currency": "USD"
                              })

List

checkouts = client.charge.list()

Paging list iterations

for charge in client.charge.list_paging_iter():
    print("{!r}".format(charge))

Events

Events API Docs

Retrieve

event = client.event.retrieve(<event_id>)

List

events = client.event.list()

Paging list iterations

for event in client.event.list_paging_iter():
    print("{!r}".format(event))

Validating webhook signatures

You could verify webhook signatures using our library. To perform the verification you'll need to provide the event data, a webhook signature from request header, and the endpoint’s secret. In case of invalid request signature or request payload, you will receive appropriate error message.

WEBHOOK_SECRET = 'your_webhook_secret'

# using Flask
@app.route('/webhooks', methods=['POST'])
def webhooks():
    # event payload
    request_data = request.data.decode('utf-8')
    # webhook signature
    request_sig = request.headers.get('X-CC-Webhook-Signature', None)

    try:
        # signature verification and event object construction
        event = Webhook.construct_event(request_data, request_sig, WEBHOOK_SECRET)
    except (WebhookInvalidPayload, SignatureVerificationError) as e:
        return str(e), 400

    print("Received event: id={id}, type={type}".format(id=event.id, type=event.type))
    return 'success', 200

Testing and Contributing

Any and all contributions are welcome! The process is simple: fork this repo, make your changes, run the test suite, and submit a pull request. Tests are run via nosetest. To run the tests, clone the repository and then:

Install the requirements

pip install -r requirements.txt

Run the tests for your current version of Python

Use tox to run the test suite against multiple versions of Python. You can install tox with pip or easy_install:

pip install tox
easy_install tox

Tox requires the appropriate Python interpreters to run the tests in different environments. We recommend using pyenv for this. Once you've installed the appropriate interpreters, running the tests in every environment is simple:

tox

Metadata

Release files for coinbase-commerce 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coinbase-commerce 1.0.1
File Size Uploaded Provenance Actions
coinbase_commerce-1.0.1.tar.gz 37.2 kB Without provenance Details for coinbase_commerce-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for coinbase-commerce 1.0.1
File Interpreter ABI Platform Actions
coinbase_commerce-1.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for coinbase_commerce-1.0.1-py2.py3-none-any.whl

Total release size: 58.1 kB

Release files / coinbase_commerce-1.0.1.tar.gz

Download URL coinbase_commerce-1.0.1.tar.gz
Size 37.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5f6807655e9297210c1178dca62d1c1a997505368311c55c8ebe4f466344d966
BLAKE2b-256 checksum
How to use checksums
ac52c99505a81df698a8c7dd992038198af75f726c81f2f9a09f4cc141099039
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

Release files / coinbase_commerce-1.0.1-py2.py3-none-any.whl

Download URL coinbase_commerce-1.0.1-py2.py3-none-any.whl
Size 20.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2eee6981767873f2ab803a2d40ad497b08a2231bcf68de79ccec0314728370fe
BLAKE2b-256 checksum
How to use checksums
f93dc5d0c2ed3d226c0649d603b7d992c771957081d13e6d7aab6a98a845d712
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

Security for coinbase-commerce 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page