A simple python wrapper around saltedge api with some utilities.
Project description
Saltedge python sdk
A simple python wrapper around saltedge api with some utilities.
Features
- Automatic page handling through generators
- Modular design
- Dynamic payload with typing support with TypedDict
Quickstart
Installation
pip install saltedge
Partner API overview (AISP)
https://docs.saltedge.com/partners/v1/#quick_start
import datetime as dt
from saltedge.api.accounts import AccountDTO
from saltedge.api.connections import ConnectionDTO
from saltedge.api.lead.leads import CreateLeadDTO
from saltedge.api.lead.sessions import (
LeadSessionDTO,
ConsentDTO,
ALL_CONSENTS,
AttemptDTO,
)
from saltedge.api.transactions import TransactionDTO
from saltedge.http import SaltedgeHttpClient
from saltedge.services import PartnersAccountService
# your saltedge credentials
app_id = "<your app id>"
app_secret = "<your app secret"
private_key = "-----BEGIN PRIVATE KEY-----\n...\n...\n-----END PRIVATE KEY-----".encode(
"utf-8"
)
client = SaltedgeHttpClient(app_id, app_secret, private_key)
partner:PartnersAccountService = PartnersAccountService(client)
# Create a lead
resp = partner.leads.create(payload=CreateLeadDTO(email="foo@example.com"))
print(resp)
# {'email': 'foo@example.com', 'customer_id': '123456.....'}
customer_id = resp["customer_id"]
# Create a Lead session
resp = partner.lead_session.create(
payload=LeadSessionDTO(
attempt=AttemptDTO(
return_to="https://localhost",
),
country_code="IT",
# ... many other options here. see docs: https://docs.saltedge.com/partners/v1/#lead_sessions-create
customer_id=customer_id,
consent=ConsentDTO(
scopes=ALL_CONSENTS,
from_date=(dt.date.today() - dt.timedelta(days=365)).strftime(
"%Y-%m-%d"
),
),
)
)
print(resp)
# {'expires_at': '2024-04-12T07:37:14Z', 'redirect_url': 'https://www.saltedge.com/dashboard/connect?token=123'}
# After visiting connect_link and connecting with your bank,
# you will be able to fetch data
# List connection
connection: ConnectionDTO
for connection in partner.connections.list(customer_id):
print(connection)
# Show details
connection = list(partner.connections.list(customer_id))[0]
print(partner.connections.show(connection["id"]))
# {'id': '123', 'secret': '123', 'provider_id': '123', 'provider_code': 'fake_demobank_xf', 'provider_name': 'Fake Demo Bank', 'customer_id': '123', 'status': 'active', 'categorization': '...'}
# List transactions
transaction: TransactionDTO
for transaction in partner.transactions.list(connection_id=connection["id"]):
print(transaction)
# {'id': '123', 'account_id': '123', 'duplicated': False, 'mode': 'normal', 'status': 'posted', 'made_on': '2024-03-01', 'amount': -64.0, 'currency_code': 'USD', 'description': 'ADOBE CREATIVE Debit IRELAND ON 28 FEB BDC', 'category': 'electronics_and_software', 'extra': {'merchant_id': '3847a91cad0519323b364fa6e83590110657a7c89f4775eaec89169f82b197ae', 'account_balance_snapshot': 314.58, 'categorization_confidence': 1}, 'created_at': '2024-04-12T07:42:10Z', 'updated_at': '2024-04-12T07:42:10Z'}
# List accounts
account: AccountDTO
for account in partner.accounts.list(connection["id"]):
print(account)
# {'id': '123', 'connection_id': '123', 'name': 'Current Account', 'nature': 'account', 'balance': 314.58, 'currency_code': 'USD', 'extra': {'iban': 'DE1234567890987654321123', 'swift': 'ABCDEFGH', 'status': 'active', 'sort_code': '65-43-21', 'client_name': 'John Smith', 'account_name': 'Current Account', 'account_number': '123456', 'available_amount': 314.58, 'transactions_count': {'posted': 38, 'pending': 0}, 'last_posted_transaction_id': '1252994279446415881'}, 'created_at': '2024-04-12T07:42:08Z', 'updated_at': '2024-04-12T07:42:14Z'}
How to contribute
Dependencies
- python 3.11+
- poetry
Dev quickstart
git clone git@github.com:besil/saltedge.git
cd saltedge
poetry install
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
saltedge-0.1.3.tar.gz
(15.5 kB
view details)
Built Distribution
saltedge-0.1.3-py3-none-any.whl
(18.6 kB
view details)
File details
Details for the file saltedge-0.1.3.tar.gz
.
File metadata
- Download URL: saltedge-0.1.3.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26c1434350cf46d9aa2a45de90892b6a538706f71d34d89a6bb8170e68636692 |
|
MD5 | 9005a35f05c1a939b1bdd753e762bd7e |
|
BLAKE2b-256 | 4e02c2d494eb1da1da6bd66670e4f08da3e20f503bfc83162ccd9427f083d2dd |
File details
Details for the file saltedge-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: saltedge-0.1.3-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58423c65df0e91ece5fa2154f33c7baab7d328620ca3e4e95c00700e12ca964a |
|
MD5 | 829fa7e9d8a9aea16eb40f0b38ecdc2e |
|
BLAKE2b-256 | 1c2936882d562f9798938828b2498684e25bd7a5165679dbf210b32fa6f56283 |