Skip to main content

Python client for official Central Bank of Azerbaijan currency rates.

Project description

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

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

cbar_currency_rates-2.0.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cbar_currency_rates-2.0.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file cbar_currency_rates-2.0.0.tar.gz.

File metadata

  • Download URL: cbar_currency_rates-2.0.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for cbar_currency_rates-2.0.0.tar.gz
Algorithm Hash digest
SHA256 daa16c642ed04764c44c29897010ec085d0d5fc373c7976f53b6aed757451303
MD5 e14370cf7ce3fbdd64c25ef3d0b73403
BLAKE2b-256 0c115542d30eba193739ea9d531b8807ac26f35e213976fa07597fc1880077a5

See more details on using hashes here.

File details

Details for the file cbar_currency_rates-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cbar_currency_rates-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a50b3a1219fc7e8a1378491fa280ace228f2fbabf409835433c53e9442adba1
MD5 49a757c3a98329b659391f71ef521e41
BLAKE2b-256 702c883dfd912861b7258a68fe5b8b61737ba6ec4434a3b4537e50362e69fed3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page