Skip to main content

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 or cbrf.asyncio.api methods:

>>> import cbrf
>>> from cbrf.const import CurrencyCodes

>>> 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=CurrencyCodes.USD)
<Element 'ValCurs' at 0x1107017c8>

>>> import asyncio

>>> asyncio.run(cbrf.asyncio.get_currencies_info())
<Element 'Valuta' at 0x102492ca0>

>>> asyncio.run(cbrf.asyncio.get_daily_rates())
<Element 'ValCurs' at 0x104c36c00>

>>> asyncio.run(cbrf.asyncio.get_dynamic_rates(date_req1=date_1, date_req2=date_2, currency_id=CurrencyCodes.USD))
<Element 'ValCurs' at 0x1026a4860>

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'

>>> import asyncio
>>> from cbrf.asyncio import CurrenciesInfo

>>> c_info = asyncio.run(CurrenciesInfo().create())
>>> 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')

>>> import asyncio
>>> from cbrf.asyncio import DailyCurrenciesRates

>>> daily = asyncio.run(DailyCurrenciesRates().create())
>>> 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')

>>> import asyncio
>>> from cbrf.asyncio import DynamicCurrenciesRates

>>> date_1 = datetime(2001, 3, 2)
... date_2 = datetime(2001, 3, 14)
... id_code = 'R01235'
>>> dynamic_rates = asyncio.run(DynamicCurrenciesRates(date_1, date_2, id_code).create())
>>> 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.

Release files for cbrf 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for cbrf 1.0.0
File Interpreter ABI Platform
cbrf-1.0.0-py3-none-any.whl Python 3 none any Details

Release files / cbrf-1.0.0-py3-none-any.whl

Download URL cbrf-1.0.0-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5620a1a7cd11ed581b29ec69c0f90ef004d8c40c4ee6b28d67e14ac99632ad81
BLAKE2b-256 checksum
How to use checksums
ad1672ce49999f8f38cf970290ac6c3cfdd34895884f9a4c74301093d1f98398
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

0.5.0

2 release files

0.4.7

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page