Skip to main content

Monobank.ua API implementation

Project description

python-monobank

GitHub-issues

python-monobank

Python client for Monobank API (https://api.monobank.ua/docs/)

Installation

pip install monobank

Usage

Personal api

  1. Request your token at https://api.monobank.ua/

  2. Use that token to initialize client:

  import monobank
  token = 'xxxxxxxxxxxxxxx'

  mono = monobank.Client(token)
  user_info = mono.get_client_info()
  print(user_info)

Methods

Get currencies

>>> mono.get_currency()
[
 {'currencyCodeA': 840,
  'currencyCodeB': 980,
  'date': 1561686005,
  'rateBuy': 25.911,
  'rateSell': 26.2357},
 {'currencyCodeA': 978,
  'currencyCodeB': 980,
  'date': 1561686005,
  'rateBuy': 29.111,
  'rateSell': 29.7513},
  ...

Get client info

>>> mono.get_client_info()
{
  'name': 'Dmitriy Dubilet'
  'accounts': [
    {
      'id': 'accidxxxxx'
      'balance': 100000000,
      'cashbackType': 'UAH',
      'creditLimit': 100000000,
      'currencyCode': 980,
      }
  ],
}

Get statements

>>> mono.get_statements('accidxxxxx', date(2019,1,1), date(2019,1,30))
[
  {
    'id': 'iZDPhf8v32Qass',
    'amount': -127603,
    'balance': 99872397,
    'cashbackAmount': 2552,
    'commissionRate': 0,
    'currencyCode': 978,
    'description': 'Smartass club',
    'hold': True,
    'mcc': 5411,
    'operationAmount': 4289,
    'time': 1561658263
  },
  ...
]

You can as well pass datetime objects

>>> mono.get_statements('accidxxxxx', datetime(2019,1,1,11,15), datetime(2019,1,2,11,15))

Create a Webhook

>>> mono.create_webhook('https://myserver.com/hookpath')

Corporatre API

Documentation is here - https://api.monobank.ua/docs/corporate.html

Corporate API have the same methods as Public API, but it does not have rate limitation, and it is a recomended way if you are handling data for commercial use (or just storing lot of personal data).

Getting access

1) Generate private key

openssl ecparam -genkey -name secp256k1 -rand /dev/urandom -out priv.key

This will output file priv.key

Warning: do not share it with anyone, do not store it in public git repositories

2) Generate public key

openssl ec -in priv.key  -pubout -out pub.key

This will output file pub.key

3) Request API access

Send an email to api@monobank.ua - describe your project, and attach pub.key (!!! NOT priv.key !!!)

Requesting permission from monobank user

Once your app got approved by Monobank team you can start using corporate API:

1) Create monobank user access request

private_key = '/path/to/your/priv.key'
request = monobank.access_request('ps', private_key)

If all fine you should recive the following:

print(request)
{'tokenRequestId': 'abcdefg_Wg', 'acceptUrl': 'https://mbnk.app/auth/abcdefg_Wg'}

You should save tokenRequestId to database, and then give user the link acceptUrl

Note: To be notified about user acceptance you can use web callback:

monobank.access_request('ps', private_key, callback_url='https://yourserver.com/callback/')

2) Check if user accepted

You can check if user accepted access request like this:

request_token = 'abcdefg_Wg'  # the token from access_request result
private_key = '/path/to/your/priv.key'

mono = monobank.CorporateClient(request_token, private_key)


mono.check()  # returns True if user accepted, False if not

3) Use methods

Once user accepts your access-request, you can start using all the methods same ways as Public API

mono.get_statements(....)

Handling Errors

If you use Personal API you may encounter "Too Many Requests" error. To properly catch it and retry - use monobank.TooManyRequests exception

try:
    mono.get_statements(....)
except monobank.TooManyRequests:
    time.sleep(1)
    # try again:
    mono.get_statements(....)

You can use ratelimiter library (like https://pypi.org/project/ratelimiter/ ) to download all transactions

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

monobank-0.4.3.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

monobank-0.4.3-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file monobank-0.4.3.tar.gz.

File metadata

  • Download URL: monobank-0.4.3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.16 CPython/3.6.6 Darwin/16.7.0

File hashes

Hashes for monobank-0.4.3.tar.gz
Algorithm Hash digest
SHA256 d056a585521c9f44a2e9103c8300b5fedb0d80521c531125e1b9a725cd3a07a1
MD5 2aed2b949673748a85bb03a5c5e8cebb
BLAKE2b-256 79d9e852a726a85147f08b41f74a292407eb6368a679065de02402320a3925d5

See more details on using hashes here.

Provenance

File details

Details for the file monobank-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: monobank-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.16 CPython/3.6.6 Darwin/16.7.0

File hashes

Hashes for monobank-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 68b917a23dc3dd7a52d48d61c447faa651905342823750d2bea6b9622a8a81c0
MD5 9bc1be67518c6262c074dca6f192b5fa
BLAKE2b-256 e8a174270f1ae7bd046f88211a962da385b025d2ad63e8ed4905e8566194b2a8

See more details on using hashes here.

Provenance

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