Skip to main content

Pocketsmith web/realtime client, for things the API does not provide

Project description

pocketsmith-web-client

A web-based client for Pocketsmith, which adds support for a few things missing from the API:

  • Searching transactions
  • Syncing institutions, including those requiring MFA!
  • Real-time events through Pusher (just like the web UI)

Installation

pip install pocketsmith-web-client

Usage

import asyncio
from pocketsmith_web import PocketsmithWebClient

pwc = PocketsmithWebClient(
    username='hambob',
    password='Myspace123',
    # If 2fa is enabled on the account — NOTE: this is the KEY, not a one-time code!
    totp_key='81r0dq0815u88qi2',
)

async def main():
    # Check login — NOTE: API methods requiring auth will automatically call this
    await pwc.login()

    # Search for some transactions and print them out
    async for transaction in pwc.search_transactions('Merchant, inc'):
        print(f'[{transaction["id"]:>8}] {transaction["date"]:%Y-%m-%d} ${transaction["amount"]:.2f}')

    # Sync some institutions
    # NOTE: these parameters can be scraped from the Account Summary page, 
    #       in URLs of the format: "/feeds/user_institutions/<uys_id>/refresh?item_ids%5B%5D=<item_id>
    await pwc.sync_institution(162303, 91821548)

asyncio.run(main())

If you have an institution requiring MFA info, the Pusher client can be used to provide this info when requested. It's up to you to figure out how to acquire the MFA info, though — whether it's from user input, a generated TOTP, a text message, email, etc.

import asyncio
import json
from pocketsmith_web import PocketsmithWebClient, PusherEvent

pwc = PocketsmithWebClient('hambob', 'Myspace123', totp_key='81r0dq0815u88qi2')


async def sync_my_mfa_bank():
    uys_id = 162303
    item_id = 91821548

    await pwc.sync_institution(uys_id, item_id)

    async with pwc.pusher() as pusher:
        # Wait for an MFA event for our bank
        await pusher.events.expect(
            PusherEvent.MfaChanged(pwc.pusher_channel),
            matches_uys_item(uys_id, item_id),
        )

        # Grab the MFA popup form details
        mfa_req = await pwc.get_mfa_form_info()

        # Ask the user for the MFA deets, please
        print(f'MFA deets required: {mfa_req["label"]}')
        token = input('Token: ')

        # Now shoot the token back to Pocketsmith
        await pwc.provide_feed_mfa(uys_id, item_id, token)


def matches_uys_item(uys_id, item_id):
    uys_id = str(uys_id)
    item_id = str(item_id)

    def does_event_match_uys_item(event: PusherEvent):
        if not isinstance(event.data, dict):
            return False

        event_uys_id = event.data.get('user_yodlee_site_id')

        event_items = event.data.get('new_mfa_items', ())
        if isinstance(event_items, str):
            try:
                event_items = json.loads(event_items)
            except (TypeError, ValueError):
                pass

        return uys_id == event_uys_id and item_id in event_items

    return does_event_match_uys_item


asyncio.run(sync_my_mfa_bank())

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

pocketsmith-web-client-0.1.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

pocketsmith_web_client-0.1.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file pocketsmith-web-client-0.1.1.tar.gz.

File metadata

  • Download URL: pocketsmith-web-client-0.1.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.2 CPython/3.8.5 Linux/5.4.0-52-generic

File hashes

Hashes for pocketsmith-web-client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 77e64748fb11cb9b135e3e77cb3e01ba2641f1e55fe5dd908784d79737a12c9e
MD5 92f7654fcb0d258fcf614464287d5538
BLAKE2b-256 faf754c6e66df32ad53792be578931c1ab3b16576df202f4264d94d707626c32

See more details on using hashes here.

File details

Details for the file pocketsmith_web_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pocketsmith_web_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b6dcd37547558b41776e5ae3734500123329d5b225cbddd6da6cd16be22eff41
MD5 632adec1a0473136b8f5a9b28797868d
BLAKE2b-256 2412aa5c916a6bbb9773996aba7b4dc0e5b98f25a3676e9c05656994d12fa4cd

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