A simple Python client for the Unirate API - providing free, real-time and historical currency exchange rates.
- π Real-time exchange rates - Get current currency conversion rates
- π Historical data - Access historical exchange rates for any date
- β° Time series data - Retrieve exchange rate data over date ranges
- π° Currency conversion - Convert amounts between currencies (current and historical)
- π 590+ currencies supported - Including cryptocurrencies
- π Completely free - No credit card required
- π Easy to use - Simple, intuitive API
pip install unirate-apifrom unirate import UnirateClient
# Initialize the client
client = UnirateClient('your-api-key-here')
# Get current exchange rate
rate = client.get_rate('USD', 'EUR')
print(f'USD to EUR rate: {rate}')
# Convert currency
amount = client.convert(100, 'USD', 'EUR')
print(f'100 USD = {amount} EUR')
# Get supported currencies
currencies = client.get_supported_currencies()
print(f'Supported currencies: {len(currencies)}')Get the current exchange rate between two currencies.
rate = client.get_rate('USD', 'EUR')Convert an amount from one currency to another using current rates.
converted = client.convert(100, 'USD', 'EUR')Get a list of all supported currency codes.
currencies = client.get_supported_currencies()Get the exchange rate between two currencies for a specific historical date.
# Get USD to EUR rate for January 1st, 2024
historical_rate = client.get_historical_rate('USD', 'EUR', '2024-01-01')
print(f'USD to EUR on 2024-01-01: {historical_rate}')Get all exchange rates for a base currency on a specific historical date.
# Get all USD rates for January 1st, 2024
rates = client.get_historical_rates('USD', '2024-01-01')
print(f'USD to EUR: {rates["EUR"]}')
print(f'USD to GBP: {rates["GBP"]}')Convert an amount using historical exchange rates for a specific date.
# Convert 100 USD to EUR using rates from January 1st, 2024
converted = client.convert_historical(100, 'USD', 'EUR', '2024-01-01')
print(f'100 USD = {converted} EUR (on 2024-01-01)')Get time series exchange rate data for a currency pair over a date range.
# Get USD to EUR rates for the first week of January 2024
time_series = client.get_time_series('USD', 'EUR', '2024-01-01', '2024-01-07')
for date, rate in time_series.items():
print(f'{date}: {rate}')from unirate import UnirateClient
def main():
# Initialize client
client = UnirateClient('your-api-key-here')
try:
print('=== Current Rates ===')
# Current exchange rate
current_rate = client.get_rate('USD', 'EUR')
print(f'Current USD to EUR: {current_rate}')
# Currency conversion
converted = client.convert(1000, 'USD', 'EUR')
print(f'1000 USD = {converted} EUR')
print('\n=== Historical Data ===')
# Historical rate for specific date
historical_rate = client.get_historical_rate('USD', 'EUR', '2024-01-01')
print(f'USD to EUR on 2024-01-01: {historical_rate}')
# Historical conversion
historical_converted = client.convert_historical(1000, 'USD', 'EUR', '2024-01-01')
print(f'1000 USD = {historical_converted} EUR (on 2024-01-01)')
# Time series data
time_series = client.get_time_series('USD', 'EUR', '2024-01-01', '2024-01-05')
print('USD to EUR time series:')
for date, rate in time_series.items():
print(f' {date}: {rate}')
except Exception as e:
print(f'Error: {e}')
if __name__ == '__main__':
main()The client raises UnirateError for API-related errors:
from unirate import UnirateClient, UnirateError
client = UnirateClient('your-api-key')
try:
rate = client.get_rate('USD', 'INVALID')
except UnirateError as e:
print(f'API Error: {e}')Get your free API key from https://unirateapi.com. No credit card required!
The API supports 590+ currencies including:
- Traditional currencies: USD, EUR, GBP, JPY, CAD, AUD, etc.
- Cryptocurrencies: BTC, ETH, LTC, and many more
Use get_supported_currencies() to get the complete list.
- Python 3.7+
- requests
MIT License