Official Python client for the Rate-API.com exchange-rate & crypto API
Project description
rate-api-python
Official Python client for Rate-API.com. Standard library only — no dependencies. Python 3.8+.
Install
pip install rate-api-python
Usage
from rate_api import RateApiClient, RateApiError
client = RateApiClient("YOUR_API_KEY")
rates = client.latest("USD", ["EUR", "GBP"])
print(rates["rates"]["EUR"])
client.convert("USD", "EUR", 100) # Pro+
client.historical("2026-01-15", "USD", ["EUR"]) # Pro+
client.pair("USD", "EUR") # single pair
client.timeseries("2026-01-01", "2026-01-31") # Business+
client.fluctuation("2026-01-01", "2026-01-31") # Business+
client.crypto(["BTC", "ETH"]) # Pro+
client.currencies() # supported currencies
client.health() # public
try:
client.timeseries("2020-01-01", "2026-12-31")
except RateApiError as e:
print(e, e.status) # "Date range too large. Maximum is 366 days." 400
v2 features
The client exposes the v2 endpoints directly (they resolve to /api/v2 regardless of base URL):
# Latest with 24h change, metadata and precision
r = client.latest_v2("USD", ["EUR", "GBP"], include_change=True, include_metadata=True, precision=4)
print(r["changes_pct"]["EUR"])
# Historical comparison between two dates (Pro+)
cmp = client.historical_compare("2026-01-15", "2026-01-01", "USD", ["EUR"])
# Batch conversion — up to 100 pairs in one call (Pro+)
batch = client.batch_convert([
{"from": "USD", "to": "EUR", "amount": 100},
{"from": "GBP", "to": "JPY", "amount": 50},
])
# Your configured rate alerts (Business+)
alerts = client.alerts()
Errors
Every failure raises RateApiError (or a subclass), so a single except RateApiError catches everything:
import time
from rate_api import RateApiClient, RateApiError, RateLimitError, RateApiTimeoutError
try:
client.latest("USD", ["EUR"])
except RateLimitError as e:
time.sleep(e.retry_after) # honour the server's backoff
except RateApiTimeoutError:
... # request exceeded `timeout`
except RateApiError as e:
print(e, e.status, e.type, e.request_id)
| Class | When | Extra attributes |
|---|---|---|
RateApiError |
any API/HTTP error | status (HTTP code; None on network/timeout), type (stable error.type slug), request_id (X-Request-Id — quote it when contacting support) |
RateLimitError |
HTTP 429 | retry_after (seconds to wait) |
RateApiTimeoutError |
request exceeded timeout |
— |
Configuration
RateApiClient(api_key, base_url="https://rate-api.com/api/v1", timeout=15, max_retries=2)
| Argument | Default | Notes |
|---|---|---|
base_url |
https://rate-api.com/api/v1 |
pass …/api/v2 to target v2 directly |
timeout |
15 |
per-request socket timeout in seconds (covers headers and body) |
max_retries |
2 |
automatically retries 429/503/network/timeout with exponential backoff, honouring the server's Retry-After header |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rate_api_python-1.0.2.tar.gz.
File metadata
- Download URL: rate_api_python-1.0.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bb8ced055d963ae922d4d3001ab67122bd7e9e5c41a22237828abecbf77d094
|
|
| MD5 |
6fc4781c61bd8e66529c617ee481981c
|
|
| BLAKE2b-256 |
80671591fa681d5c28dcffb03d832592f63e672f5e8a625c33a65613c1e3fc9a
|
File details
Details for the file rate_api_python-1.0.2-py3-none-any.whl.
File metadata
- Download URL: rate_api_python-1.0.2-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.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5784dfec56975dbb8a1cf7b75a323bb0415aa9bcaf64cf44e2f6c5a0d9800ac
|
|
| MD5 |
0461285c29dd7cc10dd9554f875d989b
|
|
| BLAKE2b-256 |
acc908f8f8877d9c211becfc5828ec4a6ab0ff47db49be9e719dca41a5d317ba
|