How do I get exchange rates in Python? #2
Answered
by
cahthuranag
cahthuranag
asked this question in
Q&A
-
|
What's the easiest way to fetch currency exchange rates in Python? I don't want to deal with raw HTTP requests. AnswerInstall the official Python SDK: pip install exchangerateapiUsage: from exchangerateapi import ExchangeRateAPI
client = ExchangeRateAPI(api_key="era_live_YOUR_KEY")
# Get latest rates
data = client.latest(base="USD", symbols=["EUR", "GBP", "JPY"])
print(data["rates"]) # {"EUR": 0.92, "GBP": 0.78, "JPY": 149.5}
# Convert amount
result = client.convert("USD", "EUR", 1000)
print(f"$1,000 = EUR {result['result']}")
# Historical rates
data = client.for_date("2026-01-15", base="USD", symbols=["EUR"])
print(data["rates"]) # {"EUR": 0.9187}
# Time series
data = client.time_series("2026-01-01", "2026-03-31", base="USD", symbols=["EUR"])Zero dependencies — uses only Python standard library ( Get your free API key: exchange-rateapi.com/register |
Beta Was this translation helpful? Give feedback.
Answered by
cahthuranag
Jun 21, 2026
Replies: 1 comment
-
|
Install the official Python SDK: pip install exchangerateapiUsage: from exchangerateapi import ExchangeRateAPI
client = ExchangeRateAPI(api_key="era_live_YOUR_KEY")
# Get latest rates
data = client.latest(base="USD", symbols=["EUR", "GBP", "JPY"])
print(data["rates"]) # {"EUR": 0.92, "GBP": 0.78, "JPY": 149.5}
# Convert amount
result = client.convert("USD", "EUR", 1000)
print(f"$1,000 = EUR {result['result']}")
# Historical rates
data = client.for_date("2026-01-15", base="USD", symbols=["EUR"])
print(data["rates"]) # {"EUR": 0.9187}
# Time series
data = client.time_series("2026-01-01", "2026-03-31", base="USD", symbols=["EUR"])Zero dependencies — uses only Python standard library ( Get your free API key: exchange-rateapi.com/register |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
cahthuranag
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install the official Python SDK:
Usage:
Zero dependencies — uses only Python standard library (
…