Skip to main content

Wrapper for The Central Bank of the Russian Federation site API

Project description

cbrf

Wrapper for The Central Bank of the Russian Federation site API

Build Status PyPI version

Site and API of The Central Bank of the Russian Federation.

Installation

Stable version:

    pip install cbrf

Dev version:

    git clone https://github.com/Egregors/cbrf.git
    cd cbrf
    pip install -e .

Settings

For using with your own hostname set environment variables, for example

export CBRF_URL_SCHEME=https
export CBRF_URL_HOST=www.my-own-cbr.ru

How to use

API

To get raw XML answers you should use cbrf.api methods:

>>> import cbrf

>>> cbrf.get_currencies_info()
<Element 'Valuta' at 0x10b91f688>

>>> cbrf.get_daily_rates()
<Element 'ValCurs' at 0x10b82b9a8>

>>> date_1 = datetime(2001, 3, 2)
>>> date_2 = datetime(2001, 3, 14)
>>> get_dynamic_rates(date_req1=date_1, date_req2=date_2, currency_id='R01235')
<Element 'ValCurs' at 0x1107017c8>

Models

You can use base models for work with API (see examples in the tests).

CurrenciesInfo

>>> from cbrf.models import CurrenciesInfo

>>> c_info = CurrenciesInfo()
>>> c_info.get_by_id("R01305").name
'Ирландский фунт'
>>> c_info.get_by_id("R01305").eng_name
'Irish Pound'

DailyCurrenciesRates

>>> from cbrf.models import DailyCurrenciesRates

>>> daily = DailyCurrenciesRates()
>>> daily.date
datetime.datetime(2017, 3, 11, 0, 0)
>>> daily.get_by_id('R01035').name
'Фунт стерлингов Соединенного королевства'
>>> daily.get_by_id('R01035').value
Decimal('72.0143')

DynamicCurrenciesRates

>>> from cbrf.models import DynamicCurrenciesRates

>>> date_1 = datetime(2001, 3, 2)
... date_2 = datetime(2001, 3, 14)
... id_code = 'R01235'
>>> dynamic_rates = DynamicCurrenciesRates(date_1, date_2, id_code)
>>> dynamic_rates.get_by_date(datetime(2001, 3, 8)).value
Decimal('28.6200')

Also, you can show DEBUG info, by setting logger level to DEBUG in your code:

import logging

logging.basicConfig(level=logging.DEBUG)

Linting & Tests

To run lint & tests:

make lint
make tests

You should install pytest first

Contributing

Bug reports, bug fixes, and new features are always welcome. Please open issues, and submit pull requests for any new code.

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

cbrf-0.5.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

cbrf-0.5.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file cbrf-0.5.0.tar.gz.

File metadata

  • Download URL: cbrf-0.5.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for cbrf-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fe413c324873dab7bf8bc590679edffae4b5db811461c7b327c1e88a4148da45
MD5 e351a5fc10549fc3cb0aaa6676684533
BLAKE2b-256 453be2243e344a52b98ccaa5413b3cc7d70efe56c7b5a856a0e16851f5b89cbb

See more details on using hashes here.

File details

Details for the file cbrf-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: cbrf-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for cbrf-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9dca06d782d742b180469a74a3a85810a88688dd5e2b4d46fc24917ff6ce01eb
MD5 f832a0fd770782ce811cac3f8c9a60bc
BLAKE2b-256 aa80aeae31cb2417f073ff82964da9f09fc6f1f549c3886accb8442ef2437534

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