Skip to main content

PyPI version codecov

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-api

For Asynchronous Support

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

pip install nbg-currency-api[async]

Usage

Synchronous Mode

Fetch rates for all currencies on the current date:

from nbg_currency_api 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_api 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_api import NBGCurrencyService, CurrencyEnum, ClientModeEnum

async def main():
    service = NBGCurrencyService(currency=CurrencyEnum.EUR, mode=ClientModeEnum.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_api 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.

Release files for nbg-currencies-api 0.1.4

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

Source distribution (sdist)

Source distribution for nbg-currencies-api 0.1.4
File Size Uploaded
nbg_currencies_api-0.1.4.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nbg-currencies-api 0.1.4
File Interpreter ABI Platform
nbg_currencies_api-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 18.9 kB

Release files / nbg_currencies_api-0.1.4.tar.gz

Download URL nbg_currencies_api-0.1.4.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e7ccd0cbfa6677ea7b315e0b50c8e3e79e8ba0622dc9f84977e2ee81db00eba1
BLAKE2b-256 checksum
How to use checksums
9afb4dfd7e903db4af9d25cd6a09cedb4ff1254bcece9cdcb6219427e73adfc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.11

Release files / nbg_currencies_api-0.1.4-py3-none-any.whl

Download URL nbg_currencies_api-0.1.4-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd156a1bc91536bb404e2a421a9e3067a4b1eb8991520a4d6180c33d4c72b6ed
BLAKE2b-256 checksum
How to use checksums
1bef9c0f2a636cf74d27478ceacc7f2bb6df8336caabf1f1c7171e7b0d38641d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.11

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.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