Welcome to the UnirateAPI Python documentation! Our free exchange rate API provides real-time currency conversion capabilities that you can easily integrate into your Python applications. Whether you're building a financial application, data analysis tool, or any other system that needs currency conversion, our API has you covered.
UnirateAPI is designed to be developer-friendly and reliable, with a focus on simplicity and performance. We provide both direct API access using standard Python libraries and an official Python client library for even easier integration.
For more detailed information about our API endpoints, rate limits, and advanced features, please check our main API documentation.
Below you'll find examples showing how to use our API with Python, both directly and using our official client library.
You can use our API in Python either by making direct HTTP requests or by using our official client library. We'll show you both approaches below.
# Option 1: Using the requests library directly
import requests
def convert_currency(api_key, from_currency, to_currency, amount):
"""
Convert currency using the UnirateAPI
"""
base_url = "https://api.unirateapi.com/api"
url = f"{base_url}/convert"
params = {
"api_key": api_key,
"from": from_currency,
"to": to_currency,
"amount": amount
}
response = requests.get(url, params=params)
if response.status_code == 200:
return response.json()
else:
raise Exception(f"API request failed: {response.text}")
# Example usage
try:
api_key = "YOUR_API_KEY"
result = convert_currency(api_key, "USD", "EUR", 100)
print(f"Converted amount: {result['result']} {result['to']}")
except Exception as e:
print(f"Error: {e}")
# Option 2: Using the official UnirateAPI Python client library
# First, install the library: pip install unirate-api
from unirate import UnirateClient
# Initialize the client
client = UnirateClient(api_key="YOUR_API_KEY")
# Get current exchange rate
rate = client.get_rate("USD", "EUR")
print(f"Current USD to EUR rate: {rate}")
# Convert amount
converted = client.convert(amount=100, from_currency="USD", to_currency="EUR")
print(f"100 USD = {converted} EUR")
# Get supported currencies
currencies = client.get_supported_currencies()
print(f"Supported currencies: {currencies[:5]}...") # Show first 5
# Direct API Response:
{
"from": "USD",
"to": "EUR",
"amount": 100,
"result": 92.45
}
# Client Library Outputs:
Current USD to EUR rate: 0.9245
100 USD = 92.45 EUR
Supported currencies: ['USD', 'EUR', 'GBP', 'JPY', 'AUD']...
Sign up now to get your API key and start converting currencies in your Python applications.
Get Your API Key