Skip to main content

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

rate_api_python-1.0.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

rate_api_python-1.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file rate_api_python-1.0.1.tar.gz.

File metadata

  • Download URL: rate_api_python-1.0.1.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

Hashes for rate_api_python-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ef3901fc8fa9e7fedabf76748b6f2dfbf5c2577c94fd3ecbbe3228bc0c3f64a7
MD5 25445961e6acc8a08c6e938d82d0aae7
BLAKE2b-256 a5839d3f4a1d126c1b40e943fedc78cc28d28f1eb182599424978e91faa70f89

See more details on using hashes here.

File details

Details for the file rate_api_python-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for rate_api_python-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c93efc9e696113df057e28c6b6a3c2399845fc0f94553ad946df8f9720bbf01e
MD5 fd450f107e6e1b00448ecccecf78d3d6
BLAKE2b-256 5a09f5523b8908684d6601679206c4310c82040ff1d797b16bd32095b12d52f1

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