Official Python SDK for the XRates exchange rate API.
Project description
xratesapi
Official Python SDK for the XRates exchange rate API.
Python 3.9+, built on httpx.
Install
pip install xratesapi
Quick start
from xratesapi import Client
client = Client("YOUR_API_KEY")
print(client.latest(base="USD", symbols=["EUR", "GBP"]))
print(client.convert("USD", "EUR", 100))
The client is also a context manager:
with Client("YOUR_API_KEY") as client:
rates = client.latest()
Methods
| Method | Endpoint |
|---|---|
latest(base="USD", symbols=None) |
GET /api/v1/latest |
historical(date, base="USD", symbols=None) |
GET /api/v1/{YYYY-MM-DD} |
convert(from_, to, amount, date=None) |
GET /api/v1/convert |
timeseries(start_date, end_date, base="USD", symbols=None) |
GET /api/v1/timeseries |
fluctuation(start_date, end_date, base="USD", symbols=None) |
GET /api/v1/fluctuation |
currencies() |
GET /api/v1/currencies |
status() |
GET /api/v1/status |
Error handling
from xratesapi import (
Client,
ApiError,
AuthenticationError,
RateLimitError,
ValidationError,
)
try:
client.latest(base="XXX")
except AuthenticationError:
... # 401 / 403
except RateLimitError:
... # 429 — back off
except ValidationError as e:
print(e.payload) # raw response body
except ApiError as e:
print(e.status, e)
Configuration
import httpx
from xratesapi import Client
# Custom timeout / base URL
client = Client("KEY", base_url="https://xratesapi.com", timeout=30.0)
# Or inject your own httpx.Client (retries, proxies, transport, ...)
http = httpx.Client(timeout=30.0, transport=httpx.HTTPTransport(retries=3))
client = Client("KEY", http_client=http)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xratesapi-0.1.0.tar.gz
(5.6 kB
view details)
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 xratesapi-0.1.0.tar.gz.
File metadata
- Download URL: xratesapi-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd1e866ef7c9ef52fc0deb1a4601f52b150e0cd4bbd4d6e5d68b4ef9cfd9c872
|
|
| MD5 |
3361b85161b8c6b5720d6681e3272d22
|
|
| BLAKE2b-256 |
d44974c79ccab44acefbe24bd2819b68af9fd0832f8acbead2243c9da1c899f5
|
File details
Details for the file xratesapi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xratesapi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc376ff8d2f4bb716e5e93a5b295e69105fbaca9599ec968183fbf02d5cf3d88
|
|
| MD5 |
1c68f446d6df0dba0ab367d1ec813959
|
|
| BLAKE2b-256 |
b32dac28fd3760e2d3caf483b239f66e88f8fb044e3adce99a0f10ef1339e757
|