bunq Python SDK
Project description
bunq Python SDK
Introduction
Hi developers!
Welcome to the bunq Python SDK! 👨💻
We're very happy to introduce yet another unique product: complete banking SDKs! Now you can build even bigger and better apps and integrate them with your bank of the free! 🌈
Before you dive into this brand new SDK, please consider:
- Learning how bunq works and what objects you will work with by reading the intro to our API 🤓
- Checking out our developer portal 🙌
- Grabbing your Production API key from our developer portal or the bunq app 🗝
- Generating a Sandbox API key using our developer portal or Tinker 🗝
- Visiting our forum where you can share your creations, questions and experience 🎤
Give us your feedback, create pull requests, build your very own bunq apps and most importantly: have fun! 💪
This SDK is in beta. We cannot guarantee constant availability or stability. Thanks to your feedback we will make improvements on it.
Installation
pip install bunq_sdk --upgrade
Usage
Creating an API context
In order to start making calls with the bunq API, you must first register your API key and device, and create a session. In the SDKs, we group these actions and call it "creating an API context". The context can be created by using the following code snippet:
apiContext = ApiContext.create(ENVIRONMENT_TYPE, API_KEY, DEVICE_DESCRIPTION)
apiContext.save(API_CONTEXT_FILE_PATH)
Please note: initialising your application is a heavy task and it is recommended to do it only once per device.
apiContext = ApiContext.restore(self.API_CONTEXT_FILE_PATH)
BunqContext.loadApiContext(apiContext)
After saving the context, you can restore it at any time:
Example
PSD2
It is possible to create an ApiContext as PSD2 Service Provider. Although this might seem a complex task, we wrote some helper implementations to get you started. You need to create a certificate and private key to get you started. Our sandbox environment currently accepts all certificates, if these criteria are met:
- Up to 64 characters
- PISP and/or AISP used in the end.
Make sure you have your unique eIDAS certificate number and certificates ready when you want to perform these tasks on our production environment.
Creating a PSD2 context is very easy:
apiContext = ApiContext.create_for_psd2(ENVIRONMENT_TYPE, CERTIFICATE, PRIVATE_KEY, CERTIFICATE_CHAIN, DEVICE_DESCRIPTION)
Safety considerations
The file storing the context details (i.e. bunq.conf
) is a key to your account. Anyone having
access to it is able to perform any Public API actions with your account. Therefore, we recommend
choosing a truly safe place to store it.
Making API calls
There is a class for each endpoint. Each class has functions for each supported action. These
actions can be create
, get
, update
, delete
and list
.
Sometimes API calls have dependencies, for instance MonetaryAccount
. Making changes to a monetary
account always also needs a reference to a User
. These dependencies are required as arguments when
performing API calls. Take a look at doc.bunq.com for the full
documentation.
Creating objects
Creating objects through the API requires an ApiContext
, a requestMap
and identifiers of all
dependencies (such as User ID required for accessing a Monetary Account). Optionally, custom headers
can be passed to requests.
payment_id = Payment.create(
amount=Amount(amount_string, self._CURRENCY_EURL),
counterparty_alias=Pointer(self._POINTER_TYPE_EMAIL, recipient),
description=description
)
Example
Reading objects
Reading objects through the API requires an ApiContext
, identifiers of all dependencies (such as
User ID required for accessing a Monetary Account), and the identifier of the object to read (ID or
UUID) Optionally, custom headers can be passed to requests.
This type of calls always returns a model.
monetary_account = generated.MonetaryAccountBank.get(
_MONETARY_ACCOUNT_ITEM_ID
)
Example
Updating objects
Updating objects through the API goes the same way as creating objects, except that also the object to update identifier (ID or UUID) is needed.
Card.update(
card_id=int(card_id),
monetary_account_current_id=int(account_id)
)
Example
Deleting objects
Deleting objects through the API requires an ApiContext
, identifiers of all dependencies (such as User ID required for
accessing a Monetary Account), and the identifier of the object to delete (ID or UUID) Optionally, custom headers can be
passed to requests.
Session.delete(self._SESSION_ID)
Example
Listing objects
Listing objects through the API requires an ApiContext
and identifiers of all dependencies (such as User ID required
for accessing a Monetary Account). Optionally, custom headers can be passed to requests.
users = User.list(api_context)
Example
Running Samples
To get an indication on how the SDK works you can use the python tinker which is located at https://github.com/bunq/tinker_python
Running Tests
Information regarding the test cases can be found in the README.md located in test.
Exceptions
The SDK can raise multiple exceptions. For an overview of these exceptions please take a look at EXCEPTIONS.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file bunq_sdk-1.14.18.tar.gz
.
File metadata
- Download URL: bunq_sdk-1.14.18.tar.gz
- Upload date:
- Size: 150.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbda6753a24ca4c6dd21548cbf07be021ffef75847596c75508a79b6d12aa4db |
|
MD5 | e43fe76c79f8529c80ec904a2aaf7c49 |
|
BLAKE2b-256 | 0922b3fd96bce9274e264348ab12462455fd16e340e2fb269660ba9718a1e038 |