Skip to main content

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:
- Checking out our new developer’s page [https://bunq.com/en/developer](https://bunq.com/en/developer) 🙌
- Grabbing your production API key from the bunq app or asking our support for a Sandbox API key 🗝
- Visiting [together.bunq.com](https://together.bunq.com) 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 = context.ApiContext(ENVIRONMENT_TYPE, API_KEY,
DEVICE_DESCRIPTION);
apiContext.save(API_CONTEXT_FILE_PATH);
```

#### Example
See [`api_context_save_example.py`](./examples/api_context_save_example.py)

The API context can then be saved with:

#### 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](https://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.


```
request_map = {
generated.Payment.FIELD_AMOUNT: object_.Amount(
_PAYMENT_AMOUNT,
_PAYMENT_CURRENCY
),
generated.Payment.FIELD_COUNTERPARTY_ALIAS: object_.Pointer(
_COUNTERPARTY_POINTER_TYPE,
_COUNTERPARTY_EMAIL
),
generated.Payment.FIELD_DESCRIPTION: _PAYMENT_DESCRIPTION,
}

payment_id = generated.Payment.create(
api_context,
request_map,
_USER_ITEM_ID,
_MONETARY_ACCOUNT_ITEM_ID
)
```

##### Example
See [`PaymentExample.py`](./examples/payment_example.py)

#### 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(
api_context,
_USER_ITEM_ID,
_MONETARY_ACCOUNT_ITEM_ID
)
```

##### Example
See [`MonetaryAccountExample.py`](./examples/monetary_account_example.py)

#### 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.

```
request_update_map = {
generated.RequestInquiry.FIELD_STATUS: _STATUS_REVOKED,
}
generated.RequestInquiry.update(
api_context,
request_update_map,
_USER_ITEM_ID,
_MONETARY_ACCOUNT_ITEM_ID,
request_id
).to_json()
```

##### Example
See [`RequestExample.py`](./examples/request_example.py)

#### 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.

```
generated.CustomerStatementExport.delete(apiContext, userId, monetaryAccountId, customerStatementId);
```

##### Example
See [`CustomerStatementExportExample.py`](./examples/customer_statement_export_example.py)

#### 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 = generated.User.list(api_context)
```

##### Example
See [`UserListExample.py`](./examples/user_list_example.py)

## Running Samples
In order to make the experience of getting into bunq Python SDK smoother, we
have bundled it with example use cases (located under `/examples`).

To run an example, please do the following:
1. In your IDE, open the example you are interested in and adjust the constants,
such as `_API_KEY` or `_USER_ID`, to hold your data.
2. In your terminal, go to the root of bunq SDK project:

```shell
$ cd /path/to/bunq/sdk/
```
3. In the terminal, run:

```shell
$ python3 run.py examples/<something_example.py>
```
Replace `<something_example.py>` with the name of the example you would like
to run. If you wish to run the example with python 2, also replace
`python3` with `python`.

In order for examples to run, you would need a valid context file (`bunq.conf`)
to be present in the bunq SDK project root directory. The file can either copied
from somewhere else (e.g. tests) or created by running the following command
in your bunq SDK project root directory:

```shell
$ python3 run.py examples/api_context_save_example.py
```

Please do not forget to set the `_API_KEY` constant in
`api_context_save_example.py` to your actual API key before running the sample!

## Running Tests

Information regarding the test cases can be found in the [README.md](./tests/README.md)
located in [test](/tests)

## Exceptions
The SDK can raise multiple exceptions. For an overview of these exceptions please
take a look at [EXCEPTIONS.md](./EXCEPTIONS.md)


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bunq_sdk-0.12.2.tar.gz (56.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bunq_sdk-0.12.2-py3-none-any.whl (66.5 kB view details)

Uploaded Python 3

File details

Details for the file bunq_sdk-0.12.2.tar.gz.

File metadata

  • Download URL: bunq_sdk-0.12.2.tar.gz
  • Upload date:
  • Size: 56.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bunq_sdk-0.12.2.tar.gz
Algorithm Hash digest
SHA256 07280af951afdc3a69e427d04616e86c437ccdee08d8c48fa3204141553d73c5
MD5 7b1aa223c83fe11b12c906c2a9614c45
BLAKE2b-256 164ad9b339f596cd0b6da07830e6ac184b19cdc39c5815f9392b332bd7b8eaa9

See more details on using hashes here.

File details

Details for the file bunq_sdk-0.12.2-py3-none-any.whl.

File metadata

File hashes

Hashes for bunq_sdk-0.12.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c9251ab498a854761bb5a67ad645982db699e4999d9026cb861e9484dee5d30b
MD5 45cacd98a2e6e232eea4a0893f70e020
BLAKE2b-256 c94ea135e846eb9e6fffa8fb4a6a3228e9e7de1e5bf977b8df0b22ad79234c7b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page