Skip to main content

CBAR Currency Rates

Python client for the official currency rates published by the Central Bank of the Republic of Azerbaijan.

CBAR publishes official AZN exchange-rate bulletins as dated XML files:

https://cbar.az/currencies/DD.MM.YYYY.xml

When a date is not provided, this package fetches the latest official bulletin for the current Baku date and falls back through recent dates if CBAR has not published a dated XML file yet.

Installation

pip install cbar-currency-rates

Quick Start

from cbar_currency_rates import CBARClient

cbar = CBARClient()

# Simple backwards-compatible shape: {"USD": 1.7, "EUR": 1.9362, ...}
rates = cbar.get_rates()
print(rates["USD"])

# Fetch selected currencies only
selected = cbar.get_rates(codes=["USD", "EUR", "TRY"])
print(selected)

Rich Rate Metadata

from cbar_currency_rates import CBARClient

cbar = CBARClient()
table = cbar.latest(codes=["USD", "JPY"])

usd = table.require("USD")
jpy = table.require("JPY")

print(table.date)          # Official bulletin date
print(table.source_url)    # CBAR XML URL
print(usd.value)           # Decimal("1.7000")
print(jpy.nominal_text)    # "100"
print(jpy.rate)            # AZN value for one JPY

CBAR lists some currencies by nominal amounts, such as 100 JPY or 100 RUB. CurrencyRate.value keeps CBAR's official value for the listed nominal, while CurrencyRate.rate normalizes it to one unit.

Historical Dates

from datetime import date
from cbar_currency_rates import CBARClient

cbar = CBARClient()
rates = cbar.get_rates(date=date(2024, 5, 27))
same_rates = cbar.get_rates(date="27.05.2024")

Accepted date inputs:

  • datetime.date
  • datetime.datetime
  • YYYY-MM-DD
  • DD.MM.YYYY
  • DD/MM/YYYY

Convert Amounts

from cbar_currency_rates import CBARClient

cbar = CBARClient()

azn = cbar.convert(100, "USD", "AZN")
eur = cbar.convert(100, "USD", "EUR")

convert() returns a Decimal and uses CBAR's official AZN cross-rates.

Bank Metals

Currency methods exclude bank metals by default. Enable them when needed:

from cbar_currency_rates import CBARClient

cbar = CBARClient()
table = cbar.latest(include_metals=True)

gold = table.require("XAU")
print(gold.value)

Compatibility

The old import style still works:

from cbar_currency_rates.rates import CBARRates

cbar = CBARRates()
print(cbar.get_rates())

Development

pip install -r requirements.txt
pip install pytest
pytest

Metadata

Release files for cbar-currency-rates 2.0.0

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

Source distribution (sdist)

Source distribution for cbar-currency-rates 2.0.0
File Size Uploaded
cbar_currency_rates-2.0.0.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cbar-currency-rates 2.0.0
File Interpreter ABI Platform
cbar_currency_rates-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / cbar_currency_rates-2.0.0.tar.gz

Download URL cbar_currency_rates-2.0.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
daa16c642ed04764c44c29897010ec085d0d5fc373c7976f53b6aed757451303
BLAKE2b-256 checksum
How to use checksums
0c115542d30eba193739ea9d531b8807ac26f35e213976fa07597fc1880077a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / cbar_currency_rates-2.0.0-py3-none-any.whl

Download URL cbar_currency_rates-2.0.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a50b3a1219fc7e8a1378491fa280ace228f2fbabf409835433c53e9442adba1
BLAKE2b-256 checksum
How to use checksums
702c883dfd912861b7258a68fe5b8b61737ba6ec4434a3b4537e50362e69fed3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

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