Wrapper for The Central Bank of the Russian Federation site API
Project description
# cbrf
_Обертка для работы с API Центробанка_
_Wrapper for The Central Bank of the Russian Federation site API_
[](https://travis-ci.org/Egregors/cbrf)
[](https://badge.fury.io/py/cbrf)
**[RU]**
[Сайт](http://www.cbr.ru/) и [API](http://www.cbr.ru/scripts/Root.asp?PrtId=SXML) Центробанка.
## Установка
Стабильная версия:
```
pip install cbrf
```
Версия для разработчиков:
```
git clone https://github.com/Egregors/cbrf.git
cd cbrf
pip install -e .
```
## Как использовать
### API
Для получения чистого XML ответа можно использовать методы `cbrf.api`:
```
>>> 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>
```
### Модели данных
Кроме того, можно использовать модели, для работы с ответами API. (Смотри примеры в тестах)
`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')
```
### Тесты
Для запуска тестов:
```
pytest cbrf/tests.py
```
> Сперва нужно установить `pytest`
**[EN]**
[Site](http://www.cbr.ru/) and [API](http://www.cbr.ru/scripts/Root.asp?PrtId=SXML)
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 .
```
## 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
Also you can user 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')
```
### Tests
To run tests:
```
pytest cbrf/tests.py
```
> 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.
_Обертка для работы с API Центробанка_
_Wrapper for The Central Bank of the Russian Federation site API_
[](https://travis-ci.org/Egregors/cbrf)
[](https://badge.fury.io/py/cbrf)
**[RU]**
[Сайт](http://www.cbr.ru/) и [API](http://www.cbr.ru/scripts/Root.asp?PrtId=SXML) Центробанка.
## Установка
Стабильная версия:
```
pip install cbrf
```
Версия для разработчиков:
```
git clone https://github.com/Egregors/cbrf.git
cd cbrf
pip install -e .
```
## Как использовать
### API
Для получения чистого XML ответа можно использовать методы `cbrf.api`:
```
>>> 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>
```
### Модели данных
Кроме того, можно использовать модели, для работы с ответами API. (Смотри примеры в тестах)
`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')
```
### Тесты
Для запуска тестов:
```
pytest cbrf/tests.py
```
> Сперва нужно установить `pytest`
**[EN]**
[Site](http://www.cbr.ru/) and [API](http://www.cbr.ru/scripts/Root.asp?PrtId=SXML)
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 .
```
## 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
Also you can user 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')
```
### Tests
To run tests:
```
pytest cbrf/tests.py
```
> 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
Release history Release notifications | RSS feed
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.3.1.tar.gz
(6.0 kB
view details)
File details
Details for the file cbrf-0.3.1.tar.gz.
File metadata
- Download URL: cbrf-0.3.1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6791e7e7c21571e5db2b15c458929dd4fef20357fb8f353aa81cf4a3d47f1bd
|
|
| MD5 |
70946b027c64f1c80343cebe2862de13
|
|
| BLAKE2b-256 |
23c5594a4c2029d322cccc1a05634fd9f9aab4194a144f0af7f59a6208d8d414
|