Skip to main content

Client for the Bridge open banking API aggregator

Project description

bridgeapi

PyPI - Version PyPI - Python Version


bridgeapi is a client for the Bridge open banking API aggregator (API documentation).

Requirements

Python 3.10+

Installation

pip install bridgeapi

Example

from bridgeapi import AppClient, UserClient

app_client = AppClient("CLIENT_ID", "CLIENT_SECRET")
app_client.list_banks()
app_client.list_users()
app_client.create_user("john@doe.com", "password")
...

user_client = UserClient("CLIENT_ID", "CLIENT_SECRET", "john@doe.com", "password")
user_client.list_items()
user_client.connect_item()
user_client.list_accounts()
user_client.list_transactions()
...

API endpoints are split between two clients:

  • AppClient handles all application-scoped endpoints, that don't depend on a user being authenticated. It only needs (client_id, client_secret) credentials to communicate with the API.
  • UserClient handles user-scoped endpoints, those that are specific to a user and require an access token and the Authorization header to communicate with the API. It needs (user_email, user_password) credentials, in addition to the same client credentials as AppClient.

All API client methods return a Pydantic model mapping exactly the schema of the API response. The raw response object can be accessed with the .response property:

result = app_client.list_banks()

result # PaginatedResult[Bank]
result.response  # <Response [200]>
result.response.json()  # JSON-parsed raw response body

Paginated results

API endpoints that return a list of results are paginated, i.e. they don't return the complete list of objects in one result but in chunks (called pages). When calling a list API endpoint, the first page of results is returned. Existence of more pages can be checked with .has_more(). Subsequent pages can be retrieved by calling .next_page():

from bridgeapi import AppClient

app_client = AppClient("CLIENT_ID", "CLIENT_SECRET")
banks = app_client.list_banks(limit=2)
print(banks.resources)  # List of 2 Bank instances

print(banks.has_more())  # True
banks = banks.next_page()
print(banks.resources)  # List of 2 other Bank instances

The entire list of objects can be retrieved by calling .fetch_all() on the first page returned by the API. Attempting to call it on a subsequent page will result in an error. Beware of potentially large collections, you may exceed API or memory limits, or wait for a long time. You may also want to increase the limit parameter.

from bridgeapi import AppClient

app_client = AppClient("CLIENT_ID", "CLIENT_SECRET")
banks = app_client.list_banks(limit=100)
print(banks.fetch_all())  # List of all banks

banks.next_page().fetch_all()  # PaginationError

User authentication management

The simplest usage of UserClient is to it handle all the authorization lifecyle. It will automatically obtain an access token and renew it when it expires (after 2 hours):

user_client = UserClient("CLIENT_ID", "CLIENT_SECRET", "john@doe.com", "password")
print(user_client.list_items())  # OK

# 2+ hours later
print(user_client.list_items())  # OK

If you wish to manage the user authorization lifecycle yourself, pass auto_renew=False at creation. You will need to call .renew_auth() manually:

user_client = UserClient(
    "CLIENT_ID", "CLIENT_SECRET", "john@doe.com", "password", auto_renew=False
)
print(user_client.is_authenticated())  # False
user_client.list_items()  # UserAuthenticationError

user_client.renew_auth()
print(user_client.is_authenticated())  # True
print(user_client.list_items())  # OK

# 2+ hours later
print(user_client.is_authenticated())  # False
user_client.renew_auth()
print(user_client.is_authenticated())  # True

Additionally, if you are managing user tokens externally and persisting them to external storage, you can provide them at creation as well:

user_client = UserClient(
    "CLIENT_ID",
    "CLIENT_SECRET",
    "john@doe.com",
    "password",
    user_uuid="uuid",
    access_token="token",
    expires_at=datetime,  # "yyyy-mm-dd HH:MM:SS"
    auto_renew=False,
)
print(user_client.is_authenticated())  # True
user_client.list_items()  # OK

# Generate and store new authorization info
auth_info = user_client.renew_auth()
store_user_auth_to_db(
    user_email=auth_info.user.email,
    user_uuid=auth_info.user.uuid,
    access_token=auth_info.access_token,
    expires_at=auth_info.expires_at,
)

License

bridgeapi is distributed under the terms of the MIT license.

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

bridgeapi-1.1.0.tar.gz (42.9 kB view details)

Uploaded Source

Built Distribution

bridgeapi-1.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file bridgeapi-1.1.0.tar.gz.

File metadata

  • Download URL: bridgeapi-1.1.0.tar.gz
  • Upload date:
  • Size: 42.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for bridgeapi-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ecbde0328886e206e9e0572f754247ac1255b2a335558a13e12f8652cf13f520
MD5 6a56c0bd711b1729f22f6ffb70a91fa7
BLAKE2b-256 0cf6f636e4763fecb46d67fa140acb8b51e897626a83b1098e9a2814ace9e7e2

See more details on using hashes here.

File details

Details for the file bridgeapi-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: bridgeapi-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for bridgeapi-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29c8382b3d283db55198e42ad9bd93945470d515c0dab111cfc465cc97494aab
MD5 dc1400a5c5cf64dbcd4325a0ed7f0545
BLAKE2b-256 0787169559996b298fc853e18f4f12f379d83b13a0223a91fdc9db1c3c300834

See more details on using hashes here.

Supported by

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