Skip to main content

An - dare I say it - awesome Python library that smartly wraps Monzo public API and allows you to use it directly in your Python project.

Project description

Build status Test coverage PyPI version Python versions License

An - dare I say it - awesome Python library that smartly wraps Monzo public API and allows you to use it directly in your Python project.

It creates a layer of abstraction and returns Python objects instead of just passing the received JSONs. It also deals with authentication and allows using either an access token or fully authenticate via OAuth 2 that’s a PITA to set up but is then automatically refreshed in the background. Yeah, you read it correctly - no more manual changing of the access token every couple of hours. High five!

Installation

>From PyPI:

$ pip install pymonzo

Authentication

Access token

If you want to just play around then you can simply get the access token taken from Monzo API Playground, either pass it explicitly to MonzoAPI() class or save it as an environment variable ($ export MONZO_ACCESS_TOKEN='...') and you’re good to go. Everything works as expected but the token is valid only for couple of hours.

OAuth 2

The second authentication option is to go through OAuth 2, which doesn’t sound bad (everyone is using it!) but from my experience is a PITA when setting up for server side applications. So.

Some technical background: Monzo currently only allows OAuth 2 ‘authorization code’ grant type and automatic token refreshing is only allowed for ‘confidential’ clients.

First, you need to create said client here. Name and logo don’t really matter but you need to set the redirect URL to this repo (https://github.com/pawelad/pymonzo) and set it to be confidential.

Got it? Cool. You now have required ‘Client ID’ and ‘Client secret’ and only need the auth code. You get it by creating a link with your client ID:

https://auth.getmondo.co.uk/?client_id=$ClientID&response_type=code&redirect_uri=https://github.com/pawelad/pymonzo

You then go to the link and authorise the app. You should get an email with a link back to the GitHub repo and the authorization code, something like:

https://github.com/pawelad/pymonzo?code=$AuthCode

You now have all three needed values - client ID, client secret and the auth code. As with the access token, you can either pass them directly to MonzoAPI() class or save them as environment variables:

$ export MONZO_CLIENT_ID='...'
$ export MONZO_CLIENT_SECRET='...'
$ export MONZO_AUTH_CODE='...'

That’s it! The token is then saved on the disk (~/.pymonzo) and is automatically refreshed when needed, so all this (should) be one time only.

Roadmap

The library currently doesn’t implement feed items, webhooks and attachments endpoints, mostly because they were’t essential to my current needs (monz) and they could be completely different in the future - per Monzo docs: > The Monzo API is under active development. Breaking changes should be expected.

That said, if you need one of those endpoints feel free to either create a PR that add them or let me know that you want them and I’ll see what I can do : -)

API

There’s no proper documentation as of now, but the code is commented and should be pretty straightforward to use.

But feel free to ask me via email or GitHub issues if anything is unclear.

Tests

Package was tested with the help of py.test and tox on Python 2.7, 3.4, 3.5 and 3.6 (see tox.ini).

Code coverage is available at Coveralls.

To run tests yourself you need to set environment variables with access token before running tox inside the repository:

$ pip install -r requirements/dev.txt
$ export MONZO_ACCESS_TOKEN='...'
$ tox

Contributions

Package source code is available at GitHub.

Feel free to use, ask, fork, star, report bugs, fix them, suggest enhancements, add functionality and point out any mistakes.

Authors

Developed and maintained by Paweł Adamczak.

Released under 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

pymonzo-0.2.2.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

pymonzo-0.2.2-py2.py3-none-any.whl (14.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pymonzo-0.2.2.tar.gz.

File metadata

  • Download URL: pymonzo-0.2.2.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pymonzo-0.2.2.tar.gz
Algorithm Hash digest
SHA256 e86284c9c89ef12778c193e0f7ca03362dcf58c8a404dc89fb9764aacd0e2090
MD5 7c65e6df493248e1511e3e1153ff3e76
BLAKE2b-256 a3ee925fcc53043a1ed2c9b4f39e77f4e3f1253eb758c507d5ce764715b3c8dc

See more details on using hashes here.

File details

Details for the file pymonzo-0.2.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pymonzo-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3a90abdf95f97dc6930476349a05044ee988aafa477f3b67d518ea292b821d82
MD5 73d4f3a69910236e1e0fec3caf2ac2ac
BLAKE2b-256 d55bfc05ef7b497ed7841014e3bcfaf80176bac24dc53cd5a0ae40cf294bb2da

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