Skip to main content

Async client for ECB daily reference exchange rates

Project description

ecb-fx-rates

Async Python client for ECB daily reference exchange rates.

Fetches and parses the ECB's XML feeds into typed Python objects. No caching, no storage — bring your own persistence layer.

Installation

pip install -e path/to/ecb-fx-rates

Requires Python 3.12+ and aiohttp.

Usage

import aiohttp
from ecb_fx_rates import EcbRatesClient, EcbDailyRates

async def main():
    client = EcbRatesClient()

    async with aiohttp.ClientSession() as session:
        # Today's rates
        today: EcbDailyRates = await client.fetch_daily(session)
        print(today.date)              # date(2025, 12, 31)
        print(today.get("USD"))        # Decimal("1.0842")
        print(today.get("EUR"))        # Decimal("1") — always

        # All rates for a specific year
        year_2025 = await client.fetch_year(session, 2025)
        # ~250 EcbDailyRates, one per ECB business day

        # Last 90 calendar days (~60 business days)
        recent = await client.fetch_last_90_days(session)

        # Full history since 1999 (~6MB download)
        everything = await client.fetch_history(session)

API

EcbRatesClient

Method Returns Feed used
fetch_daily(session) EcbDailyRates eurofxref-daily.xml (~5KB)
fetch_last_90_days(session) list[EcbDailyRates] eurofxref-hist-90d.xml (~50KB)
fetch_history(session) list[EcbDailyRates] eurofxref-hist.xml (~6MB)
fetch_year(session, year) list[EcbDailyRates] 90d or hist, filtered to year

EcbDailyRates

Attribute Type Description
date date ECB publication date
rates dict[str, Decimal] Currency code → EUR/X rate
Method Returns Description
get(currency) Decimal | None Rate for currency. EUR always returns Decimal("1").

Rate semantics: 1 EUR = rate units of currency. To convert foreign currency to EUR: eur = amount / rate.

Testing

pip install -e ".[dev]"
pytest tests/ -x -q

License

MIT

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

ecb_fx_rates-0.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

ecb_fx_rates-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file ecb_fx_rates-0.1.0.tar.gz.

File metadata

  • Download URL: ecb_fx_rates-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for ecb_fx_rates-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c6321e8b32dba615094cf7a8cf48449914deb1932759e48a85a02135fca45f2b
MD5 ba0468430bf42ef506bedbc8d8beb572
BLAKE2b-256 ea31d4ac7a642badef03ba55b52a6f2b1ccf0f031372efcd9631df6a70c7b1cb

See more details on using hashes here.

File details

Details for the file ecb_fx_rates-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ecb_fx_rates-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for ecb_fx_rates-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e82986a3fe9278f337ad6bf4097bca72ae32931de1b017f8935b861700fb3d0c
MD5 4e005ffbae367dfd74bfd075266cb267
BLAKE2b-256 29289edd8be83ff38f8c5ff7b219c00f02502860fcdba1c2035b3630cb7bb927

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