Skip to main content

A Python wrapper over NBG official exchange rate of LARI against foreign currencies

Project description

PyPI version

NBG Currency Service

NBGCurrencyService is a Python library designed to fetch and normalize currency exchange rates from the National Bank of Georgia (NBG) API. It provides both synchronous and asynchronous functionality, making it suitable for various applications.


Features

  • Fetch exchange rates for the current date or a specific date.
  • Retrieve rates for all currencies or a specific currency.
  • Supports both synchronous and asynchronous modes.
  • Easy-to-use interface with well-structured data models.

Installation

Install the package

pip install nbg-currency-service

For Asynchronous Support

To enable async mode, install with the optional aiohttp dependency:

pip install nbg-currency-service[async]

Usage

Synchronous Mode

Fetch rates for all currencies on the current date:

from nbg_currency_service import NBGCurrencyService

service = NBGCurrencyService()
data = service.fetch()
print(data)

Fetch rates for a specific currency on a specific date:

from datetime import datetime
from nbg_currency_service import NBGCurrencyService, CurrencyEnum

service = NBGCurrencyService(
    date=datetime(2023, 12, 25), currency=CurrencyEnum.USD
)
data = service.fetch()
print(data)

Asynchronous Mode

Fetch rates asynchronously for a specific currency:

import asyncio
from nbg_currency_service import NBGCurrencyService, CurrencyEnum

async def main():
    service = NBGCurrencyService(currency=CurrencyEnum.EUR, mode="ASYNC")
    data = await service.afetch()
    print(data)

asyncio.run(main())

Data Models

CurrencyDataResponse

This is the structured response returned by the service after fetching and normalizing data.

Field Type Description
date datetime The date for the rates
currencies List[CurrencyRateItem] List of currency rate items

CurrencyRateItem

Represents details of a single currency rate.

Field Type Description
code str ISO code of the currency
quantity int Quantity for the rate
rateFormated str Formatted rate string
diffFormated str Formatted difference string
rate float Exchange rate
name str Currency name
diff float Rate difference
date datetime Date of the rate
validFromDate datetime Start date for the rate

Configuration

Supported Currencies

The CurrencyEnum includes all ISO codes of supported currencies, such as:

  • CurrencyEnum.USD
  • CurrencyEnum.EUR
  • CurrencyEnum.GBP

Modes

  • SYNC (default): Use synchronous requests with the fetch method.
  • ASYNC: Use asynchronous requests with the afetch method.

Example Output

Fetching exchange rates for USD:

from nbg_currency_service import NBGCurrencyService, CurrencyEnum

service = NBGCurrencyService(currency=CurrencyEnum.USD)
data = service.fetch()

print(data)

Sample output:

CurrencyDataResponse(
    date=datetime.datetime(2025, 1, 7, 0, 0),
    currencies=[
        CurrencyRateItem(
            code='USD',
            quantity=1,
            rateFormated='3.20',
            diffFormated='+0.02',
            rate=3.2,
            name='US Dollar',
            diff=0.02,
            date=datetime.datetime(2025, 1, 7, 0, 0),
            validFromDate=datetime.datetime(2025, 1, 6, 0, 0)
        )
    ]
)

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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

nbg_currencies_api-0.1.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

nbg_currencies_api-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file nbg_currencies_api-0.1.1.tar.gz.

File metadata

  • Download URL: nbg_currencies_api-0.1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for nbg_currencies_api-0.1.1.tar.gz
Algorithm Hash digest
SHA256 684c213674687190f7ef68957420a2eb9c16bd7baadb22f4b3d74a9b4a3de688
MD5 ceaaccb1a361f0cb01b5335cd565ba2b
BLAKE2b-256 4446e724442cfa9b6ab4a464026694e6c90425af0e108c6d79fadb5011d19061

See more details on using hashes here.

File details

Details for the file nbg_currencies_api-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for nbg_currencies_api-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e91a8b4d751176a90b8c97263ce4ab2bc5daddefca4b6b875613de35d0a0ef7
MD5 57368e9b1a14792c9997c2abb363f4b9
BLAKE2b-256 4884e09f670a96ab0e1530f0060561695e6f88f94d3786be8c5090fbb2f82b57

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